FIX prevent catastrophic cancellation in r_regression (#11395) - #34834
Open
FinalSunFlower wants to merge 2 commits into
Open
FIX prevent catastrophic cancellation in r_regression (#11395)#34834FinalSunFlower wants to merge 2 commits into
FinalSunFlower wants to merge 2 commits into
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #11395.
What does this implement/fix? Explain your changes.
r_regressioncomputes centered feature norms using a moment-based expression. Floating-point cancellation can make the mathematically non-negative centered sum of squares slightly negative for constant or near-constant columns, causing an invalid square root and propagating invalid correlations. This change clamps the intermediate squared norms to zero beforesqrt, preserving existing results for active non-constant features and keeping dense, CSR, and CSC inputs consistent. Regression tests cover constant features,force_finite=False, sparse formats, high-magnitude cancellation, and active-feature preservation.Introduce yourself
I am FinalSunFlower, contributing a numerically focused bug fix to scikit-learn's feature-selection utilities. I use scikit-learn for classical machine-learning workflows and was prompted by issue #11395 to improve the stability of
r_regressionon degenerate inputs.AI usage disclosure
I used AI assistance for:
Any other comments?
Local CPU validation passed for the targeted regression tests, the complete feature-selection test module, Ruff checks, and formatting checks. The changelog entry is included in
doc/whats_new/upcoming_changes/sklearn.feature_selection/34834.fix.rst.