lenskit.metrics.ranking.DCG#
- class lenskit.metrics.ranking.DCG(n=None, *, k=None, weight=LogRankWeight(), discount=None, gain=None)#
Bases:
lenskit.metrics.ranking._base.ListMetric,lenskit.metrics.ranking._base.RankingMetricBaseCompute the _unnormalized_ 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 metric does not normalize by ideal DCG. For that, use
NDCG. See Jeunen et al. [JPU24] for an argument for using the unnormalized version.- Parameters:
n (int | None) – The maximum recommendation list length to consider (longer lists are truncated).
discount (Discount | None) – The discount function to use. The default, base-2 logarithm, is the original function used by Järvelin and Kekäläinen [JarvelinKekalainen02].
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).
- property label#
The metric’s default label in output. The base implementation returns the class name by default.
- measure_list(recs, test)#
Compute measurements for a single list.
- Returns:
A float for simple metrics
Intermediate data for decomposed metrics
A dict mapping metric names to values for multi-metric classes
- Parameters:
recs (lenskit.data.ItemList)
test (lenskit.data.ItemList)
- Return type: