Skip to content

Getting error while calculating NDCG using sklearn #20119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joshidp opened this issue May 21, 2021 · 3 comments
Closed

Getting error while calculating NDCG using sklearn #20119

joshidp opened this issue May 21, 2021 · 3 comments
Labels

Comments

@joshidp
Copy link

joshidp commented May 21, 2021

I'm trying to calculate the NDCG score for binary relevance:

from sklearn import metrics

# test 1
y_true = [[3]]
y_score = [[5]]
metrics.ndcg_score(y_true, y_score)

And getting error

ValueError: Only ('multilabel-indicator', 'continuous-multioutput', 'multiclass-multioutput') formats are supported. Got binary instead

Below code snippet is working which has more than 1 item. Please suggest why single item array is not working.

from sklearn import metrics

# test 1
y_true = [[6 ,5, 4, 3, 2, 1]]
y_score = [[120, -2, -6, -3,  2, 12]]
metrics.ndcg_score(y_true, y_score)
@gfrisch
Copy link

gfrisch commented May 21, 2021

Not sure it is really a bug.
Trying to compute the ranking score of a single item list is a nonsense.
Should it obviously return 1 instead of an error ? Not sure ...

@joshidp
Copy link
Author

joshidp commented May 21, 2021

It might not be a bug but during K Cross validation single item is being passed and causing failure, this behavior is not right and not well documented. Please help

@glemaitre
Copy link
Member

I am closing because this is a duplicate of #21335
Closing since the discussion is going on there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants