Skip to content

Commit 4eb8390

Browse files
author
Daria Tikhonovich
committed
fixed ndcg doc
1 parent 2cfdf11 commit 4eb8390

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

rectools/metrics/ranking.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,24 +318,23 @@ class NDCG(_RankingMetric):
318318
319319
.. math::
320320
NDCG@k=\frac{1}{|U|}\sum_{u \in U}\frac{DCG_u@k}{IDCG_u@k}
321+
DCG_u@k = \sum_{i=1}^{k} \frac{rel_u(i)}{log(i + 1)}
321322
322323
where
323-
- :math:`DCG_u@k` is "Discounted Cumulative Gain" at k for user u.
324-
- `"Gain"` stands for relevance of item at position i to user. It equals to ``1`` if this item
325-
is relevant, ``0`` otherwise
324+
- :math:`IDCG_u@k = \sum_{i=1}^{k} \frac{1}{log(i + 1)}` when `divide_by_achievable` is set
325+
to ``False`` (default).
326+
- :math:`IDCG_u@k = \sum_{i=1}^{\min (|R(u)|, k)} \frac{1}{log(i + 1)}` when
327+
`divide_by_achievable` is set to ``True``.
328+
- :math:`DCG_u@k` is "Discounted Cumulative Gain" at ``k`` for user ``u``.
329+
- :math:`rel_u(i)` is `"Gain"`. Here it is an indicator function, it equals to ``1`` if the
330+
item at rank ``i`` is relevant to user ``u``, ``0`` otherwise.
326331
- `"Discounted Gain"` means that original item relevance is being discounted based on this
327332
items rank. The closer is item to the top the, the more gain is achieved.
328333
- `"Discounted Cumulative Gain"` means that discounted gains are summed together.
329-
- :math:`IDCG_u@k` is `"Ideal Discounted Cumulative Gain"` at k for user u. This is maximum
330-
possible value of `DCG@k`, used as normalization coefficient to ensure that `NDCG@k`
331-
values lie in ``[0, 1]``.
332-
333-
When `divide_by_achievable` is set to ``False`` (default) `IDCG_u@k` is the same value for all
334-
users and is equal to:
335-
:math:`IDCG_u@k = \sum_{i=1}^{k} \frac{1}{log(i + 1)}`
336-
When `divide_by_achievable` is set to ``True``, the formula for IDCG depends
337-
on number of each user relevant items in the test set. The formula is:
338-
:math:`IDCG_u@k = \sum_{i=1}^{\min (|R(u)|, k)} \frac{1}{log(i + 1)}`
334+
- :math:`IDCG_u@k` is `"Ideal Discounted Cumulative Gain"` at ``k`` for user ``u``. This is
335+
the maximum possible value of `DCG@k`, used as normalization coefficient to ensure that
336+
`NDCG@k` values lie in ``[0, 1]``.
337+
- :math:`|R_u|` is number of relevant (ground truth) items for user $u$.
339338
340339
Parameters
341340
----------

0 commit comments

Comments
 (0)