HistGradientBoosting fit fails when a column is all NaN in the training rows
PitfallVerified 1 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
HistGradientBoostingRegressor().fit(X, y) stops inside the binning step:
File ".../sklearn/ensemble/_hist_gradient_boosting/binning.py", line 82, in _find_binning_thresholds
bin_thresholds = sliding_window_view(distinct_values, 2).mean(axis=1)
ValueError: window shape cannot be larger than input array shape
The full data fits. Only some folds fail, for example when one group (one workload, one data source) is held out.
Cause#
A column that has values only in the held-out rows is all NaN in the training rows. The binner finds no distinct value for it and cannot build thresholds.
Fix#
Fit each fold on the columns that have at least one value in its training rows, and predict with the same columns:
= ~
=
Evidence#
Seen in the dpucrumbs black-box study (scikit-learn 1.9.1) on a leave-one-workload-out loop: each workload had its own feature columns, so every held-out fold left some columns all NaN. The per-fold column mask fixed every fold.
Also found by searching
- ValueError: window shape cannot be larger than input array shape
- HistGradientBoostingRegressor fit fails in one cross-validation fold
- how do I fit HistGradientBoosting when a column is all NaN in the training rows
- leave-one-group-out fit crashes on a feature only one group has