Skip to content

ENH Render categorical splits in tree exporters - #34809

Open
lcrmorin wants to merge 13 commits into
scikit-learn:mainfrom
lcrmorin:export-dict-20051
Open

lcrmorin wants to merge 13 commits into
scikit-learn:mainfrom
lcrmorin:export-dict-20051

Conversation

@lcrmorin

@lcrmorin lcrmorin commented Aug 24, 2026 •

Copy link
Copy Markdown

Reference Issues/PRs

Addresses categorical exporting in #33965. Following review feedback, this PR focuses on standalone decision trees and ExtraTrees in the existing exporters. The public export_dict API is not included.

What does this implement/fix?

Add categorical split rendering to export_text, export_graphviz and plot_tree, preserving numerical output.

  • Standalone classifiers and regressors show original category labels. Text reports list the categories on each branch; Graphviz and plots show the full left-category set.
  • Missing/unknown routing is shown explicitly. Shared helpers reuse tree routing logic and handle category lookup, formatting and escaping.
  • Forest sub-estimators with categorical splits raise a clear error because they lack their own category encoder. Numeric-only and single-leaf forest trees still export normally.

The scope has been reduced by removing the integer-code fallback, max_categories, truncation and smaller-side selection. No new public display parameters are introduced. Large category sets can produce long labels; this limitation is documented.

Five files changed: +122/-11 implementation (including docstrings), +213 tests and +30 documentation; total +365/-11, 108 fewer added lines than the previous version.

Validation

  • Local tree suite and exporter doctests: 972 passed, 9 skipped. All 52 tree-guide doctest examples passed. Lint and formatting passed before incorporating the latest upstream merge, which did not change the tree files.
  • Forest regression coverage checks categorical errors, successful numeric-only export and single-leaf export across all three exporters and four forest types.
  • New CI was triggered by the push of 68ffefb; results are pending. Previous green CI does not validate this simplified version.

Possible follow-ups

  • Support original category labels when exporting forest sub-estimators, with an agreed way to retain or supply their mapping.
  • Discuss optional display limits and smaller-side rendering separately if needed for large category sets.
  • Revisit the public export_dict API for sklearn.tree.export_dict #20051. Its implementation is preserved on a separate branch, which will need adapting to the simplified helpers.

AI tools assisted with these changes.

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.

  • The pull request addresses an existing issue that is ready for contribution (e.g. not tagged as 'Needs Triage', 'Needs Decision', ...). If you are proposing a new feature, please open an issue to discuss it first.

  • There are no other open pull requests already targeting the same issue.

  • You have followed the pull request checklist. In particular, linting and tests should pass.

@lcrmorin lcrmorin changed the title Export dict 20051 Add Export dict #20051 Aug 24, 2026
@lcrmorin lcrmorin changed the title Add Export dict #20051 ENH Export decision trees as dictionaries and render categorical splits Oct 1, 2026
@lcrmorin
lcrmorin marked this pull request as draft October 6, 2026 05:16
Comment thread sklearn/tree/_export.py Resolved
@lcrmorin lcrmorin changed the title ENH Export decision trees as dictionaries and render categorical splits ENH Export decision trees as dictionaries Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

This PR exceeds the recommended size of 500 lines changed. Consider splitting it into smaller PRs to ease the review process. Please make sure you read our Contributing guide and in particular our Pull Request guidelines

@lcrmorin lcrmorin changed the title ENH Export decision trees as dictionaries ENH Render categorical splits in tree exporters Nov 23, 2026
@github-actions github-actions Bot added size/L and removed size/XL labels Nov 23, 2026
@lcrmorin
lcrmorin marked this pull request as ready for review November 27, 2026 07:17

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.

BUG Tree export functions display native categorical splits as <= -inf

2 participants