question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NDCG score doesn't work with binary relevance and a list of 1 element

See original GitHub issue

See 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:open
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
cBournhonesquecommented, Oct 18, 2021

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 too

0reactions
georged4scommented, Nov 2, 2022

Thanks @glemaitre for replying and for the heads up. Cool, I will look into this one.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found