Course contentsShow
← Machine Learning and Deep Learning
Lesson 2377 of 3,53851. Recommender SystemsFree lesson

Normalized Discounted Cumulative Gain (NDCG)

Master NDCG to evaluate ranking quality with position-based discounting and graded relevance.

Normalized Discounted Cumulative Gain (NDCG)

What you'll learn: How NDCG measures ranking quality by rewarding relevant items at top positions while penalizing them when buried lower in recommendations.

The Core Problem with Earlier Metrics

You've learned Precision@K, Recall@K, and MAP — but these treat all positions equally or don't fully capture graded relevance. What if Item #1 is "extremely relevant" but Item #2 is just "somewhat relevant"? And what if a highly relevant item appears at position 10 instead of position 1? NDCG solves both problems.

How NDCG Works

Graded Relevance: Instead of binary relevant/not-relevant, NDCG uses relevance scores (e.g., 0-5 stars, or custom scales). A 5-star item is more valuable than a 3-star item.

Position-Based Discounting: Items at top positions matter more. NDCG divides each item's relevance by log₂(position + 1), so position 1 has discount 1.0, position 2 has ~0.63, position 3 has ~0.5, and so on.

Cumulative Gain (CG): Sum all relevance scores: CG = rel₁ + rel₂ + ... + relₖ

Discounted CG (DCG): Apply position discount: DCG = rel₁/log₂(2) + rel₂/log₂(3) + rel₃/log₂(4) + ...

Normalization: Divide by the ideal DCG (IDCG) — what you'd get if items were perfectly ranked. This gives a 0-1 score where 1.0 = perfect ranking.

The Formula

NDCG@K = DCG@K / IDCG@K

Think of it like grading a test: DCG is your actual score, IDCG is the maximum possible score, and NDCG is your percentage.

Why It Matters

NDCG rewards systems that place the most relevant items at the very top — exactly what users care about in recommendations.

Key Takeaway: NDCG evaluates ranking quality by combining graded relevance with position-sensitive discounting, normalized against the ideal ranking — the gold standard for recommendation system evaluation.