Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
luiser1401 wants to merge11 commits intoscikit-learn:main
base:main
Choose a base branch
Loading
fromluiser1401:solve-issue-luis

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

@luiser1401luiser1401 changed the titleDOC: Replace y_pred with y_score in DetCurveDisplay (issue: 31761)FIX: Replace y_pred with y_score in DetCurveDisplay (issue: 31761)Jul 15, 2025
@github-actionsGitHub Actions
Copy link

github-actionsbot commentedJul 15, 2025
edited
Loading

✔️ Linting Passed

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

Generated for commit:d98568f. Link to the linter CI:here

Copy link
Member

@lucyleeowlucyleeow left a comment
edited
Loading

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
ify_scoreisnotNoneandnot (
isinstance(y_pred,str)andy_pred=="deprecated"
):
raiseValueError(
"`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."
)
ifnot (isinstance(y_pred,str)andy_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 tosklearn/utils/_plotting.py and it can be used for precision recall, ROC and DET displays

luiser1401 reacted with thumbs up emoji
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

luiser1401 reacted with thumbs up emoji
Copy link
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 is1.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 ofy_pred

luiser1401 reacted with thumbs up emoji
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 offpr orfnr to ensure that we are passingy_pred through correctly.
Maybe instead of hard coding the numbers we can just calculate them usingdet_curve?

Copy link
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.

Copy link
Member

@jeremiedbbjeremiedbb 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

@@ -1,10 +1,14 @@
# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause


Copy link
Member

Choose a reason for hiding this comment

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

please revert this unrelated change.

@@ -1,10 +1,10 @@
# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause

Copy link
Member

Choose a reason for hiding this comment

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

Please revert this unrelated change.


assert disp.estimator_name == expected_clf_name
assert disp.line_.get_label() == expected_clf_name


# TODO(1.9): remove
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# TODO(1.9): remove
# TODO(1.10): remove


forsin ["top","right"]:
assertdisplay.ax_.spines[s].get_visible()isnotdespine

ifdespine:
forsin ["bottom","left"]:
assertdisplay.ax_.spines[s].get_bounds()== (0,1)


# TODO(1.9): remove
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# TODO(1.9): remove
# TODO(1.10): remove

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.

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

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."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
" only as `y_pred`is deprecated in 1.7 and will be removed in 1.10."
" only as `y_pred`was 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. "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"y_predis deprecated in 1.7 and will be removed in 1.10. "
"y_predwas deprecated in 1.7 and will be removed in 1.10. "

Comment on lines +3 to +4
:func:`metrics.PrecisionRecallDisplay.from_predictions`. Both will be removed in
v1.10.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:func:`metrics.PrecisionRecallDisplay.from_predictions`.Both will be removed in
v1.10.
:func:`metrics.PrecisionRecallDisplay.from_predictions`.`y_pred` will be removed in
v1.10.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jeremiedbbjeremiedbbjeremiedbb left review comments

@lucyleeowlucyleeowAwaiting requested review from lucyleeow

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
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
@luiser1401@lucyleeow@jeremiedbb

[8]ページ先頭

©2009-2025 Movatter.jp