NDCG Evaluation Metric for Recommender Systems

This video talks about the NDCG metric for recommender systems that takes into account both the degree of relevance and the ranking of items to evaluate recommender systems.

What is the NDCG metric?

NDCG stands for Normalized Discounted Cumulative Gain.

Recommender systems are important in sevaral application domains such as e-commerce, finance, healthcare and so on. It is important to come up with evaluation metrics to measure how well a recommender system works. Look at our article on Evaluation metrics for recommender systems for a quick overview.

Why do we need the NDCG metric?

Typical classification and regression metrics measure whether the predicted value is close to the actual value. But they do not account for the order of predictions. To evaluate recommender systems we need to measure how relevant the results are and how good the ordering is.

The most popular metric to evaluate a recommender system is the MAP@K metric. This metric tries to measure how many of the recommended results are relevant and are showing at the top.

However, the MAP@K metric has some shortcomings. The MAP@K metric focusses on precision – which which of the recommended items are relevant and which are not. It does not take into account how relevant the recommended results are.

There are many instances where the user assigns an explicit score to a recommended item, or we have expert evauators give a score for recommendations. When we have the ground truth for relevence score, we can try to evaluate how relevant the recommendations are.

One can think of the difference between the MAP and NDCG metric as the difference between evaluating predictions of 0-1 decisions like in classification vs predicting scores as in regression.

How does the NDCG Metric Work?

The NDCG metric involves finding the normalized discounted cumulative gain.

What is Gain?

Gain is just the relevance score for each item recommended.

What is cumulative gain?

Cumulative gain at K is the sum of gains of the first K items recommended.

CG_{@K}=\sum_{i=1}^K G_i

Note that this still does not take into account the ordering of the items.

What is discounted cumulative gain?

Discounted cumulative gain weighs each relevance score based on its position. The recommendations at the top get a higher weight while the relevance of those at the bottom get a lower weight.

DCG_{@K}=\sum_{i=1}^K \frac{G_i}{log_2 (i+1)}

Note that the denominator is log(i+1) giving more weightage to items recommended at the top.

The DCG has one shortcoming: The score is dependent on the number of items recommended. If we have two recommenders that are recommending a different number of items, it is hard to compare the DCG score. The recommender with more items is likely to have a higher score.

What is the NDCG Metric ?

The normalized discounted cumulative gain is the DCG with a normalization factor in the denominator.

The denominator is the ideal DCG score when we recommend the most relevant items first.

NDCG_{@K}= \frac{DCG_{@K}}{IDCG_{@K}} \\

IDCG_{@K}=\sum_{i=1}^{K^{ideal}} \frac{G^{ideal}_i}{log_2 (i+1)}

NDCG Example:

To understand this better, here is an example that shows how the NDCG is computed.

iRecommender:Doc OrderRecommender:Doc RelevanceGround Truth:Doc OrderGround Truth:Doc Relevance

The table above shows the document order as shown by the recommender. This is based on the relevance score predicted by the recommender.

The second column is the actual relevance score given by the customer or the evaluator.

The third column shows the documents in descending order of this relevance score. The fourth column once again shows the ground truth relevance score given by the customer or evaluator.

DCG_{@3}=\frac{3}{log(1+1)}+\frac{4}{log(2+1)}+\frac{3}{log(3+1)} \\
IDCG_{@3}=\frac{4}{log(1+1)}+\frac{3}{log(2+1)}+\frac{3}{log(3+1)} \\

The DCG is computed from the first two columns (with the order shown in column 1). The IDCG or the ideal DCG is computed using the last two columns. The NDCG is the ratio as shown in the picture.

Related References

Wikipedia Article on the NDCG metric

Leave a Reply

Your email address will not be published. Required fields are marked *