Skip to content

Fix plot_tree crash on truncated and multi-output SGTRegressor nodes - #84

Merged
upadhyan merged 2 commits into
mainfrom
fix/82-plot-tree-regressor
Oct 3, 2026
Merged

upadhyan merged 2 commits into
mainfrom
fix/82-plot-tree-regressor

Conversation

@upadhyan

@upadhyan upadhyan commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #82.

Root cause

_draw_leaf_text formatted node['value'] as one float. tree_export sets value=None on internal regressor nodes and a per-output list on multi-output leaves, and plot_tree draws nodes cut off by max_depth as leaves, so both cases raised TypeError. Classifiers didn't crash because class_counts is filled in on internal nodes too, but multi-output classifiers silently showed only output 0's class (and class_names=True produced garbled labels).

Changes

  • Truncated regressor internals render as ….
  • Multi-output leaves render one entry per output as [a, b], for regressors and classifiers. plot_tree resolves class names per output; pass one list per output for multi-output classifiers (same convention as export_text).
  • The per-output and list formatting helpers move out of export_text, so both renderers share them.
  • The plot_tree docstring states that n= is a rounded weighted count for classifiers and an unweighted count for regressors. Unifying the two needs a change to the C++ export, which is left out of this PR.

Why no test caught it

The only max_depth test used a classifier, and no plot_tree test fitted a 2-D y.

Tests

  • New parametrized regressor test (1 or 2 outputs × max_depth None or 1) and a multi-output classifier test in tests/test_plot_tree.py. Both fail on main and pass on this branch.
  • test-checker blind tests for _draw_leaf_text, promoted to tests/regression/: 9 fail on main and pass here, 30 pass on both, none fail here.
  • Full suite: 1246 passed, 2 skipped.

🤖 Generated with Claude Code

upadhyan and others added 2 commits October 2, 2026 22:02
plot_tree raised TypeError for an SGTRegressor drawn with max_depth, or
fitted on a multi-output y (#82). _draw_leaf_text formatted node['value']
as one float, but tree_export sets value=None on internal nodes and a
per-output list on multi-output leaves, and plot_tree draws nodes cut off
by max_depth as leaves. Classifiers did not crash because class_counts is
filled in on internal nodes too, but multi-output classifiers silently
showed only output 0's class.

Truncated regressor internals now render as "…". Multi-output leaves
render one entry per output as "[a, b]" for both regressors and
classifiers; plot_tree resolves class names per output (pass one list per
output for multi-output classifiers). The per-output and list formatting
helpers move out of export_text so both renderers share them. The
plot_tree docstring now states that n= is a rounded weighted count for
classifiers and an unweighted count for regressors.

No test caught this: the only max_depth test used a classifier, and no
plot_tree test fitted a 2-D y. Add a regressor test over single and
multi-output, with and without max_depth, plus a multi-output classifier
test, and the test-checker blind tests promoted for _draw_leaf_text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upadhyan
upadhyan merged commit 58dfc52 into main Oct 3, 2026
16 checks passed
@upadhyan
upadhyan deleted the fix/82-plot-tree-regressor branch October 3, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot_tree crashes on SGTRegressor with max_depth truncation or multi-output y

1 participant