M7-002Medium排序与推荐 · Ranking & recsys🔥 大厂高频出现 2 次
NDCG 怎么算?为什么搜索用 NDCG 而不是准确率?
How is NDCG computed, and why does search use it instead of accuracy?
💡 考场高分一句话答案:
NDCG = DCG/IDCG,用对数折损位置并支持多级相关性;搜索是排序问题,位置变化对体验影响大,准确率无法反映。
NDCG is DCG divided by the ideal DCG, with a logarithmic position discount and graded relevance. Search is a ranking problem, so position changes matter and accuracy cannot see them.
📌 核心考察要点 (Key Points)
- DCG:$\sum (2^{rel_i}-1)/\log_2(i+1)$,位置越靠后折损越大
- IDCG:理想排序(按相关性降序)的 DCG,用于归一化到 [0,1]
- 多级相关性:0=无关、1=边缘、2=相关、3=高度相关、4=完美
- 为什么不用准确率:把第 3 位的好结果提到第 1 位,准确率不变但体验大变
- DCG: $\sum (2^{rel_i}-1)/\log_2(i+1)$, discounting harder further down
- IDCG: the DCG of the ideal ordering, normalising the score into [0,1]
- Graded relevance: 0 irrelevant, 1 marginal, 2 relevant, 3 highly relevant, 4 perfect
- Why not accuracy: promoting a good result from position three to one leaves accuracy identical but transforms the experience
📐 第一性原理与数理推导机理
对数折损的合理性来自“用户从上往下看、越往后注意力衰减”的行为假设。折损函数也可以换成 $1/\log_2(i+1)$ 之外的形式(如指数折损),选择取决于产品形态:移动端首屏只有 3 条,折损应更陡。
⚖️ 业务权衡与取舍 (Trade-offs & Calibration)
NDCG 的一个实践问题是标注成本。Google 用分层抽样 + 众包标注 + 专家复核,并对高频 query 优先标注。面试里可以提“我会用 NDCG@10 做主指标,但只在有标注的 query 集上算,并报告标注覆盖率”。
⚠️ 常见高频面试陷阱与避坑指南
- 用 NDCG 但不报告 k,导致跨版本不可比
- 忽略标注质量,把噪声当信号
🔍 大厂面试官连环追问 (Follow-ups)
- NDCG 与 MAP 的区别?
- 如何为移动端调整折损函数?
🎯 关联大厂考题实战训练 (2 题)
嫌字多看太累?进入苏格拉底式对话推演实验室
零打字负担,以大厂考官真实困境切入,通过点选直觉选项暴露思维盲区,手把手推导 Why。
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.