Normalized Discounted Cumulative Gain (NDCG)
What you'll learn: How to evaluate ranking quality by rewarding highly relevant items at the top while penalizing good results buried lower in your list.
The Core Problem with Rankings
Imagine you're building a search engine. When someone searches for "best pizza recipe," you return 10 results. Not all results are equally good—some are excellent (5 stars), others decent (3 stars), and some barely relevant (1 star). But here's the catch: position matters enormously. An excellent result at position 10 is nearly worthless if users never scroll that far.
NDCG measures how well your ranking algorithm places the most relevant items at the top positions.
How NDCG Works
NDCG combines two key ideas you've already learned about:
- Graded relevance: Unlike binary classification, items can have multiple relevance levels (0, 1, 2, 3, etc.)
- Position discounting: Results lower in the list get penalized with logarithmic decay
The formula applies a discount factor based on position—typically 1/log₂(position + 1)—so the 1st position has no discount, but the 2nd, 3rd, and beyond progressively count less.
Then it normalizes by comparing your ranking to the ideal ranking (best possible ordering). This gives you a score between 0 and 1, where 1.0 means perfect ranking.
Why It Matters
Unlike simpler metrics like accuracy or Mean Average Precision at K, NDCG handles graded relevance elegantly. Your search result can be "somewhat relevant" rather than just "relevant or not," which matches real-world scenarios much better.
Key Takeaway: NDCG evaluates ranking quality by heavily rewarding relevant items at top positions while gracefully handling multi-level relevance scores, making it ideal for search engines, recommendation systems, and any task where position-aware ranking matters.