Skip to content

Commit

Permalink
Merge pull request #369 from lukas-wegmeth/fix
Browse files Browse the repository at this point in the history
Documentation fix for Recall and Hit
  • Loading branch information
mdekstrand authored Mar 12, 2024
2 parents b62797f + f4e1e27 commit 2580591
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lenskit/metrics/topn.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def recall(recs, truth, k=None):
Compute recommendation recall. This is computed as:
.. math::
\\frac{|L \\cap I_u^{\\mathrm{test}}|}{\\operatorname{max}\\{|I_u^{\\mathrm{test}}|, k\\}}
\\frac{|L \\cap I_u^{\\mathrm{test}}|}{\\operatorname{min}\\{|I_u^{\\mathrm{test}}|, k\\}}
This metric has a bulk implementation.
"""
Expand Down Expand Up @@ -119,17 +119,13 @@ def hit(recs, truth, k=None):
is scored as 1, and lists with no relevant items as 0. When averaged over the recommendation
lists, this computes the *hit rate* :cite:p:`Deshpande2004-ht`.
.. math::
\\frac{|L \\cap I_u^{\\mathrm{test}}|}{\\operatorname{max}\\{|I_u^{\\mathrm{test}}|, k\\}}
This metric has a bulk implementation.
"""
nrel = len(truth)
if nrel == 0:

if len(truth) == 0:
return None

if k is not None:
nrel = min(nrel, k)
recs = recs.iloc[:k]

good = recs["item"].isin(truth.index)
Expand Down

0 comments on commit 2580591

Please sign in to comment.