-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Fix spurious warning from type_of_target when called on estimator.classes_ #31584
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
4f5483f
0b5cfc5
eb90ddd
a586649
46bd286
0155642
cd60bf5
9302e60
d4736e9
fef3f26
7022e82
5dade50
421728c
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- Fixed a spurious warning (about the number of unique classes being | ||
greater than 50% of the number of samples) that could occur when | ||
passing `classes` :func:`utils.multiclass.type_of_target`. | ||
By :user:`Sascha D. Krauss <saskra>`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,7 +302,11 @@ def test_type_of_target_too_many_unique_classes(): | |
We need to check that we don't raise if we have less than 20 samples. | ||
""" | ||
|
||
y = np.arange(25) | ||
# Create array of unique labels, except '0', which appears twice. | ||
# This does raise a warning. | ||
# Note warning would not be raised if we passed only unique | ||
# labels, which happens when `type_of_target` is passed `classes_`. | ||
y = np.hstack((np.arange(20), [0])) | ||
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. Could we add a note here to explain why we add the '0' at the end? 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. And maybe we could keep the original 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. However, the original So should we rather adapt the test or treat the case 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.
+1 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.
@saskra I think @lucyleeow is correct. Now the # More than 20 samples but only unique classes, no warning should be raised
y = np.arange(25)
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
type_of_target(y) |
||
msg = r"The number of unique classes is greater than 50% of the number of samples." | ||
with pytest.warns(UserWarning, match=msg): | ||
type_of_target(y) | ||
|
@@ -313,6 +317,14 @@ def test_type_of_target_too_many_unique_classes(): | |
warnings.simplefilter("error") | ||
type_of_target(y) | ||
|
||
# More than 20 samples but only unique classes, simulating passing | ||
# `classes_` to `type_of_target` (when number of classes is large). | ||
# No warning should be raised | ||
y = np.arange(25) | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore", UserWarning) | ||
type_of_target(y) | ||
|
||
|
||
def test_unique_labels_non_specific(): | ||
# Test unique_labels with a variety of collected examples | ||
|
Uh oh!
There was an error while loading. Please reload this page.