Skip to content

API Replace y_pred with y_score in DetCurveDisplay #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

Merged
merged 20 commits into from
Jul 25, 2025

Conversation

luiser1401
Copy link
Contributor

This PR replaces y_pred with y_score in the DetCurveDisplay class. This change was made to follow the pattern in RocCurveDisplay.

Fixes: #31761

@luiser1401 luiser1401 changed the title DOC: Replace y_pred with y_score in DetCurveDisplay (issue: 31761) FIX: Replace y_pred with y_score in DetCurveDisplay (issue: 31761) Jul 15, 2025
Copy link

github-actions bot commented Jul 15, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 901eda2. Link to the linter CI: here

Copy link
Member

@lucyleeow lucyleeow left a 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).

Comment on lines 304 to 319
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
Copy link
Member

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

Comment on lines 1 to 5
- :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>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

Suggested change
- :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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check line lenghts and structure the log how you suggested, however the last release is 1.7 on Jun 6th

Comment on lines 118 to 131
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):
Copy link
Member

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]
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've deleted hardcoded values for these kind of test in al three classes.

@luiser1401 luiser1401 requested a review from lucyleeow July 17, 2025 14:18
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @luiser1401. Here are some comments

Comment on lines 422 to 440
# TODO(1.9): remove after the end of the deprecation period of `y_pred`
def _deprecate_y_pred_parameter(y_score, y_pred):
"""Deprecate `y_pred` in favour of of `y_score`."""
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.10."
)
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.10. "
"Please use `y_score` instead."
),
FutureWarning,
)
return y_pred

return y_score
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For RocCurveDisplay, the deprecation happened in 1.7 but the deprecations of this PR will be released with 1.8, so we need to add a version argument to this function.

@luiser1401 luiser1401 requested a review from jeremiedbb July 21, 2025 12:19
@jeremiedbb jeremiedbb changed the title FIX: Replace y_pred with y_score in DetCurveDisplay (issue: 31761) API Replace y_pred with y_score in DetCurveDisplay Jul 21, 2025
@luiser1401 luiser1401 requested a review from jeremiedbb July 21, 2025 14:41
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @luiser1401

@jeremiedbb jeremiedbb added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jul 22, 2025
@jeremiedbb jeremiedbb added this to the 1.8 milestone Jul 22, 2025
Copy link
Member

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a nitpick on wording but I'm fine for this to go in as is

@jeremiedbb jeremiedbb merged commit 91486d6 into scikit-learn:main Jul 25, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation module:metrics Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

y_pred changed to y_true in RocCurveDisplay.from_predictions, but not in DetCurveDisplay.from_predictions
3 participants