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

rankrelevancegaindiscount 1/log₂(i+1) DCG contributioncumulative DCGideal relevanceideal cumulative
Definitions and conventions
MetricDefinitionEdge case handling
DCG@kΣ gain(relᵢ) / log₂(i+1)Positions past the list end count as 0
Gainexponential: 2^rel − 1 · linear: relscikit-learn uses linear; TREC and LightGBM use exponential
IDCG@kDCG@k of the judgments sorted descendingUses all judged items, not only retrieved ones
NDCG@kDCG@k / IDCG@k0 when IDCG = 0 (some libraries return 1 or NaN)
Precision@krelevant in top-k / kDivides by k even if fewer than k items were returned
Recall@krelevant in top-k / total relevant0 when nothing is relevant
AP@kΣ P@i·relᵢ / min(k, total relevant)The normaliser differs across libraries
RR@k1 / rank of first relevant item0 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.