lenskit.metrics.RecipRank#

class lenskit.metrics.RecipRank(k=None)#

Bases: ListMetric, 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”.

Parameters:

k (int | None)

__init__(k=None)#
Parameters:

k (int | None)

Methods

__init__([k])

measure_list(recs, test)

Compute the metric value for a single result list.

truncate(items)

Truncate an item list if it is longer than k.

Attributes

default

The default value to infer when computing statistics over missing values.

k

The maximum length of rankings to consider.

label

The metric's default label in output.

property label#

The metric’s default label in output.

The base implementation returns the class name by default.

measure_list(recs, test)#

Compute the metric value for a single result list.

Individual metric classes need to implement this method.

Parameters:
Return type:

float