Back to Classic ML Mind Map
中文·English
📊 Classic MLID: ndcg

NDCG

🎯Core Definition
a ranking quality metric measuring how well highly relevant documents are placed at the top. Discounted cumulative gain DCG@k=i=1k2reli1log2(i+1)DCG@k = \sum_{i=1}^{k} \frac{2^{rel_i} - 1}{\log_2(i+1)}, where relirel_i is the graded relevance at position ii (typically 0-4) and log2(i+1)\log_2(i+1) is the position discount (1 at rank 1, log231.585\log_2 3 \approx 1.585 at rank 2, 2 at rank 3, log252.322\log_2 5 \approx 2.322 at rank 4). IDCG is the DCG of the ideal ranking (relevance descending), and NDCG@k=DCG@kIDCG@k[0,1]NDCG@k = \frac{DCG@k}{IDCG@k} \in [0,1]. Numerical example: true relevance [3, 2, 1, 0], model output order [2, 1, 3, 0], then DCG@4=2211+211log23+2312+201log25=3+0.63+3.5+0=7.13DCG@4 = \frac{2^2-1}{1} + \frac{2^1-1}{\log_2 3} + \frac{2^3-1}{2} + \frac{2^0-1}{\log_2 5} = 3 + 0.63 + 3.5 + 0 = 7.13; IDCG with the ideal order [3, 2, 1, 0]: IDCG@4=2311+221log23+2112+0=7+1.89+0.5=9.39IDCG@4 = \frac{2^3-1}{1} + \frac{2^2-1}{\log_2 3} + \frac{2^1-1}{2} + 0 = 7 + 1.89 + 0.5 = 9.39, so NDCG@47.13/9.390.76NDCG@4 \approx 7.13 / 9.39 \approx 0.76.
💡Use Cases
search ranking and recsys fine-ranking (LambdaRank / LTR optimized for NDCG); hand computation is an interview staple; the truncation k means “only the top k positions count”, usually k = 5 or 10.
Key Problems Solved
precision/recall treat all relevant documents equally, ignoring position and degree of relevance; 2rel12^{rel}-1 exponentially amplifies the gain of highly relevant documents (a relevance-4 item contributes ~2.3× a relevance-3 item) and log2(i+1)\log_2(i+1) penalizes lower positions, encoding “more relevant and higher up = more credit”; dividing by IDCG decouples NDCG from candidate-list size and relevance distribution so scores are comparable across queries, and NDCG is 0 when nothing relevant is ranked — avoiding the inflation of raw DCG as k grows.
🎯5 High-Frequency Exam Points
1
Hand computation: relevance [3, 2, 1, 0] ranked as [2, 1, 3, 0]; compute DCG@4, IDCG@4 and NDCG@4.
2
Why 2reli12^{rel_i}-1 instead of relirel_i? What is the intuition behind the position discount log2(i+1)\log_2(i+1)?
3
Why divide DCG by IDCG? What problems does the unnormalized DCG have?
4
How NDCG differs from binary metrics: graded 0-4 relevance vs relevant/irrelevant; how does the truncation k affect results?
5
Relation between NDCG and MRR: what does NDCG@1 correspond to under binary relevance?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "NDCG"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardROC-AUCNext CardMRR & GAUC

🔗 More Classic ML Knowledge Cards

AdaBoost DerivationBagging & Random ForestBaum-Welch (HMM EM)GBDT Negative Gradient