Skip to content

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

Open
cakedev0 wants to merge 2 commits into
scikit-learn:mainfrom
cakedev0:shared-validation-hgb
Open

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

Conversation

@cakedev0

@cakedev0 cakedev0 commented Dec 2, 2026

Copy link
Copy Markdown
Member

Reference Issues/PRs

Second part of the split of #35162, follow-up of #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 #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 and others added 2 commits December 2, 2026 14:05
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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant