Skip to content

Native categorical splitting enhancements in DecisionTree, ExtraTree, RandomForest and ExtraTrees #33965

Open
0 of 1 issue completed

Description

@adam2392

Warning

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.

Describe the workflow you want to enable

From: #33354 (comment), we want to enable:

  1. [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
  2. [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
  3. [Refactor] Consolidate the goes_left operation to work at inference time too: [ENH] ExtraTree: Add random splitting via deterministic hash to support up to 2**24 possible categories #33972
  4. [Refactor] Understand the bitset operations and merge these with the HistGradientBoosting bitset operations FEA Categorical split support for DecisionTree*, and RandomForest* #33354)
  5. [Feature] Implement categorical splitting for RandomSplitter for ExtraTrees. Pretty easy now that we have an arbitrary sized bitset, which we can expand to hold many categories in the case of a randomized tree: [ENH] ExtraTree: Add random splitting via deterministic hash to support up to 2**24 possible categories #33972
  6. [Feature] Add support for categorical in exporting
  7. [Feature] Add internal ordinal encoding support for any kind of "categorical input" (see FEA Categorical split support for DecisionTree*, and RandomForest* #33354 (comment))
  8. [Refactor] Address refactoring to use ColumnTransformer in tree, similar to HGBT: FEA Categorical split support for DecisionTree*, and RandomForest* #33354 (comment)
  9. Add warm_start capability with categorical_features (see: ENH Add categorical support for the forests #34832 (comment)_)

Below the line for priority:

  1. [Feature] Brute-force search; expands categorical support to multi-class and multi-output problems
  2. [Feature] Add support for sparse categorical splitting with best and random splitter

Describe your proposed solution

These work streams may not all be relevant, or mergable, but we can explore.

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. added
    Hard
    on May 10, 2026
  2. changed the title [-]Native categorical splitting enhancements[/-] [+]Native categorical splitting enhancements in DecisionTree, ExtraTree, RandomForest and ExtraTrees[/+] on May 10, 2026
  3. cakedev0 commented on May 10, 2026

    @cakedev0
    Member

    Good idea to create this issue! 👌

    Can you number the items?


    [Refactor] Understand the bitset operations and merge these with the HistGradientBoosting bitset operations

    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 ^^)

  4. cakedev0 commented on Jul 23, 2026

    @cakedev0
    Member

    [Feature] Add internal ordinal encoding support for any kind of "categorical input" (see #33354 (comment))

    I think this was done in #33345 right?


    Some small follow-ups:

  5. cakedev0 commented on Jul 24, 2026

    @cakedev0
    Member

    Some feedback on current items:

    [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
    • ... and that's it actually
  6. adam2392 commented on Jul 25, 2026

    @adam2392
    MemberAuthor

    Thanks for the feedback @cakedev0! Updated the items, and tagged the appropriate PR where relevant

  7. lcrmorin commented on Sep 28, 2026

    @lcrmorin

    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.

  8. cakedev0 commented on Sep 28, 2026

    @cakedev0
    Member

    [Refactor] Address refactoring to use ColumnTransformer in tree, similar to HGBT

    I believe this is done, right @adam2392?

  9. lcrmorin commented on Oct 1, 2026

    @lcrmorin

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    HardNew Featuremodule:tree

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions