Repository navigation
FIX Fix HGB binning on features with only missing values - #35216
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
FrancoisPgm
left a comment
There was a problem hiding this comment.
LTGM thanks.
I have nothing to complain about, plus I learned the existence np.searchsorted and that numpy can sort NaNs :)
|
Thanks for the PR! Can you add a non-regression test 🙏? Since it appears to be a regression I added the milestone 1.10 so that we merge this one before the release. |
| if with_missing_values: | ||
| # only zero-weighted non-missing values: no threshold for this feature | ||
| X[sw != 0, -1] = np.nan |
There was a problem hiding this comment.
@lesteve this is the non regression test ^^ (with this change, the test crashes on main)
There was a problem hiding this comment.
Right, I missed this one, I was probably expecting a new test function and/or I read to quickly 😅 ...
done: Maintenance: get [sklearn#35304](scikit-learn/scikit-learn#35304) merged (replace the deprecated `np.isfortran`, fixes [sklearn#35289](scikit-learn/scikit-learn#35289)) todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Waiting to Now: add the non-regression test lesteve asks for add: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) (slow `X @ w` on C-contiguous tall matrices) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148) (scalar operands synchronize the queue) Co-Authored-By: Claude Opus 5.5 <[email protected]>
lesteve
left a comment
There was a problem hiding this comment.
I pushed a commit tweaking the tests. I am not 100% sure this is absolutely needed, but since I am not super familiar with the code, I'd rather keep three separate cases: no missing values, some missing values, some missing values where all non-zero sample weights are for missing values.
If both of @cakedev0 and @FrancoisPgm are happy with this I will merge this PR!
|
I'm ok with the tweak. From my understanding the third case introduced with "some" is not strictly necessary regarding the fix, but it could eventually detect a regression in the future that the 2 other cannot. |
|
I like it! Not too verbose but good coverage. Thanks! |
|
OK thanks for your feed-back, I enabled auto-merge. |
todo: move [sklearn#35216](scikit-learn/scikit-learn#35216) from Now to Waiting, the test was already there, approved by lesteve with auto-merge add: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features; approved) add: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator; ev-br on the SplineTransformer mutation) todo: lucyleeow approved [sklearn#35215](scikit-learn/scikit-learn#35215) Co-Authored-By: Claude Opus 5.5 <[email protected]>
done: HGB: get [sklearn#35216](scikit-learn/scikit-learn#35216) merged (binning crash on all-missing features, fixes [sklearn#35164](scikit-learn/scikit-learn#35164)), merged before I removed it done: Trees: get [sklearn#34554](scikit-learn/scikit-learn#34554) merged (recursion PDP on categorical features) drop: Threads: answer lesteve on [sklearn#35105](scikit-learn/scikit-learn#35105) (RFC deprecate `pre_dispatch`) drop: Maintenance: follow up on [sklearn#35209](scikit-learn/scikit-learn#35209) (newton-cg test failing on the macOS x86_64 wheels) drop: Benchmarks: review [benchmarks#142](probabl-ai/scikit-learn-benchmarks#142) (cuML benchmark config) drop: Threads: review [sklearn#34729](scikit-learn/scikit-learn#34729) (inference methods don't modify the estimator) drop: Linear: [sklearn#34793](scikit-learn/scikit-learn#34793) (Ridge centering trick for cholesky), benchmarks in [benchmarks#115](probabl-ai/scikit-learn-benchmarks#115) and [benchmarks#31](probabl-ai/scikit-learn-benchmarks#31) drop: Upstream: sklearnex reports [sklearnex#3402](uxlfoundation/scikit-learn-intelex#3402), [sklearnex#3377](uxlfoundation/scikit-learn-intelex#3377), [sklearnex#3220](uxlfoundation/scikit-learn-intelex#3220) drop: Upstream: [data-apis/array-api#976](data-apis/array-api#976) (why `stable=True` is the default for `xp.sort`) drop: Upstream: dpnp reports [IntelPython/dpnp#3149](IntelPython/dpnp#3149) and [IntelPython/dpnp#3148](IntelPython/dpnp#3148) drop: Threads: [sklearn#34736](scikit-learn/scikit-learn#34736) (oversubscription in `pairwise_distances`), out of the reported findings item drop: KMeans: benchmarks [benchmarks#154](probabl-ai/scikit-learn-benchmarks#154), [benchmarks#160](probabl-ai/scikit-learn-benchmarks#160), [OpenBLAS#6105](OpenMathLib/OpenBLAS#6105) and [sklearn#17334](scikit-learn/scikit-learn#17334), out of the [sklearn#35193](scikit-learn/scikit-learn#35193) item todo: move [joblib#1899](joblib/joblib#1899), [sklearn#35261](scikit-learn/scikit-learn#35261) and [sklearn#35053](scikit-learn/scikit-learn#35053) from Reviews to Now, [sklearn#35181](scikit-learn/scikit-learn#35181) to the top of Waiting (by hand in 03835dd) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reference Issues/PRs
Fixes #35164
What does this implement/fix? Explain your changes.
Fitting a HGB model on data with a feature that has no non-missing values crashes in
_find_binning_thresholds:It's a regression from 1.9.0: #29641 replaced the midpoints computation with
sliding_window_view, which fails on an empty array, and #34248 later moved the failure todistinct_mask[0] = True. The same happens when all non-missing values of a feature have zero weight.The fix treats an empty column like a constant one: no thresholds, so all values go to the missing values bin (same as 1.8).
AI usage disclosure
I used AI assistance for: