lenskit.metrics.ranking#
LensKit ranking (and list) metrics.
Classes#
Base class for most ranking metrics, implementing an |
|
Compute the _unnormalized_ discounted cumulative gain [JarvelinKekalainen02]. |
|
Compute the normalized discounted cumulative gain [JarvelinKekalainen02]. |
|
Evaluate diversity using Shannon entropy over item categories. |
|
Evaluate diversity using rank-biased Shannon entropy over item categories. |
|
Measure exposure distribution of recommendations with the Gini coefficient. |
|
Measure item diversity of recommendations with the Gini coefficient. |
|
Compute whether or not a list is a hit; any list with at least one |
|
Evaluate recommendation diversity using intra-list similarity (ILS). |
|
Evaluate recommendations with the natural logarithm of rank-biased precision, |
|
Compute Average Precision (AP) for a single user's recommendations. This is |
|
Compute the _obscurity_ (mean popularity rank) of the recommendations. |
|
Compute recommendation precision. This is computed as: |
|
Compute recommendation recall. This is computed as: |
|
Evaluate recommendations with rank-biased precision [MZ08]. |
|
Compute the reciprocal rank [KV97] of the first relevant |
|
Geometric cascade weighting for result ranks. |
|
Logarithmic weighting for result ranks, as used in NDCG. |
|
Base class for rank weighting models. |
Functions#
|
Compute the natural logarithm of rank-biased precision from log-space weights. |
|
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
float64subnormal 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
-infwhen no position is relevant.- Stability:
Experimental
- Return type:
- 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: