Precision@k, Recall@k & NDCG
Evaluating top K recommendation and search results using Precision at K, Recall at K, and Normalized Discounted Cumulative Gain.
Position Matters in Ranking Systems
In classification, getting a positive prediction correct scores the same regardless of order.
In search and recommendation systems, position order is everything:
- User sees item at Rank 1 High utility and satisfaction!
- User sees item buried at Rank 20 User leaves the platform before scrolling down!
Ranking evaluation metrics measure the quality of Top-K recommended items.
┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. PRECISION@K │ 2. RECALL@K │ 3. NDCG@K │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Proportion of top-K │ Fraction of ALL true │ Graded relevance metric │
│ slots containing binary │ positive items retrieved │ with logarithmic position│
│ relevant items. │ inside top-K slots. │ discounting. Gold Standard!│
└──────────────────────────┴──────────────────────────┴──────────────────────────┘
1. Precision@K and Recall@K
Suppose a user liked 5 movies globally ( Total Relevant Items). We recommend a top-5 list () containing 3 liked movies:
- Limitation: Neither Precision@K nor Recall@K cares about order inside the top-K slots! A list with relevant items at ranks
[1, 2, 3]gets the exact same score as[3, 4, 5].
2. Normalized Discounted Cumulative Gain (NDCG@K)
NDCG solves the position problem and supports Multi-Level Graded Relevance (for example ).
Step 1: Discounted Cumulative Gain (DCG@K)
Logarithmic discounting heavily penalizes relevant items placed lower down the list.
Step 2: Ideal DCG@K (IDCG@K)
Re-sort the top-K items in perfect descending relevance order and compute DCG@K.
Step 3: Normalization (NDCG@K)
Normalizing against ideal sorting outputs a standardized score between and .
Metric Comparison Table
| Metric | Multi-Level Graded Scores? | Position Sensitive? | Primary Use Case |
|---|---|---|---|
| Precision@K | No (Binary) | No | Simple feed evaluation |
| Recall@K | No (Binary) | No | Candidate retrieval stage |
| NDCG@K | Yes (Graded) | Yes (Log Discounting) | E-Commerce & Search Ranking |
Say this out loud
Ranking metrics evaluate ordered recommendation lists. Precision at K measures the proportion of relevant items inside top K slots. Recall at K measures the fraction of total relevant items captured. NDCG at K is the industry gold standard metric for multi level graded relevance, discounting item relevance logarithmically based on rank position and normalizing against ideal sorting.
Followups to expect
- What is Mean Reciprocal Rank (MRR)? Evaluates reciprocal rank of the first relevant item, suitable for navigational search where users seek a single target result.
- How do you choose K in offline evaluation? Match K to actual user interface screen capacity: or for mobile feed cards, for web search engine pages.
Check yourself
Why do standard classification metrics fail when evaluating search engines and top K recommendation lists?