Why rank-based recommendation use NDCG?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In the domain of information retrieval and recommender systems, particularly systems that rely on rank-based recommendations, evaluating the efficacy of these systems is pivotal. One of the leading metrics used to assess the quality of ordered lists is the Normalized Discounted Cumulative Gain, commonly abbreviated as NDCG. This article explores why NDCG is a preferred evaluation metric for rank-based recommendations, providing technical explanations, examples, and comparisons to other methods.
Understanding Rank-Based Recommendations
Rank-based recommendation systems are designed to suggest items to users, presenting them in an ordered sequence according to predicted interest or relevance. The precise ranking of items is crucial because users are more likely to interact with top-ranked items. The effectiveness of these recommendations is often evaluated using metrics that take into account the position and relevance of each item in the ranking.
What is NDCG?
NDCG stands for Normalized Discounted Cumulative Gain. It is a metric that quantifies the usefulness of a recommendation system based on the relative position of relevant items within a ranked list. NDCG is preferred in rank-based systems due to its ability to consider both the position of items and their corresponding relevance scores.
Components of NDCG
- Relevance
Score(): Each item is assigned a relevance score indicating its importance or usefulness to the user. - Discount Function: The relevance of each result is discounted logarithmically proportional to its position, reflecting the idea that items appearing earlier in the list are more significant.
- Cumulative Gain (CG): It is the sum of the relevance scores of items in the list.
- Discounted Cumulative Gain (DCG):
- Ideal DCG (IDCG): DCG of the ideal ranking where items are sorted by decrease of relevance score.
- Normalization: NDCG is the ratio of DCG to IDCG.
The normalization ensures that the scores are between 0 and 1, allowing for easy comparison across different queries and datasets.
Why Use NDCG?
- Position Sensitivity: NDCG values items that appear earlier in the list more significantly, reflecting real-world user behavior where the value of each item diminishes as users diagnose deeper in the list.
- Relevance Weighting: Unlike binary relevance metrics such as Precision@K, NDCG accommodates multiple levels of relevance, allowing it to be used in varied contexts where relevance is not merely binary.
- Normalization: By normalizing DCG with ideal DCG, NDCG accounts for variance in ideal scoring, enabling fair evaluations across different query sets or users.
- Interpretability: Often achieving a higher level of interpretability compared to Precision and Recall, NDCG provides a more nuanced understanding of recommendation performance.
Example Calculation
Consider a recommendation system output for a query, with a true relevance score of each item as follows:
| Item Position | Item ID | Relevance Score |
| 1 | A | 3 |
| 2 | B | 2 |
| 3 | C | 3 |
| 4 | D | 0 |
| 5 | E | 1 |
Step-by-Step DCG and NDCG Calculation
- DCG Calculation:• DCG at position 1: • DCG at position 2: • DCG at position 3: • Continuing this approach, calculate DCG up to position 5.
- Calculate the Ideal DCG (IDCG):• Sort items by descending true relevance: A=3, C=3, B=2, E=1, D=0 • Calculate DCG in this ideal order.
- Normalize DCG to obtain NDCG:• Divide the actual DCG by the ideal DCG at each position.
This process will yield a series of values between 0 and 1, representing the quality of the ranking at different points.
Comparison with Other Metrics
| Metric | Position Sensitivity | Relevance Levels | Normalization | Use Case |
| Precision@K | Low | Binary | No | Useful for binary relevance, does not consider position. |
| Recall@K | Low | Binary | No | Indicates completeness, not useful for ordered lists. |
| MAP | Moderate | Binary | Yes (Average) | Averages precision values, less effective for non-binary. |
| NDCG | High | Multi-level | Yes | Ideal for scenarios with graded relevance. |
Other Considerations
Scalability
NDCG's computation is dependent on log operations, which are computationally efficient. It scales well even with larger datasets, though care should be taken with highly imbalanced relevance distributions.
Applicability
While NDCG is versatile, its efficacy is most pronounced in contexts where relevance can be graded rather than binary. In simpler recommendation settings, alternative measures might suffice, but for complex systems, NDCG provides significant insight.
In conclusion, NDCG is a powerful metric that captures both the graded relevance and the positional importance of items in recommendation lists. Its widespread use and adaptability to various contexts make it an indispensable tool for evaluating rank-based recommendation systems.

