Skip to content
Calcrivo

NDCG Calculator

Calculate Normalized Discounted Cumulative Gain to evaluate ranking model quality.

Inputs

Relevance scores in predicted rank order

Relevance scores in ideal (descending) order

NDCG

0.9488

DCG

13.8483

IDCG

14.5954

Step by step

  1. DCG: Σ(2^rel_i − 1) / log₂(i+2)

    positions 1..6

    = 13.848264

  2. IDCG: same formula with ideal ordering

    positions 1..6

    = 14.595391

  3. NDCG = DCG / IDCG

    13.8483 / 14.5954

    = 0.948811

How it works

NDCG measures ranking quality by comparing a predicted ranking's Discounted Cumulative Gain (DCG) against the ideal ranking (IDCG). DCG gives higher weight to relevant items appearing earlier in the ranking, using a logarithmic discount. NDCG = DCG / IDCG normalizes to [0, 1].

Formula

NDCG

NDCG = DCG / IDCG; DCG = sum((2^rel_i - 1) / log2(i + 2))

rel_i
Relevance score of item at position i
IDCG
DCG of the ideal (perfectly sorted) ranking

Frequently Asked Questions

Why use logarithmic discounting?

Users are much more likely to look at top-ranked results. The log discount reflects diminishing returns of later positions — a relevant result at position 1 is far more valuable than the same result at position 10.

When is NDCG preferred over precision@k?

NDCG is preferred when relevance is graded (not binary) and position matters. It captures both the relevance level and rank position, while precision@k only counts binary relevant/irrelevant.

You might also need