lenskit.metrics.NDCG#
- class lenskit.metrics.NDCG(n=None, *, k=None, weight=<lenskit.metrics.ranking._weighting.LogRankWeight object>, discount=None, gain=None)#
Bases:
ListMetric,RankingMetricBaseCompute the normalized discounted cumulative gain [JarvelinKekalainen02].
Discounted cumultative gain is computed as:
\[\begin{align*} \mathrm{DCG}(L,u) & = \sum_{i=1}^{|L|} \frac{r_{ui}}{d(i)} \end{align*}\]Unrated items are assumed to have a utility of 0; if no rating values are provided in the truth frame, item ratings are assumed to be 1.
This is then normalized as follows:
\[\begin{align*} \mathrm{nDCG}(L, u) & = \frac{\mathrm{DCG}(L,u)}{\mathrm{DCG}(L_{\mathrm{ideal}}, u)} \end{align*}\]- Parameters:
n (int | None) – The maximum recommendation list length to consider (longer lists are truncated).
weight (RankWeight) – The rank weighting to use.
discount (Callable[[ndarray[tuple[Any, ...], dtype[number]]], ndarray[tuple[Any, ...], dtype[float64]]] | None) – The discount function to use. The default, base-2 logarithm, is the original function used by Järvelin and Kekäläinen [JarvelinKekalainen02]. It is deprecated in favor of the
weightoption.gain (str | None) – The field on the test data to use for gain values. If
None(the default), all items present in the test data have a gain of 1. If set to a string, it is the name of a field (e.g.'rating'). In all cases, items not present in the truth data have a gain of 0.k (int | None)
- Stability:
- Caller (see Stability Levels).
- __init__(n=None, *, k=None, weight=<lenskit.metrics.ranking._weighting.LogRankWeight object>, discount=None, gain=None)#
Methods
__init__([n, k, weight, discount, gain])extract_list_metrics(data, /)Return the given per-list metric result.
measure_list(recs, test)Compute the metric value for a single result list.
summarize(values, /)Summarize per-list metric values
truncate(items)Truncate an item list if it is longer than
n.Attributes
defaultkThe metric's default label in output.
nThe maximum length of rankings to consider.
set_kweightdiscountgain- property label#
The metric’s default label in output. The base implementation returns the class name by default.