Repository navigation
Fix StandardScaler for columns far from zero and constant columns - #549
Conversation
|
Thanks for fixing the timestamp and constant-column cases. I reviewed
I verified the variance counterexample separately; I did not run the Rust suite locally. |
|
@bardrop please take a look to the review ^ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #549 +/- ##
===========================================
+ Coverage 43.97% 87.27% +43.30%
===========================================
Files 85 100 +15
Lines 7281 9999 +2718
===========================================
+ Hits 3202 8727 +5525
+ Misses 4079 1272 -2807 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks, good catch. Fixed in the last commit:
|
|
CI caught a test I missed because I only ran the default features: |
|
Re-reviewed through No new merge blocker from me. One non-blocking suggestion on the ElasticNet test: the lazy/eager scales already come from the same I did not see check runs for the latest head when I looked, so please confirm CI is green before merge. The |
|
Thanks for the re-review. The wider tolerance now applies only to the normalized |
|
All checks are green on 0c13c67 now, including the windows, wasm32 and i686 jobs. |
|
Thanks |
Fixes #548
Checklist
Current behaviour
variancecomputessum(x^2) / n - mean^2. For values far from zero (for example Unix timestamps) the result is wrong,0or negative.StandardScalerthen returns values near1e307.RidgeRegression,LassoandElasticNetreturn "Cannot rescale constant column".StandardScalerreplaces a zero standard deviation byf64::MIN_POSITIVE. Forf32this becomes0, so a constant column becomesNaN. Forf64, new values in that column become very large.New expected behaviour
variance(and sostd_dev) uses Welford's algorithm, in one pass and without allocation. The variance of a constant column is exactly0.StandardScalerdivides a column with zero variance by1, as scikit-learn does.Change logs
Fixed
linalg: numerically stablevarianceandstd_devforArrayView1andArrayView2.preprocessing:StandardScalerfor constant columns.Eight tests fail before the change. Two of them are the old
ensure_std_validtests, which expectedf64::MIN_POSITIVE. OneGaussianNBtest compared variances withassert_eq!; its values changed in the last digit and are now exactly2/3and2/9.cargo test --all-features,clippyandfmtpass.