Evaluating Top-N Rankings#
The lenskit.metrics.ranking module contains the core top-N ranking
accuracy metrics (including rank-oblivious list metrics like precision, recall,
and hit rate).
Ranking metrics extend the RankingMetricBase base class, often in
addition to ListMetric, and return a score given a recommendation
list and a test rating list, both as item lists; most metrics require the recommendation item list to
be ordered.
All LensKit ranking metrics take n as a constructor argument to control the
list of the length that is considered; this allows multiple measurements (e.g.
HR@5 and HR@10) to be computed from a single set of rankings.
Changed in version 2026.1: The argument for the list length has changed from k to n, for
consistency across LensKit. k is kept as a deprecated alias until
2027.1.
Changed in version 2025.1: The top-N accuracy metric interface has changed to use item lists, and to be simpler to implement.
Included Effectiveness Metrics#
List and Set Metrics#
These metrics just look at the recommendation list and do not consider the rank positions of items within it.
|
Compute whether or not a list is a hit; any list with at least one |
|
Compute recommendation precision. This is computed as: |
|
Compute recommendation recall. This is computed as: |
Ranked List Metrics#
These metrics treat the recommendation list as a ranked list of items that may or may not be relevant; some also support different item utilities (e.g. ratings or graded relevance scores).
|
Compute the reciprocal rank [KV97] of the first relevant |
|
Evaluate recommendations with rank-biased precision [MZ08]. |
|
Compute the normalized discounted cumulative gain [JarvelinKekalainen02]. |
|
Compute the _unnormalized_ discounted cumulative gain [JarvelinKekalainen02]. |
Beyond Accuracy#
These metrics measure non-accuracy properties of recommendation lists, such as popularity/obscurity or diversity.
|
Compute the _obscurity_ (mean popularity rank) of the recommendations. |