-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
TST add unit tests for current _get_response #21041
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
TST add unit tests for current _get_response #21041
Conversation
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 the code could be simpler (see below) but otherwise, ok with the new tests.
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 this PR fixes a bug and could be considered for 1.0.1.
sklearn/metrics/_plot/base.py
Outdated
@@ -111,7 +113,7 @@ def _get_response(X, estimator, response_method, pos_label=None): | |||
pos_label = estimator.classes_[1] | |||
y_pred = y_pred[:, 1] | |||
else: | |||
class_idx = np.flatnonzero(estimator.classes_ == pos_label) | |||
class_idx = np.flatnonzero(estimator.classes_ == pos_label)[0] |
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.
This feels like a bug fix. Should we include this in a whats_new?
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.
This comment is on an outdated line but the point is still valid.
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.
This is a private function so I think that we are fine.
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.
Even tho we have different output shapes for y_pred
, all the functions that call _get_response
also ends up calling _binary_clf_curve
. _binary_clf_curve
will then force y_score
to be 1d:
scikit-learn/sklearn/metrics/_ranking.py
Line 734 in 07a9dc9
y_score = column_or_1d(y_score) |
So in the end, not a bug fix (for a public API).
except ValueError: | ||
pass |
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.
May we add a comment on what version numpy will raise a ValueError
?
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 will add a comment. NumPy will not raise an error. Scikit-learn raise an error because pos_label="unknown"
. And the NumPy warning is only raised if pos_label
is a string. I did not think about it but we could maybe generate the warning when pos_label
is a valid string label.
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.
Actually, I remove the test since we completely change the way to get the index.
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
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.
LGTM
Failing test is on AppVeyor which should not be running. |
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Working on #21038, I could catch an inconsistency regarding the shape of
y_pred
whenpos_label
is set to a value.We were also raising a
FutureWarning
with a scalar/NumPy arrayin
operation.This PR adds minimum tests. They will be probably adapted later on in #20999 but this is safer to have them now.