Skip to content

roc_auc_score fails if dtype is object #2723

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
pprett opened this issue Jan 6, 2014 · 10 comments · Fixed by #9828
Closed

roc_auc_score fails if dtype is object #2723

pprett opened this issue Jan 6, 2014 · 10 comments · Fixed by #9828
Labels
Easy Well-defined and straightforward way to resolve Enhancement

Comments

@pprett
Copy link
Member

pprett commented Jan 6, 2014

to reproduce:

import numpy as np
np.random.seed(13)
classes = np.array(['yes', 'no'])
y = classes[np.random.randint(2, size=10)]
t = classes[np.random.randint(2, size=10)]
from sklearn.metrics import roc_auc_score
from sklearn.metrics import accuracy_score
roc_auc_score(t, y)
ValueError: Data is not binary and pos_label is not specified
@pprett
Copy link
Member Author

pprett commented Jan 6, 2014

I'm not sure how this should be dealt with: either rely on lexical ordering and let the last label be the positive or expose the pos_label argument. Anyways, the error is misleading because the data is binary and the pos_label cannot be specified.

@amueller
Copy link
Member

amueller commented Jan 7, 2014

why can pos_label not be specified? shouldn't it be yes?

@jnothman
Copy link
Member

jnothman commented Jan 7, 2014

The greater-is-positive approach is used elsewhere, but is awkward (e.g.
hinge_loss iirc). And there's a PR to add pos_label here (#2616). Though I
suggest that in order to not make the mess of multiclass averages and
pos_label interaction that we consider something more like #2610, which
allows you to specify a set of labels to average over, such that binary is
no longer a special case (indeed, the lack of labels parameter in
multiclass roc_auc_score is already a bug, because it means a missing class
in one cv fold could give a wildly different macro-average).

On 7 January 2014 11:22, Andreas Mueller notifications@github.com wrote:

why can pos_label not be specified? shouldn't it be yes?


Reply to this email directly or view it on GitHubhttps://github.com//issues/2723#issuecomment-31702170
.

@arjoly
Copy link
Member

arjoly commented Jan 28, 2014

related #2616

@ogrisel ogrisel removed this from the 0.15 milestone Jun 9, 2014
@Nikeshbajaj
Copy link

What I can understand is, roc_auc_score works for binary, 0, 1, does not understand 'yes' and 'no' as negative and positive class, which will make confusion for computation of true/false positive/negative, which to be treated what??

-----------try this instead ------This works-------
import numpy as np
np.random.seed(13)
#classes = np.array(['yes', 'no'])
#y = classes[np.random.randint(2, size=10)]
#t = classes[np.random.randint(2, size=10)]
y = np.random.randint(2, size=10)
t = np.random.randint(2, size=10)
from sklearn.metrics import roc_auc_score
from sklearn.metrics import accuracy_score
accuracy_score(t,y)
roc_auc_score(t, y)
-----------------end-----------------------------------------

@jnothman
Copy link
Member

We should not be able to provide pos_label to roc_auc_score: it is invariant to swapping classes as long as the score is similarly inverted (which I hope is tested but probably isn't...?). Rather we should make sure that roc_auc_score assumes that the greater of binary labels is the one for which the score is being reported.

@qinhanmin2014
Copy link
Member

@jnothman Just make sure that this will only work for binary y_true, not for multilabel-indicator y_true, right?

@qinhanmin2014
Copy link
Member

qinhanmin2014 commented Sep 21, 2017

@jnothman
I'm still wondering how you want to solve the problem.
For example, if I get y_true = ['good','not-good', 'good', 'not-good'] and y_score = [0.9, 0.1, 0.2, 0.7], y_score represents the probability of 'good'. So you are expecting users to do something like roc_auc_score(y_true, 1-y_pred) or 1-roc_auc_score(y_true, y_pred) instead of roc_auc_score(y_true, y_pred, pos_label='good')? Thanks.

@jnothman
Copy link
Member

why does y_score represent the probability of good? If someone trains a LogisticRegression model with y=['good','not-good', 'good', 'not-good'], it will automatically map 'not-good' as the positive class. When the user provides the output of the LogisticRegression.predict_proba (or does so via the scorer) as y_score, a high value will correspond to a likely 'not-good' prediction.

@qinhanmin2014
Copy link
Member

@jnothman Thanks. I opened #9828 to address your solution. Please have a look when you have time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Well-defined and straightforward way to resolve Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants