Skip to content

FIX Use the categorical encoding of trees in HGB, keeping the column order - #30

Closed
cakedev0 wants to merge 2 commits into
mainfrom
shared-validation-hgb
Closed

cakedev0 wants to merge 2 commits into
mainfrom
shared-validation-hgb

Conversation

@cakedev0

@cakedev0 cakedev0 commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Reference Issues/PRs

Second part of the split of scikit-learn#35162, follow-up of scikit-learn#35181.

What does this implement/fix? Explain your changes.

HGB now uses the X validation and categorical encoding of trees (sklearn/tree/_preprocessing.py, added in scikit-learn#35181), instead of its own ColumnTransformer. The diff in sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py is +29/-98 while fixing 3 bugs 😄

The encoding now keeps the original column order, while the ColumnTransformer used before moved the categorical features first. This fixes 3 bugs when a categorical feature is not the first column:

  • interaction_cst was applied to the wrong features,
  • partial_dependence(method="recursion") was computed for the wrong feature,
  • the cardinality error reported the wrong feature index.

AI usage disclosure

I used AI assistance for:

  • Code generation (closely guided)
  • Test/benchmark generation

Any other comments?

Possible follow-up: HGB validation doesn't have to force the dtype to float64. It could keep the dtype of the input (maybe just enforce float) and let the bin mapper handle both float32 and float64. This would save a copy of X for float32 inputs.

@cakedev0
cakedev0 force-pushed the shared-validation-hgb branch 2 times, most recently from 5d3ece9 to 3d9f32e Compare October 20, 2026 07:22
@cakedev0
cakedev0 force-pushed the shared-validation-hgb branch 3 times, most recently from 17fee36 to 86a7d1e Compare November 2, 2026 10:27
@cakedev0
cakedev0 force-pushed the shared-validation-hgb branch from 86a7d1e to 80f5f0b Compare December 2, 2026 12:59
@cakedev0
cakedev0 changed the base branch from shared-validation-trees to main December 2, 2026 12:59
HGB uses the encoding of trees, which keeps the column order. This fixes
interaction_cst, partial dependence with method="recursion" and the
cardinality error message when a categorical feature is not first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cakedev0
cakedev0 force-pushed the shared-validation-hgb branch from 80f5f0b to 3f3433b Compare December 2, 2026 13:06
@cakedev0

cakedev0 commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Opened upstream as scikit-learn#35602.

@cakedev0 cakedev0 closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant