lenskit.metrics.ranking#

LensKit ranking (and list) metrics.

Classes#

RankingMetricBase

Base class for most ranking metrics, implementing an n parameter for

DCG

Compute the _unnormalized_ discounted cumulative gain [JarvelinKekalainen02].

NDCG

Compute the normalized discounted cumulative gain [JarvelinKekalainen02].

Entropy

Evaluate diversity using Shannon entropy over item categories.

RankBiasedEntropy

Evaluate diversity using rank-biased Shannon entropy over item categories.

ExposureGini

Measure exposure distribution of recommendations with the Gini coefficient.

ListGini

Measure item diversity of recommendations with the Gini coefficient.

Hit

Compute whether or not a list is a hit; any list with at least one

ILS

Evaluate recommendation diversity using intra-list similarity (ILS).

LogRBP

Evaluate recommendations with the natural logarithm of rank-biased precision,

AveragePrecision

Compute Average Precision (AP) for a single user's recommendations. This is

MeanPopRank

Compute the _obscurity_ (mean popularity rank) of the recommendations.

Precision

Compute recommendation precision. This is computed as:

Recall

Compute recommendation recall. This is computed as:

RBP

Evaluate recommendations with rank-biased precision [MZ08].

RecipRank

Compute the reciprocal rank [KV97] of the first relevant

GeometricRankWeight

Geometric cascade weighting for result ranks.

LogRankWeight

Logarithmic weighting for result ranks, as used in NDCG.

RankWeight

Base class for rank weighting models.

Functions#

log_rank_biased_precision(good, log_weights, ...)

Compute the natural logarithm of rank-biased precision from log-space weights.

rank_biased_precision(good, weights[, normalization])

Compute rank-biased precision given explicit weights.

Package Contents#

lenskit.metrics.ranking.log_rank_biased_precision(good, log_weights, log_normalization)#

Compute the natural logarithm of rank-biased precision from log-space weights.

This is the log-space analogue of rank_biased_precision():

\[\ln \operatorname{RBP} = \operatorname{logsumexp}_{i \in \text{good}} \ln w_i - \ln Z\]

Working in log space means the rank discounts are never exponentiated and then summed, so scores far below the float64 subnormal floor remain representable instead of collapsing to zero. A list that retrieves none of its test items has \(\operatorname{RBP} = 0\), and therefore returns \(-\infty\) — a valid measurement, not a missing one.

Parameters:
  • good (numpy.ndarray) – Boolean array indicating relevant items at each position.

  • log_weights (numpy.ndarray) – Natural log of the weight for each item position (same length as good).

  • log_normalization (float) – Natural log of the normalization factor.

Returns:

The natural log of the RBP score, or -inf when no position is relevant.

Stability:

Experimental

Return type:

float

lenskit.metrics.ranking.rank_biased_precision(good, weights, normalization=1.0)#

Compute rank-biased precision given explicit weights.

Parameters:
  • good (numpy.ndarray) – Boolean array indicating relevant items at each position.

  • weights (numpy.ndarray) – Weight for each item position (same length as good).

  • normalization (float) – Optional normalization factor, defaults to 1.0.

Returns:

RBP score

Return type:

float