lenskit.metrics.ranking.RecipRank#

class lenskit.metrics.ranking.RecipRank(n=None, *, k=None)#

Bases: lenskit.metrics.ranking._base.ListMetric, lenskit.metrics.ranking._base.RankingMetricBase

Compute the reciprocal rank [KV97] of the first relevant item in a list of recommendations. Taking the mean of this metric over the recommendation lists in a run yields the MRR (mean reciprocal rank).

Let \(\kappa\) denote the 1-based rank of the first relevant item in \(L\), with \(\kappa=\infty\) if none of the first \(k\) items in \(L\) are relevant; then the reciprocal rank is \(1 / \kappa\). If no elements are relevant, the reciprocal rank is therefore 0. Deshpande and Karypis [DK04] call this the “reciprocal hit rate”.

Stability:
Caller (see Stability Levels).
Parameters:
  • n (int | None)

  • k (int | None)

property label#

The metric’s default label in output. The base implementation returns the class name by default.

measure_list(recs, test)#

Compute measurements for a single list.

Returns:

  • A float for simple metrics

  • Intermediate data for decomposed metrics

  • A dict mapping metric names to values for multi-metric classes

Parameters:
Return type:

float