---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://catboost.ai/docs/en/references/ndcg.md
  - href: en/references/ndcg.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://catboost.ai/docs/en/llms.txt

# NDCG

<!-- source: en/_includes/work_src/reusage-common-phrases/ranking-quality-assessment.md -->
This function is usually used to assess the quality of ranking.
<!-- endsource: en/_includes/work_src/reusage-common-phrases/ranking-quality-assessment.md -->

- [Calculation principles](#calculation)
- [User-defined parameters](#user-defined-parameters)

## Calculation principles {#calculation}

<!-- source: en/_includes/work_src/reusage-common-phrases/function-calculation.md -->
The calculation of this function consists of the following steps:
<!-- endsource: en/_includes/work_src/reusage-common-phrases/function-calculation.md -->


1. <!-- source: en/_includes/work_src/reusage-common-phrases/ascending_a_i.md -->
   The objects in each group are sorted in descending order of predicted relevancies ($a_{i}$).
   <!-- endsource: en/_includes/work_src/reusage-common-phrases/ascending_a_i.md -->

1. The DCG metric is calculated for each group ($group \in groups$) with sorted objects (see step [1](#ndcg__calc-principles__sort-predicted-relevancies)).

    The calculation principle depends on the specified value of the `type` and `denominator` parameters:

   | type/denominator|LogPosition| Position|
   |-----------------|-----------------------------------------------------|-------------------------------------------------|
   | **Base** | $DCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{t_{g(i,group)}}{log_{2}(i+1)}$| $DCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{t_{g(i,group)}}{i}$|
   | **Exp**  | $DCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{2^{t_{g(i,group)}} - 1}{log_{2}(i+1)}$| $DCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{2^{t_{g(i,group)}} - 1}{i}$|

    $t_{g(i,group)}$ is the label value for the i-th object in the group.

1. The objects in each group are sorted in descending order of target relevancies ($t_{i}$).

1. The iDCG metric is calculated for each group ($group \in groups$) with sorted objects (see step [3](#ndcg__calc-principles__sort-target-relevancies)).

    The calculation principle depends on the specified value of the `type` and `denominator` parameters:

    | type/denominator|LogPosition| Position|
    |-----------------|-----------------------------------------------------|-------------------------------------------------|
    | **Base** | $IDCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{t_{g(i,group)}}{log_{2}(i+1)}$| $IDCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{t_{g(i,group)}}{i}$|
    | **Exp**  | $IDCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{2^{t_{g(i,group)}} - 1}{log_{2}(i+1)}$ | $IDCG(group,top) = \sum\limits_{i=1}^{top}\displaystyle\frac{2^{t_{g(i,group)}} - 1}{i}$|

1. The NDCG metric is calculated for each group:
    $nDCG(group,top) = \displaystyle\frac{DCG}{iDCG}$
1. The aggregated value of the metric for all groups is calculated as follows:
    $nDCG(top) = \frac{\sum\limits_{group \in groups}  nDCG(group, top) * w_{group}}{\sum\limits_{group \in groups}  w_{group}}$


## User-defined parameters {#user-defined-parameters}

### top

#### Description

<!-- source: en/_includes/work_src/reusage-loss-functions/top__desc.md -->
The number of top samples in a group that are used to calculate the ranking metric. Top samples are either the samples with the largest approx values or the ones with the lowest target values if approx values are the same.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/top__desc.md -->

_Default_: –1 (all label values are used)


###  use_weights

#### Description

<!-- source: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->
Use object/group weights to calculate metrics if the specified value is <q>true</q> and set all weights to <q>1</q> regardless of the input data if the specified value is <q>false</q>.
<!-- endsource: en/_includes/work_src/reusage-loss-functions/use-weights__desc__without__note.md -->

_Default_: true

### type

#### Description

Metric calculation principles.

Possible values:
- Base
- Exp

_Default_: Base


### denominator

#### Description

Metric denominator type.

Possible values:
- LogPosition
- Position

_Default_: LogPosition
