← Back to Classic ML Mind Map
📊 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=1k2reli−1log⁡2(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 log⁡2(i+1)\log_2(i+1) is the position discount (1 at rank 1, log⁡23≈1.585\log_2 3 \approx 1.585 at rank 2, 2 at rank 3, log⁡25≈2.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=22−11+21−1log⁡23+23−12+20−1log⁡25=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=23−11+22−1log⁡23+21−12+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@4≈7.13/9.39≈0.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; 2rel−12^{rel}-1 exponentially amplifies the gain of highly relevant documents (a relevance-4 item contributes ~2.3× a relevance-3 item) and log⁡2(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.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of NDCG.
Use Cases
In production engineering, what are the primary use cases for NDCG and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Hand computation: relevance [3, 2, 1, 0] ranked as [2, 1, 3, 0]; compute DCG@4, IDCG@4 and NDCG@4.
2
Why 2reli−12^{rel_i}-1 instead of relirel_i? What is the intuition behind the position discount log⁡2(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
🎯
Verify Mastery: Practice Exam Questions for "NDCG"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardROC-AUCNext Card →MRR & GAUC

🔗 More Classic ML Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/ML/card/ndcg
中文速览与面试要点

NDCG (NDCG)

定义: 排序质量指标, 衡量“高相关文档是否排在前面”。折损累积增益 DCG@k = _i=1^k 2^rel_i - 1 _2(i+1), 其中 rel_i 是第 i 位的相关度分级 (通常 0-4), _2(i+1) 是位置折损 (第 1 位折损 1, 第 2 位 _2 3 1.585, 第 3 位 2, 第 4 位 _2 5 2.322)。按相关度降序的理想排列算出 IDCG, 归一化 NDCG@k = DCG@kIDCG@k [0,1]。数值例: 标注相关度 [3, 2, 1, 0], 模型输出顺序 [2, 1, 3, 0], 则 DCG@4 = 2^2-11 + 2^1-1 _2 3 + 2^3-12 + 2^0-1 _2 5 = 3 + 0.63 + 3.5 + 0 = 7.13; IDCG 用最优顺序 [3, 2, 1, 0]: IDCG@4 = 2^3-11 + 2^2-1 _2 3 + 2^1-12 + 0 = 7 + 1.89 + 0.5 = 9.39, 故 NDCG@4 7.13 / 9.39 0.76。 使用场景: 搜索排序、推荐精排 (LambdaRank/LTR 常用 NDCG 优化), 面试必考手算; 截断 k 表示只看前 k 位, 通常取 k = 5 或 10。 解决的问题: 精确率/召回率把所有相关文档等权对待, 不区分位置与相关程度; DCG 用 2^rel-1 指数放大高相关文档的增益 (相关度 4 的贡献是相关度 3 的近 2.3 倍), 用 _2(i+1) 惩罚排位靠后的文档, 体现“越相关越靠前贡献越大”; 除以 IDCG 后 NDCG 与候选数量、相关文档分布解耦, 不同 query 之间可直接比较, 且完全没有相关文档时 NDCG 恒为 0, 不会出现 DCG 随 k 增大而虚高的偏差。

核心要点

  • 手算: 相关度 [3, 2, 1, 0] 被排成 [2, 1, 3, 0], 求 DCG@4、IDCG@4 与 NDCG@4?
  • 为什么用 2^rel_i-1 而不是直接 rel_i? 位置折损 _2(i+1) 的直觉是什么?
  • NDCG 为什么要除以 IDCG? 不归一化的 DCG 有哪些问题?
  • NDCG 与二值指标的差异: 0-4 分级相关 vs 相关/不相关; 截断 k 对结果有何影响?
  • NDCG 与 MRR 的关系: 二值相关时 NDCG@1 与首个相关位置的对应是什么?