-
-
Notifications
You must be signed in to change notification settings - Fork 26k
FIX: Replace y_pred with y_score in DetCurveDisplay (issue: 31761) #31764
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
base: main
Are you sure you want to change the base?
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.
Thanks @luiser1401 , just some suggestions.
CI failure is unrelated (we're working on fixing).
if y_score is not None and not ( | ||
isinstance(y_pred, str) and y_pred == "deprecated" | ||
): | ||
raise ValueError( | ||
"`y_pred` and `y_score` cannot be both specified. Please use `y_score`" | ||
" only as `y_pred` is deprecated in 1.7 and will be removed in 1.9." | ||
) | ||
if not (isinstance(y_pred, str) and y_pred == "deprecated"): | ||
warnings.warn( | ||
( | ||
"y_pred is deprecated in 1.7 and will be removed in 1.9. " | ||
"Please use `y_score` instead." | ||
), | ||
FutureWarning, | ||
) | ||
y_score = y_pred |
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.
Let's refactor this out to sklearn/utils/_plotting.py
and it can be used for precision recall, ROC and DET displays
- :func:`metrics._plot.det_curve.DetCurveDisplay.from_predictions` y_pred parameter is deprecated and will be removed | ||
in v1.9. It has been replaced by y_score. | ||
- :func:`metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_predictions` y_pred parameter is deprecated | ||
and will be removed in v1.9. It has been replaced by y_score. | ||
By :user:`Luis <luiser1401>` |
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.
What about:
- :func:`metrics._plot.det_curve.DetCurveDisplay.from_predictions` y_pred parameter is deprecated and will be removed | |
in v1.9. It has been replaced by y_score. | |
- :func:`metrics._plot.precision_recall_curve.PrecisionRecallDisplay.from_predictions` y_pred parameter is deprecated | |
and will be removed in v1.9. It has been replaced by y_score. | |
By :user:`Luis <luiser1401>` | |
- `y_pred` is deprecated in favour of `y_score` in :func:`metrics.DetCurveDisplay.from_predictions` | |
and :func:`metrics.PrecisionRecallDisplay.from_predictions`. Both will be removed | |
in v1.10. | |
By :user:`Luis <luiser1401>` |
Can't tell if lines are under 88 characters but please check this.
I think we're at v1.8 so removal will in in 2 versions, 1.10
def test_y_score_and_y_pred_specified_error(): | ||
"""Check that an error is raised when both y_score and y_pred are specified.""" | ||
y_true = np.array([0, 1, 1, 0]) | ||
y_score = np.array([0.1, 0.4, 0.35, 0.8]) | ||
y_pred = np.array([0.2, 0.3, 0.5, 0.1]) | ||
|
||
with pytest.raises( | ||
ValueError, match="`y_pred` and `y_score` cannot be both specified" | ||
): | ||
DetCurveDisplay.from_predictions(y_true, y_score=y_score, y_pred=y_pred) | ||
|
||
|
||
# TODO(1.9): remove | ||
def test_y_pred_deprecation_warning(pyplot): |
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 these can be one test, that checks deprecation of y_pred
display_y_pred = DetCurveDisplay.from_predictions(y_true, y_pred=y_score) | ||
|
||
assert_allclose( | ||
display_y_pred.fpr, [5.000000e-01, 5.000000e-01, 5.000000e-01, 2.220446e-16] |
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 only need to test one of fpr
or fnr
to ensure that we are passing y_pred
through correctly.
Maybe instead of hard coding the numbers we can just calculate them using det_curve
?
This PR replaces y_pred with y_score in the DetCurveDisplay class. This change was made to follow the pattern in RocCurveDisplay.
Fixes: #31761