Repository navigation
Conversation
export_text, export_graphviz and plot_tree built split labels from
tree_.threshold, which is -inf for native categorical splits, so these
nodes were shown as "feature <= -inf".
Decode the categories sent to the left child from the node bitset (or
the hash seed for ExtraTree splits) and display them by name, e.g.
"color in {red, blue}".
Fixes scikit-learn#35534
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
Author
|
Closing as a duplicate of #34809, which came first and covers the same fix more completely. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Fixes #35534.
What does this implement/fix? Explain your changes.
export_text,export_graphvizandplot_treebuilt split labels fromtree_.threshold, which is-inffor native categorical splits, so these nodes were shown asfeature <= -inf.This PR uses
tree_.split_kindto detect categorical splits and decodes the categories sent to the left child:SPLIT_CATEGORICAL_BITSET: fromtree_._left_cat_bitset;SPLIT_CATEGORICAL_HASH(ExtraTree*): by evaluating the routing hash for each category code with the stored seed.Category names come from the fitted encoder (
_categorical_encoder.categories_). When it is not available (e.g. a rawTreepassed toexport_graphviz), the encoded integers are shown.Output for the example in the issue:
plot_treeandexport_graphvizlabel the nodecolor in {green, yellow}.Tests check, for all three exporters and for both split kinds, that the printed set matches the routing given by
tree.apply.Introduce yourself
Hi, I'm Dishan, a final-year engineering student in AIML. I've used scikit-learn a lot in my ML coursework and projects, so I wanted to start contributing back. This is my first contribution to scikit-learn, I'm happy to adjust the approach based on your feedback.
AI usage disclosure
I used AI assistance for:
Any other comments?
Open questions for reviewers: