Repository navigation
Add export_graphviz with plot_tree-style node panels - #92
Merged
Merged
Conversation
Edge labels reuse the export_text routing rules, so both exports agree. Nodes show samples, value and class; filled=True shades them like sklearn. Closes #69.
Internal nodes now show their shape function shaded by destination child, with an optional X histogram (pair nodes: routing heatmap with marginal histograms). Edges are coloured by child and carry the export_text rule as a tooltip instead of a label.
Each colour switch in a univariate panel now gets a tick, with its threshold label centred under it (overlapping labels drop to a further row), and the NaN label sits under the NaN column.
Continuous pair axes get a tick at each colour switch (including switches visible only in the other axis's missing margin) with the threshold label beside it: x below the heatmap, y to its left. Categorical axes and missing margins are labelled per cell.
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.
Closes #69.
What
Adds
sgtlearn.export_graphviz(estimator, out_file=None, *, X=None, feature_names=None, class_names=None, filled=False, decimals=2), which returns (or writes) Graphviz DOT source for a fittedSGTClassifier/SGTRegressor.Internal nodes draw the same panels as
plot_tree, using Graphviz HTML-like labels, so the DOT is self-contained andgraphvizstays out of the dependencies:X, a histogram of the samples reaching the node, with bars coloured by child, plus a NaN column. Each colour switch gets a tick, and its threshold label is centred under it. Labels that would overlap move to another row.X, cells that contain samples are drawn in full colour, with gray marginal histograms. Continuous axes are ticked and labelled at each switch, x below and y to the left. This includes switches that only show in the other axis's missing margin.export_textrule, computed by the same_child_regionsfunction, so the two exports can't disagree.filled=Trueshades leaves the way sklearn does.Docs
export_graphvizis back in__all__,docs/api/index.rstanddocs/api/plotting.rst.docs/_static/export_graphviz_iris.svg, and show how to render withgraphviz.Source.ROADMAP.mdanddocs/roadmap.rst) is ticked again.Tests
In
tests/test_export_text.py:export_textlines for the univariate, categorical, pair-classifier and pair-regressor fixtures (K = 3 and K = 9).Xis given.feature_names,Xshape).All 1424 tests pass. I rendered the output with viz.js (Graphviz compiled to WebAssembly) and it produced no Graphviz warnings. It hasn't been rendered with the native
dotbinary, which isn't installed on my machine.Known limits
plot_treeuses exact interval widths.