Calculator Inputs
Example Data Table
| Rank | Item | Observed Relevance | Ideal Relevance |
|---|---|---|---|
| 1 | Query A | 3 | 3 |
| 2 | Query B | 2 | 3 |
| 3 | Query C | 3 | 2 |
| 4 | Query D | 0 | 2 |
| 5 | Query E | 1 | 1 |
| 6 | Query F | 2 | 0 |
This sample helps test graded relevance, cutoff depth, and the gap between observed ranking quality and the best achievable ordering.
Formula Used
Gain functions:
Linear gain: g(rel) = rel
Exponential gain: g(rel) = 2rel - 1
Discount at rank i:
discount(i) = logbase(i + 1)
Discounted Cumulative Gain:
DCG@k = Σ [ g(reli) / logbase(i + 1) ] for i = 1 to k
Ideal DCG:
IDCG@k uses the same formula after sorting relevance into the best possible order.
Normalized DCG: nDCG@k = DCG@k / IDCG@k
How to Use This Calculator
- Enter a label list for the ranked items, queries, or documents.
- Paste the observed relevance scores in the predicted ranking order.
- Choose the cutoff k, gain type, log base, and decimal precision.
- Optionally provide an already ordered ideal relevance list.
- Click Calculate nDCG to show metrics, details, and the Plotly graph.
- Use the CSV and PDF buttons to export your report.
FAQs
1. What does normalized DCG measure?
Normalized DCG measures ranking quality by comparing the observed ranked list against the best possible ranking. It rewards highly relevant items near the top and scales results between 0 and 1 when IDCG is positive.
2. Why is IDCG necessary?
IDCG gives the maximum achievable discounted gain for the same relevance values. Dividing DCG by IDCG removes scale differences and makes experiments easier to compare across queries, datasets, or ranking models.
3. When should I use exponential gain?
Use exponential gain when higher relevance grades should matter much more than lower grades. It is common in information retrieval because a grade jump near the top often represents a stronger improvement in usefulness.
4. What does cutoff k change?
Cutoff k limits the evaluation to the top ranks. This is useful when users only view the first few positions, such as search results, recommendations, or reranked document lists.
5. Can I use decimal relevance values?
Yes. The calculator accepts decimal relevance values. This helps when relevance comes from averaged labels, continuous quality scores, or weighted judgments from multiple annotators.
6. Why is my nDCG value zero?
nDCG becomes zero when DCG is zero or when all ideal gains are zero. This usually means the ranked list contains no effective relevance at the evaluated cutoff or the provided labels are all zero.
7. Should the optional ideal list already be sorted?
Yes. If you enter a custom ideal list, provide it in the order you want treated as ideal. If you leave it blank, the calculator automatically sorts the observed relevance values in descending order.
8. Is a higher nDCG always better?
Yes. A higher nDCG indicates the observed ordering is closer to the ideal ordering. A value near 1 means the model ranks relevant items very effectively within the evaluated cutoff.