Explain NDCG — why use it over AUC for ranking?
Written by the mlprep team · Updated
Explain NDCG. Why use it over AUC for a ranking problem, and what does it actually measure about your ranker?
Why AUC falls short for ranking#
AUC-ROC measures the probability that a random positive is ranked above a random negative — purely pairwise. A model that gets the ordering right but buries the best result at position 50 can still achieve high AUC. Users don't read 50 results. You care about what's at the top.
Cumulative Gain and Discounted Cumulative Gain#
Start with Cumulative Gain at position k:
where rel_i is the relevance score of the item at position i (e.g., 0 = irrelevant, 1 = relevant, 2 = highly relevant). This just sums relevance — position doesn't matter.
Discounted Cumulative Gain penalizes relevant items appearing lower in the list:
Position 1: divided by log₂(2) = 1. Position 2: divided by log₂(3) ≈ 1.58. Position 10: divided by log₂(11) ≈ 3.46.
A highly relevant item at position 1 contributes its full relevance. The same item at position 10 contributes only ~29% as much. This captures the intuition that users rarely scroll past the first few results.
Normalization: NDCG#
DCG is unnormalized — a query with 10 relevant items will have higher DCG than one with 2, making cross-query comparison meaningless.
NDCG divides by IDCG (Ideal DCG) — the DCG you'd get with a perfect ranker (all relevant items at the top):
NDCG ranges from 0 to 1 regardless of the number of relevant items, enabling averaging across queries.
Concrete example#
Query with 3 items, relevance scores [2, 0, 1] (what the model returned) vs ideal [2, 1, 0]:
DCG = 2/log₂(2) + 0/log₂(3) + 1/log₂(4) = 2 + 0 + 0.5 = 2.5
IDCG = 2/log₂(2) + 1/log₂(3) + 0/log₂(4) = 2 + 0.63 + 0 = 2.63
NDCG = 2.5 / 2.63 = 0.95
When to use NDCG vs other metrics#
NDCG: when items have graded relevance (not just binary), you care about top-k quality, and different queries have different numbers of relevant items. Standard for search, recommendation ranking, ad ranking.
Mean Reciprocal Rank (MRR): when there's one correct answer and you care about where it first appears. FAQ retrieval, question answering.
Precision@k: simpler, binary relevance, when you just want to know what fraction of the top k are relevant.
AUC-ROC: when you're doing binary classification and care about overall discrimination, not position.
The position bias complication#
In practice, NDCG computed from click data is biased — users are more likely to click position 1 regardless of relevance. Relevance labels inferred from clicks overestimate the quality of high-position items. Proper evaluation either uses human relevance judgments or applies inverse propensity scoring to correct for position bias.
Senior/staff considerations#
NDCG is useful only if the relevance labels are meaningful for the product goal. Human labels, purchases, clicks, dwell time, saves, and long-term retention each define a different ranking objective. A senior answer should ask what the relevance grades mean and whether they are current, unbiased, and aligned with online success.
Important nuances:
- NDCG@k should match the surface. Search may care about @5 or @10; feed ranking may need deeper metrics because users scroll; retrieval may care about recall@1000 before reranking.
- The gain function matters. Some systems use
2^rel - 1instead of rawrel, which rewards highly relevant items much more than mildly relevant ones. - Averaging across queries can hide failures. Slice by head vs tail queries, query intent, language, freshness, cold-start items, and navigational vs exploratory searches.
- NDCG does not measure diversity, novelty, fairness, freshness, latency, or business value. It needs guardrails.
- If labels come from clicks, correct or at least reason about position bias, selection bias, and missing-not-at-random negatives.
Interview red flags#
- Saying AUC is "basically a ranking metric" without explaining why top-k position matters.
- Computing NDCG from raw clicks and calling it ground truth.
- Optimizing NDCG@100 when the product only displays 10 results.
- Ignoring that offline NDCG improvements may not translate online if the label source is biased or stale.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
NDCG@k = DCG@k / IDCG@k. DCG discounts relevance by log₂(position+1) — item at position 1 worth full relevance, position 10 worth ~29%. Normalization by ideal ranking makes it comparable across queries. Use NDCG for ranking when relevance is graded and top-k quality matters. AUC measures pairwise ordering but ignores position — wrong metric for search/recommendation.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you compute NDCG when you only have implicit feedback (clicks) instead of explicit relevance labels?
- What's the difference between NDCG@10 and NDCG@100 and when do you care about each?
- Your NDCG improves in offline eval but A/B test shows no engagement lift. What do you investigate first?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Walk me through classification evaluation metrics — precision, recall, F1, AUC
How do you put confidence intervals on ML metrics?
How do you evaluate a new ranker using logs from an old policy?
How do you run an A/B test to evaluate a new ML model?