Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEA Categorical split support for DecisionTree*, ExtraTree*, RandomForest* and `ExtraTrees* #29437

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

adam2392
Copy link
Member

@adam2392 adam2392 commented Jul 8, 2024

Reference Issues/PRs

Supersedes #12866 #4899 and #7068 , #3346

What does this implement/fix? Explain your changes.

Implements splitting rules when categorical data is given in a decision tree classifier/regressor.

  • Tree data structures are moved to maintain the cimport/import sequence (ParentInfo, SplitRecord, Node) -> _utils.pxd
  • Adds partitioning of samples given a category (this complements nicely the partitioning of samples given a numerical threshold)
  • Adds splitting logic given a category
  • Adds a bitset cache (i.e. a uint64_t memory view) that allows us to compute the category split as we traverse the tree

Open Questions / TODO

  1. Should breiman_shortcut be part of Splitter? It is completely unused by RandomSplitter, so it seems weird to pass in an argument that is unnecessary. Otoh, if we specialize the breiman_shortcut only for BestSplitter, then we need to also specialize how breiman_shortcut is passed in BaseDecisionTree.
  2. Add unit-testing for splitting on categories vs one-hot-encoder -> shallower trees for 8 categories
  3. Understand the bitset operations and merge these with the HistGradientBoosting bitset operations
  4. benchmark experiments to determine splitting on categories vs not in terms of fit time, accuracy, etc.

Any other comments?

May be related to #24967

Would be nice to merge in #29458

Notes:

  1. breiman_shortcut should either be in only BestSplitter, or a special method of the Partitioner, or even a private function, which is optionally used. It's a private method for use during splitting, so maybe not part of Partitioning.
  2. I think we can enable support for Sparse categories in the next PR
  3. Perhaps information about categories should be passed from parent node since the Tree technically has information about the n_categories, so we can trim down the number of categories. I think this can be implemented last and then benchmarked to determine if this optimization is useful or not. I suspect it is since for categorical splits, there is time involved to "count the unique categories", which seems unnecessary. This is conceptually similar to tracking constant features

Signed-off-by: Adam Li <[email protected]>
Copy link

github-actions bot commented Jul 8, 2024

❌ Linting issues

This PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling pre-commit hooks. Instructions to enable them can be found here.

You can see the details of the linting issues under the lint job here


cython-lint

cython-lint detected issues. Please fix them locally and push the changes. Here you can see the detected issues. Note that the installed cython-lint version is cython-lint=0.16.2.


/home/runner/work/scikit-learn/scikit-learn/sklearn/tree/_utils.pxd:77:1: E303 too many blank lines (3)

Generated for commit: fcebee9. Link to the linter CI: here

Signed-off-by: Adam Li <[email protected]>
adam2392 added 2 commits July 17, 2024 08:53
Signed-off-by: Adam Li <[email protected]>
Signed-off-by: Adam Li <[email protected]>
@adam2392 adam2392 mentioned this pull request Aug 22, 2024
12 tasks
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