A search system returns four documents whose graded relevance, in rank order, is [3,2,0,1] (higher is more relevant; 0 is irrelevant). What are precision@3 and NDCG@4, using DCG@k=∑i=1krelilog⁡2(i+1)?

ML systems and evaluation, Ranking metrics
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can compute position-aware ranking metrics and normalise them correctly.

Key idea

Precision@k is the fraction of the top k results that are relevant. DCG (discounted cumulative gain) adds up relevance grades, dividing each by log⁡2(i+1) so that lower ranks count less. NDCG@k (normalised DCG) discounts graded gains by log⁡2(i+1) and divides by the DCG of the ideal ordering, so it lies in [0,1].

Steps

  1. Precision@3: treat rel>0 as relevant. The top 3 are [3,2,0], with 2 relevant, so P@3=2/3≈0.667.
  2. DCG@4: 31+2log⁡23+0log⁡24+1log⁡25=3+1.262+0+0.431=4.693.
  3. Ideal order [3,2,1,0]: IDCG@4=3+1.262+12+0=4.762.
  4. NDCG@4=4.693/4.762≈0.985. The only mistake is swapping the relevance-1 and relevance-0 documents near the bottom, which costs little.
  5. Contrast: precision ignores grades and order within the top k; NDCG rewards putting the most relevant items first. Mention MRR (the reciprocal rank of the first relevant item) and the alternative gain 2rel−1, which emphasises highly relevant documents.

Common mistakes

How long your answer should be

Four lines of arithmetic and two sentences of interpretation; about 3 minutes.

Last checked on 4 December 2026.

Read this

Previous in ML systems and evaluation: What is the difference between covariate (data) drift and concept drift, what is an example of each, and how would you detect each in production?
Next in ML systems and evaluation: Why is ordinary shuffled k-fold cross-validation wrong for time-series data, and what should you do instead?