Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

luiser1401
Copy link

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: 291a1b6. 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

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
2 participants