Checking the List a Reader Actually Sees
A recommender usually shows a short list. Evaluate that list’s relevant items, their positions, and the cases where little history is available.
13 sections · 4 questions · 2 coding challenges
The arrow keys move between sections too.
Evaluating the Recommendation Task
BOTIE
Our exercise fixes the candidate set, relevance labels, and list length. That lets us calculate exactly what a metric rewards before drawing conclusions about a live recommendation system.
Sources for this history
Did the Useful Guide Reach the First Few Results?
Botie may rank a useful guide correctly relative to most of the catalogue and still place it below everything the reader sees. Average rating error does not directly answer whether the visible list helped.
We will evaluate a fixed candidate set at a chosen cutoff, then distinguish finding relevant guides from putting the most useful ones near the top.
The relevance labels are invented judgements for the displayed guides.
Step 1 of 4
Inspect the visible list
Each value indicates whether a ranked guide is relevant.
| Displayed position | Top three relevance |
|---|---|
| Rank 1 | 1 |
| Rank 2 | 0 |
| Rank 3 | 1 |
Rank 1
- Top three relevance
- 1
Rank 2
- Top three relevance
- 0
Rank 3
- Top three relevance
- 1
Step 2 of 4
Count useful results
Precision divides by list length; recall divides by all relevant candidates.
Retrieved: 3 guides Relevant among those retrieved: 2 Relevant among all candidates: 4 Precision at 3 = 2 / 3 Recall at 3 = 2 / 4 = 1 / 2
Step 3 of 4
Respect the order
A reader meets the first guide before the third. We can give useful results more credit when they appear earlier. Give each position a weight, multiply by whether its guide is relevant, and add the contributions.
| Reading position | Relevant? | Position weight | Contribution |
|---|---|---|---|
| First | Yes (1) | 1 | 1 × 1 = 1 |
| Second | No (0) | About 0.631 | 0 × 0.631 = 0 |
| Third | Yes (1) | 0.5 | 1 × 0.5 = 0.5 |
| Total | 2 relevant guides | 1 + 0 + 0.5 = 1.5 |
First
- Relevant?
- Yes (1)
- Position weight
- 1
- Contribution
- 1 × 1 = 1
Second
- Relevant?
- No (0)
- Position weight
- About 0.631
- Contribution
- 0 × 0.631 = 0
Third
- Relevant?
- Yes (1)
- Position weight
- 0.5
- Contribution
- 1 × 0.5 = 0.5
Total
- Relevant?
- 2 relevant guides
- Position weight
- Contribution
- 1 + 0 + 0.5 = 1.5
Step 4 of 4
The first useful result can matter even when precision is unchanged
These lists contain the same number of relevant guides. Their precision is equal, but one makes the reader pass an irrelevant result before finding something useful. A position-sensitive measure can capture that difference.
| List | First result | Second result | Precision at two |
|---|---|---|---|
| A | Irrelevant | Relevant | 0.5 |
| B | Relevant | Irrelevant | 0.5 |
A
- First result
- Irrelevant
- Second result
- Relevant
- Precision at two
- 0.5
B
- First result
- Relevant
- Second result
- Irrelevant
- Precision at two
- 0.5
Ranking quality is judged at the list the reader receives
The denominator matches the number of recommendations the reader received.
How useful was the list the reader actually saw?
Keep the displayed list separate from the full catalogue. Change which shown guides are relevant and compare the useful count with the number of recommendations delivered.
BOTIE
Precision of the displayed list
0.6667
Follow the operations
1. Visible binary relevance labels
- 01
- 10
- 21
2. Add a list
2
3. Count items
3
4. Divide
0.6667
5. Result
0.6667
Use a nonempty binary list at a fixed cutoff. This computes precision, not recall or NDCG.
1. Fix the Candidate Set and Cutoff
When Botie made the recommendation, which guides could he have shown? We should evaluate against that candidate set, excluding unavailable items and deciding how to handle guides already read. Ranking against ten sampled alternatives can give a different score from ranking against the whole catalogue.
The cutoff should match the number of recommendations the reader sees. Keep the interactions used for fitting separate from the held-out relevance labels we use to judge that list.
Comparisons need the same candidates and exclusion rules.
2. Separate Precision From Recall
Precision at k is the fraction of the returned k items that are relevant. Recall at k is the fraction of all relevant candidates that appear there. The denominators answer different questions.
When no relevant candidates are labelled for a reader, recall is undefined unless an aggregation convention is declared. Do not silently create a perfect score.
Top-three relevance = [1,0,1]; total relevant candidates = 4
Precision@3 = 2/3
Recall@3 = 2/4 = 0.5These metrics ignore ordering within the selected top-k set.
3. Give Earlier Positions More Weight
Discounted cumulative gain divides a gain by a logarithmic rank discount. NDCG normalises by the best possible ordering of the same relevance labels at the same cutoff. Define whether gains are binary, raw graded relevance, or exponential graded gains.
Our example uses binary gains. If ideal gain is zero, report the declared zero or exclusion convention instead of dividing by zero.
Binary DCG = sum(relevance_at_rank / log2(rank + 1))
Ranks start at 1
NDCG = observed DCG / ideal DCGA perfect ordering gives one when positive ideal gain exists.
Count relevance at the part of the list being shown
There are three relevant guides in the catalogue. Only the first two recommendations are visible in this comparison, and one of those is relevant.
import numpy as np
relevance = np.array([0, 1, 1, 0])
visible = relevance[:2]
total_relevant = 3
print(f'{visible.mean():.3f}')
print(f'{visible.sum() / total_relevant:.3f}')0.500
0.333Half of the visible list is useful, but it retrieves only one third of the relevant catalogue. The denominators answer different questions.
4. Inspect New Readers and New Guides Separately
Average per-reader metrics so highly active readers do not dominate unintentionally. Report performance for sparse histories and cold starts, along with catalogue coverage and repeated recommendations.
Offline labels reflect past exposure and may miss items a reader would have liked. A live experiment can assess actual behaviour, but it needs an explicit objective and careful interpretation rather than treating clicks as the whole goal.
The workshop calculates precision from a supplied visible list. Python also checks position-sensitive gain.
5. A Ranking Cannot Recover a Guide Missing from Its Candidates
A two-stage recommender first retrieves a manageable candidate set, then ranks it. If the useful guide never reaches that set, the ranker cannot place it first. Evaluate candidate recall separately from the quality of the final ordering.
Use the same candidate policy when comparing rankers. A model scored against a handful of easy random negatives is solving a different problem from one ranking the full eligible catalogue.
6. Separate Finding the Guide from Ordering It
The first count asks how many relevant guides retrieval included. The second asks how many appear in the visible list after ranking. Keep the full relevance set fixed while calculating both.
An unobserved interaction is not necessarily a confirmed irrelevant item. The example supplies relevance explicitly so the metric calculation has an unambiguous target.
Inspect both stages of a recommendation
Guides two and five are relevant. Retrieval misses guide five entirely.
import numpy as np
relevant = {2,5}
candidates = [0,1,2,3]
visible = [1,2]
candidate_recall = len(relevant.intersection(candidates))/len(relevant)
precision = len(relevant.intersection(visible))/len(visible)
print(candidate_recall, precision)0.5 0.5A better ordering could move guide two into first place. Guide five needs a different repair: retrieval must include it before the ranker can place it anywhere.
7. Average across Requests with a Defined Policy for Empty Targets
Some evaluation requests have no labelled relevant guide. Recall then has a zero denominator. Decide whether those requests are excluded from that metric or assigned a documented convention, and report how many there are.
Inspect new readers, new guides and low-exposure topics separately. An average dominated by frequent readers can conceal poor results for everyone else. Offline relevance reflects the collection and exposure process; an online change still needs a careful comparison of user outcomes.
Check yourself
Questions on Parts 1 to 7
Question 1 of 4
What is recall at three?
Use the information below.
Top-three binary relevance [1,0,1], four relevant candidates overall.Try it with Botie
Build with Botie
Write and run Python