NDCG score doesn't work with binary relevance and a list of 1 element
See original GitHub issueSee this code example:
>>> t = [[1]]
>>> p = [[0]]
>>> metrics.ndcg_score(t, p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/utils/validation.py", line 63, in inner_f
return f(*args, **kwargs)
File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py", line 1567, in ndcg_score
_check_dcg_target_type(y_true)
File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py", line 1307, in _check_dcg_target_type
raise ValueError(
ValueError: Only ('multilabel-indicator', 'continuous-multioutput', 'multiclass-multioutput') formats are supported. Got binary instead
It works correctly when the number of elements is bigger than 1: https://stackoverflow.com/questions/64303839/how-to-calculate-ndcg-with-binary-relevances-using-sklearn
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
How to calculate NDCG with binary relevances using sklearn?
Please try: from sklearn.metrics import ndcg_score y_true = [[0, 1, 0]] y_pred = [[0, 1, 0]] ndcg_score(y_true, y_pred) 1.0.
Read more >Proper way to use NDCG@k score for recommendations
In "plain" language. The Discounted Cumulative Gain for k shown recommendations (DCG@k) sums the relevance of the shown items for the ...
Read more >MRR vs MAP vs NDCG: Rank-Aware Evaluation Metrics And ...
The first family comprises binary relevance based metrics. ... Another issue is handling NDCG@K. The size of the ranked list returned by the ......
Read more >PDF/1 - Information Retrieval
Three elements: 1. A benchmark document collection ... Binary (relevant vs. non-relevant) in the simplest ... What if the results are not in...
Read more >A Theoretical Analysis of NDCG Ranking Measures
A central problem in ranking is to design a measure for evaluation of ranking functions. In ... the simplest case that the relevance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
HI jerome, you are right, I made a mistake. I’m using the definition on wikipedia It looks like the results would be 0.0 if the document isn’t a relevant one (relevance=0), or 1.0 if it is (relevance > 0). So the returned value could be equal to
y_true[0] > 0.
? In any case, I think that just updating error messages but keeping the current behaviour could be fine tooThanks @glemaitre for replying and for the heads up. Cool, I will look into this one.