Repository navigation
FIX prevent overflow in StandardScaler.partial_fit for large values - #34874
ShamikOfficial wants to merge 2 commits into
Conversation
StandardScaler.partial_fit used last_mean * last_sample_count which overflows for large values or long streams. Fall back to a delta-based update (Chan et al.) when the sum-based result is non-finite. Fixes scikit-learn#5602
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
Towncrier requires upcoming_changes fragments to use the pull request number, not the issue number. Co-authored-by: Cursor <[email protected]>
|
Closing this for now to free the open-PR slot — no maintainer feedback yet, and I'm focusing on a separate ready fix (#27777 / HuberRegressor ConvergenceWarning). Happy to reopen later if there's interest. |
Reference Issues/PRs
Fixes #5602.
What does this implement/fix? Explain your changes.
_incremental_mean_and_varupdates running statistics withlast_sum = last_mean * last_sample_count. For features with very largevalues or long incremental streams, that product can overflow to
inf,which then poisons the mean and variance used by
StandardScaler.partial_fit.This keeps the sum-based update as the primary path (more accurate in the
normal case), but falls back to an algebraically equivalent delta-based
update from Chan, Golub & LeVeque (1979) whenever the sum-based result is
not finite. The same idea is applied to the variance correction term.
Constant-feature detection also wraps its upper-bound check in
np.errstate(over="ignore")so it does not spuriously warn when themean itself is huge.
Introduce yourself
I use scikit-learn for applied ML and numerical/data pipelines. I picked
#5602 because it is a long-standing numerical correctness bug in a
widely used estimator, with a clear overflow mechanism and a standard
fallback algorithm.
This is among my first scikit-learn pull requests.
AI usage disclosure
I used AI assistance for:
I reviewed, ran, and understand all of the changes in this PR.
Any other comments?
34874.fix.rst(PR number)._incremental_mean_and_varand end-to-endStandardScaler.partial_fit.