core practice · coding problem

Compute precision and recall by hand

Given retrieved doc ids [1,4,2,9] and relevant ids {2,4,7}, compute precision@4 and recall@4.

The mechanism

Precision/recall measure set quality; MRR rewards getting one right answer near the top; nDCG rewards graded relevance discounted by rank. Pick the metric that matches what users feel.

Study Ranking Metrics

Expected evidence

precision@4 = 0.5 (2 relevant in 4), recall@4 = 2/3.

Try this drill in the practice workspace →

Hints when you need them
  • Precision = relevant retrieved / total retrieved.
  • Recall = relevant retrieved / total relevant in corpus.

Watch for these mistakes

  • Reporting accuracy instead of rank-aware metrics
  • Using nDCG without graded relevance labels
  • Measuring recall without a fixed cutoff k

Check the sources

Browse all practice briefs