Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation fix for Recall and Hit #369

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading