For the query "waterproof hiking boots", assessors graded four products as relevant: Boot-X (3), Boot-Y (3), Boot-Z (2) and Sock-K (1); every other product is grade 0. The search returned the top 5 below, and Boot-Y was not retrieved. With gain 2^rel − 1 and discount log₂(rank + 1), what is nDCG@5?
| Rank | Returned product | Grade |
|---|---|---|
| 1 | Boot-X | 3 |
| 2 | Rain cover | 0 |
| 3 | Boot-Z | 2 |
| 4 | Sock-K | 1 |
| 5 | Insole | 0 |
Show the answer and explanation
Correct answer: A, ≈ 0.67: IDCG@5 is the DCG of the best possible top 5 from all judged products, so the unretrieved grade-3 Boot-Y takes rank 2 of the ideal list.
Explanation Ranking Metrics
nDCG@k = DCG@k / IDCG@k. DCG sums each result's gain divided by a position discount. IDCG is the DCG of the ideal ranking: the best possible top k built from all judged documents for the query, not only the ones the system returned.
DCG of the returned list (gain 2^rel − 1, discount log₂(rank + 1)):
- rank 1, Boot-X: 7 / 1 = 7
- rank 3, Boot-Z: 3 / 2 = 1.5
- rank 4, Sock-K: 1 / log₂5 ≈ 0.431
- DCG@5 ≈ 8.93
Ideal top 5 = grades 3, 3, 2, 1, 0: 7 + 7/log₂3 + 3/2 + 1/log₂5 ≈ 7 + 4.417 + 1.5 + 0.431 ≈ 13.35. So nDCG@5 ≈ 8.93 / 13.35 ≈ 0.67.
Why the other values are wrong:
- 0.95 re-sorts only the returned items (IDCG ≈ 9.39). That hides the missed grade-3 boot, which is exactly the failure the metric should penalise.
- 0.50 drops the discount from the ideal list. IDCG must use the same discounts as DCG, otherwise even a perfect ranking scores below 1 (13.35 / 18 ≈ 0.74).
- 0.43 normalises by an imaginary page of five grade-3 products. Only two exist for this query, so a perfect ranking would again score below 1.
Interview tip: when you review an nDCG pipeline, ask where the IDCG comes from. Code that builds it from the returned list (or a truncated candidate set) silently inflates scores and hides recall failures.