-
-
Notifications
You must be signed in to change notification settings - Fork 26.6k
FIX roc_auc_curve: Return np.nan instead of 0.0 for single class #30103
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
Changes from all commits
0637f13
da2809d
ef8fdba
4d33b35
9ea9001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| - :func:`metrics.roc_auc_score` will now correctly return 0.0 and | ||
| - :func:`metrics.roc_auc_score` will now correctly return np.nan and | ||
| warn user if only one class is present in the labels. | ||
| By :user:`Gleb Levitski <glevv>` | ||
| By :user:`Gleb Levitski <glevv>` and :user:`Janez Demšar <janezd>` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - :func:`metrics.roc_auc_score` will now correctly return np.nan and | ||
| warn user if only one class is present in the labels. | ||
| By :user:`Gleb Levitski <glevv>` and :user:`Janez Demšar <janezd>` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -375,12 +375,11 @@ def _binary_roc_auc_score(y_true, y_score, sample_weight=None, max_fpr=None): | |
| warnings.warn( | ||
| ( | ||
| "Only one class is present in y_true. ROC AUC score " | ||
| "is not defined in that case. The score is set to " | ||
| "0.0." | ||
| "is not defined in that case." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be helpful to store
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my understanding and exploration of the code, I would prefer to keep this as it is, but if anybody wants to change it - go ahead. :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the idea here is different: we are not going to say that it is a positive or a negative class, we will just show the value that we found, i.e Or something like that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let us stop this. As I wrote, classes are renumerated. I know next to nothing about sklearn's code, but if caller gives If I change the function to def _binary_roc_auc_score(y_true, y_score, sample_weight=None, max_fpr=None):
if len(np.unique(y_true)) != 2:
print("all values equal", y_true[0])
returnI get the following To my possibly incomplete understanding of the code, This function cannot give a more descriptive warning, because it doesn't have sufficient information for it. A better warning could be given by the function that calls it, but it would require a big refactoring because a (curried) Changing a single |
||
| ), | ||
| UndefinedMetricWarning, | ||
| ) | ||
| return 0.0 | ||
| return np.nan | ||
|
|
||
| fpr, tpr, _ = roc_curve(y_true, y_score, sample_weight=sample_weight) | ||
| if max_fpr is None or max_fpr == 1: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lesteve this PR number is not gonna show up here. What do we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can duplicate the changelog entry into two files with different PR numbers in their name but the same contents.
Then both entries will be merged by towncrier when we aggregate the changelog of a given release.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's the towncrier's way of doing it, creating two files with same content that only differ by the PR number in the filename.
I originally thought it was a hidden towncrier feature but it is mentioned in the tutorial
I discovered this by looking at the towncrier source code. Note that it only works if both fragments have the same type (
fixin this case) IIRC.There is twisted/towncrier#599 to try to make it a bit more convenient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glemaitre you've enabled automerge before resolving this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I duplicated the changelog.