Ranking Metrics Playground
Enter the relevance grade of each retrieved item in the order your system ranked them, and see NDCG, Precision, Recall, MAP, MRR and Hit Rate computed step by step. A common bug is computing the ideal DCG from the retrieved list instead of from all relevant items, which hides what your system missed. Fill in the ground-truth judgments to see the difference.
6
Metrics
Cumulative DCG vs ideal
your ranking
ideal ranking
Step-by-step DCG
| rank | relevance | gain | discount 1/log₂(i+1) | DCG contribution | cumulative DCG | ideal relevance | ideal cumulative |
|---|
Definitions and conventions
| Metric | Definition | Edge case handling |
|---|---|---|
| DCG@k | Σ gain(relᵢ) / log₂(i+1) | Positions past the list end count as 0 |
| Gain | exponential: 2^rel − 1 · linear: rel | scikit-learn uses linear; TREC and LightGBM use exponential |
| IDCG@k | DCG@k of the judgments sorted descending | Uses all judged items, not only retrieved ones |
| NDCG@k | DCG@k / IDCG@k | 0 when IDCG = 0 (some libraries return 1 or NaN) |
| Precision@k | relevant in top-k / k | Divides by k even if fewer than k items were returned |
| Recall@k | relevant in top-k / total relevant | 0 when nothing is relevant |
| AP@k | Σ P@i·relᵢ / min(k, total relevant) | The normaliser differs across libraries |
| RR@k | 1 / rank of first relevant item | 0 if none in top-k |
An item counts as relevant for the binary metrics when its grade is > 0. Everything runs in your
browser. The reference Python implementation (metrics.py) is tested against
sklearn.metrics.ndcg_score and kept in parity with this page's JavaScript.