Why a metric needs a positional discount

Simple metrics such as precision@K ignore where the relevant result sits. A shopper shown the right
product in position 10 probably never sees it — yet precision@10 scores that exactly the same as a
hit in position 1.

NDCG fixes this: the contribution of the item at position i is discounted by log2(i + 1). The
item in position 1 contributes in full, the one in position 2 contributes half as much, and so on.

The NDCG formula

DCG@K = Sum (rel_i / log2(i + 1))  for i from 1 to K

NDCG@K = DCG@K / IDCG@K

where IDCG@K is the DCG of the ideal ranking
(every relevant product placed first)

An example for K=4 with relevance values [3, 2, 3, 0]:

DCG@4 = 3/log2(2) + 2/log2(3) + 3/log2(4) + 0/log2(5)
      = 3/1 + 2/1.585 + 3/2 + 0
      = 3 + 1.26 + 1.5 = 5.76

Ideal order [3, 3, 2, 0] → IDCG@4 = 3 + 1.89 + 1 + 0 = 5.89
NDCG@4 = 5.76 / 5.89 = 0.978 approximately

Applications in e-commerce

Evaluating search. How well the search algorithm puts the products shoppers actually buy into
the first positions.

PLP ranking. Personalized category sorting — you need to confirm that the products interesting
to a specific shopper sit higher. NDCG measures that directly.

Offline evaluation of recommendations. Before a new algorithm goes into an A/B test, it is
scored on historical data: NDCG of the new algorithm against the current one.

Tip: use NDCG@K with a K that matches the number of slots actually displayed. For a
recommendation block of 6 products, use NDCG@6. For a catalogue page where 8 to 12 positions are
visible above the fold, use NDCG@10 or NDCG@12.

The limits of NDCG

  • It requires relevance labels, from experts or from behaviour logs. Without them the metric
    cannot be computed.
  • Offline NDCG is not online conversion. An algorithm with high NDCG on historical data can
    still deliver a smaller conversion lift in an A/B test, because of novelty effects or the
    behaviour of one particular segment.
  • It ignores diversity. Showing 10 relevant but near-identical products yields a high NDCG and
    poor UX.
Metric Accounts for position Accounts for diversity Needs relevance labels
NDCG yes no yes
MAP yes (binary) no yes
Precision@K no no yes
Coverage no yes no