-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG] Improve error message with implicit pos_label in _binary_clf_curve #15562
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
Merged
ogrisel
merged 10 commits into
scikit-learn:master
from
ogrisel:improve-binary-clf-error-message
Nov 20, 2019
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9d7e92a
Improve error message with implicit pos_label in _binary_clf_curve
ogrisel 2af412d
PEP8 fix indentation in test
ogrisel eb1e3a2
Improve comment
ogrisel 8958875
More tests
ogrisel c0d065f
Merge remote-tracking branch 'origin/master' into improve-binary-clf-…
ogrisel cf4c979
Improve support and test for various y_true encoding
ogrisel d8b28f2
cosmit
ogrisel 6ac9222
PEP8
ogrisel da58f5a
Unused import
ogrisel 27c0de3
Fix old comment
ogrisel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,14 +525,23 @@ def _binary_clf_curve(y_true, y_score, pos_label=None, sample_weight=None): | |
sample_weight = column_or_1d(sample_weight) | ||
|
||
# ensure binary classification if pos_label is not specified | ||
# classes.dtype.kind in ('O', 'U', 'S') is required to avoid | ||
# triggering a FutureWarning by calling np.array_equal(a, b) | ||
# when elements in the two arrays are not comparable. | ||
classes = np.unique(y_true) | ||
if (pos_label is None and | ||
not (np.array_equal(classes, [0, 1]) or | ||
np.array_equal(classes, [-1, 1]) or | ||
np.array_equal(classes, [0]) or | ||
np.array_equal(classes, [-1]) or | ||
np.array_equal(classes, [1]))): | ||
raise ValueError("Data is not binary and pos_label is not specified") | ||
if (pos_label is None and ( | ||
classes.dtype.kind in ('O', 'U', 'S') or | ||
not (np.array_equal(classes, [0, 1]) or | ||
np.array_equal(classes, [-1, 1]) or | ||
np.array_equal(classes, [0]) or | ||
np.array_equal(classes, [-1]) or | ||
np.array_equal(classes, [1])))): | ||
classes_repr = ", ".join(repr(c) for c in classes) | ||
raise ValueError("y_true takes value in {{{classes_repr}}} and " | ||
"pos_label is not specified: either make y_true " | ||
"take integer value in {{0, 1}} or {{-1, 1}} or " | ||
There 10000 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. "integer value" is not correct @ogrisel |
||
"pass pos_label explicitly.".format( | ||
classes_repr=classes_repr)) | ||
elif pos_label is None: | ||
pos_label = 1. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you sure that we should include O?
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 so: object dtype is the default dtype used by pandas when parsing a CSV file with string columns that typically encode the target variable in a classification problem for instance.