You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native categorical splitting enhancements in DecisionTree, ExtraTree, RandomForest and ExtraTrees #33965
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
[Optimization] Add a bitset cache (i.e. a uint64_t memory view) that allows us to compute the category split as we traverse the tree for inference speedup
[Feature] Support in tree-based ensemble models (RF + ExtraTrees). This could be done after for random splitter support, so we do all the classes at once: ENH Add categorical support for the forests #34832
changed the title [-]Native categorical splitting enhancements[/-][+]Native categorical splitting enhancements in DecisionTree, ExtraTree, RandomForest and ExtraTrees[/+]on May 10, 2026
[Feature] Add a bitset cache (i.e. a uint64_t memory view) that allows us to compute the category split as we traverse the tree for inference speedup
This is an optimization not a feature I think? And this is what is done in HGB right?
It indeed feels like a good idea as it also reduces the memory size of the NODE_DTYPE. I'd be happy to take a look at that someday.
[Feature] Brute-force search; expands categorical support to multi-class and multi-output problems
I'd prefer to avoid that, I don't think it brings a lot of value: above ~10-20 classes this will be too slow to be useful, and for this number of classes, one-hot encoding should work just fine. But it will bring a lot of complexity in the code-base.
[Feature] Add support for sparse categorical splitting with best and random splitter
I feel this is not a priority either. I'm not sure if sparse categorical datasets are common? And honestly, I'm not even sure using trees on sparse datasets is common? (but happy to change my mind if I have examples)
Some items to add IMO:
[Feature] Support in tree-based ensemble models. This could be done after for random splitter support, so we do all the classes at once
I’ve added categorical support to export_dict in #34809, contributing to item 8. It stores category labels once at the root and the category codes routed left at each split, including random categorical splits. JSON round-trip tests check predictions and missing/unknown-category routing.
This covers dictionary/JSON export; the other exporters still need separate work.
I have embarked categorical support for other exports methods as well. Making the PR a bit big but i figured it might be easier to review merge all at once. I am going trough manual review. I would appreciate some (human) feedback as well.
Activity
[-]Native categorical splitting enhancements[/-][+]Native categorical splitting enhancements in DecisionTree, ExtraTree, RandomForest and ExtraTrees[/+]cakedev0 commentedon May 10, 2026
Good idea to create this issue! 👌
Can you number the items?
Isn't this already done?
Also, can you add an item about supporting any categorical values via internal ordinal encoders? see this comment #33354 (comment)
(I'd happy to do it btw, but probably after the support of random splitter, that I'd be happy to do too ^^)
cakedev0 commentedon Jul 23, 2026
I think this was done in #33345 right?
Some small follow-ups:
cakedev0 commentedon Jul 24, 2026
Some feedback on current items:
This is an optimization not a feature I think? And this is what is done in HGB right?
It indeed feels like a good idea as it also reduces the memory size of the
NODE_DTYPE. I'd be happy to take a look at that someday.I'd prefer to avoid that, I don't think it brings a lot of value: above ~10-20 classes this will be too slow to be useful, and for this number of classes, one-hot encoding should work just fine. But it will bring a lot of complexity in the code-base.
I feel this is not a priority either. I'm not sure if sparse categorical datasets are common? And honestly, I'm not even sure using trees on sparse datasets is common? (but happy to change my mind if I have examples)
Some items to add IMO:
adam2392 commentedon Jul 25, 2026
Thanks for the feedback @cakedev0! Updated the items, and tagged the appropriate PR where relevant
lcrmorin commentedon Sep 28, 2026
I’ve added categorical support to export_dict in #34809, contributing to item 8. It stores category labels once at the root and the category codes routed left at each split, including random categorical splits. JSON round-trip tests check predictions and missing/unknown-category routing.
This covers dictionary/JSON export; the other exporters still need separate work.
cakedev0 commentedon Sep 28, 2026
I believe this is done, right @adam2392?
lcrmorin commentedon Oct 1, 2026
I have embarked categorical support for other exports methods as well. Making the PR a bit big but i figured it might be easier to review merge all at once. I am going trough manual review. I would appreciate some (human) feedback as well.