lenskit.metrics.ranking.LogRankWeight#
- class lenskit.metrics.ranking.LogRankWeight(*, base=2, offset=0)#
Bases:
RankWeightLogarithmic weighting for result ranks, as used in NDCG.
This is the ranking model typically used for DCG and NDCG.
Since \(\operatorname{lg} 1 = 0\), simply taking the log will result in division by 0 when weights are applied. The correction for this in the original NDCG paper [JarvelinKekalainen02] is to clip the ranks, so that both of the first two positions have discount \(\operatorname{lg} 2\). A different correction somtimes seen is to compute \(\operatorname{lg} (k+1)\). This discount supports both; the default is to clip, but if the
offsetoption is set to a positive number, it is added to the ranks instead.- Parameters:
base (pydantic.PositiveFloat) – The log base to use.
offset (pydantic.NonNegativeInt) – An offset to add to ranks before computing logs.
- weight(ranks)#
Compute the discount for the specified ranks.
Ranks must start with 1.