Skip to content

Fix wrong chance_level plot in PrecisionRecallDisplay when using Pytorch data - #33405

Merged
betatim merged 9 commits into
scikit-learn:mainfrom
lucolivi:fix-incorrect-chance-ap-with-pytorch-data
Mar 11, 2026
Merged

betatim merged 9 commits into
scikit-learn:mainfrom
lucolivi:fix-incorrect-chance-ap-with-pytorch-data

Conversation

@lucolivi

@lucolivi lucolivi commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #33342

What does this implement/fix? Explain your changes.

This fix the bug that caused the wrong chance level line to be plot in PrecisionRecallDisplay.from_predictions when y_true was a pytorch array. It was caused by the use of a Counter object to calculate the chance level, that makes use of hash functions to index values, which are not fixed for a given value in pytorch data types. Now the implementation compares y_true entries to pos_label values directly, without requiring Counter objects.

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?

No

@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label Feb 25, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Feb 25, 2026

@AnneBeyer AnneBeyer 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.

Thank you @lucolivi!
I checked that this resolves the issue for PrecisionRecallDisplay.from_predictions (and actually also for from_estimator).
I only have a few small suggestions below, otherwise LGTM!

@lucolivi

lucolivi commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @AnneBeyer, thank you for your suggestions, I`ve included them all!

@lesteve lesteve 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.

Thanks, this looks good to me.

@lesteve lesteve added the Waiting for Second Reviewer First reviewer is done, need a second one! label Mar 5, 2026

@betatim betatim 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.

I enabled auto-merge

@betatim
betatim enabled auto-merge (squash) March 10, 2026 13:24
@betatim
betatim merged commit f5cce5c into scikit-learn:main Mar 11, 2026
44 of 45 checks passed
@lesteve

lesteve commented Mar 11, 2026

Copy link
Copy Markdown
Member

I restarted the CI build and it passed this time see #33510 for tracking the non-deterministic CI failure.

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

Labels

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.

Wrong chance_level plot in PrecisionRecallDisplay when using Pytorch data

4 participants