Skip to content

DOC Fix response values shape - #32918

Merged
thomasjpfan merged 3 commits into
scikit-learn:mainfrom
AnneBeyer:fix_response_values_shape
Dec 22, 2025
Merged

thomasjpfan merged 3 commits into
scikit-learn:mainfrom
AnneBeyer:fix_response_values_shape

Conversation

@AnneBeyer

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #32872

What does this implement/fix? Explain your changes.

The problem in #32872 arises from the assumption that multiclass classification will have a different output shape than binary classification, which is not the case when response_method="predict".
To make sure, I added a test for all output shapes and updated the docstring according to the result.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

I have not checked if this assumption is used anywhere else.

(LogisticRegression(), "predict", "binary", (10,)),
(LogisticRegression(), "predict_proba", "binary", (10,)),
(LogisticRegression(), "decision_function", "binary", (10,)),
(LogisticRegression(), "predict", "multiclass", (10,)),

@AnneBeyer AnneBeyer Dec 17, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the test that was inconsistent with the previous version of the docstring (which suggested that it should be (10,4))

Comment thread sklearn/utils/tests/test_response.py Outdated
if target_type == "binary":
y = np.array([0, 1] * 5)
elif target_type == "multiclass":
y = np.arange(10)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can the test values for y be something like [0, 1, 2, 3, 0, 1, 2, 3, 3, 0] so that the test would check for (10, 4) for the multi-class + predict_proba case?

This makes it more obvious that n_samples and n_classes can be different values.

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan added the Waiting for Second Reviewer First reviewer is done, need a second one! label Dec 20, 2025

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks, @AnneBeyer!

@thomasjpfan, could we merge this?

@thomasjpfan
thomasjpfan merged commit 485c7bc into scikit-learn:main Dec 22, 2025
@AnneBeyer
AnneBeyer deleted the fix_response_values_shape branch January 5, 2026 11:13
@github-project-automation github-project-automation Bot moved this to Todo in Labs Jan 5, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Labs Jan 5, 2026
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.

4 participants