Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## v0.2.0
- [x] Superset branching on categorical features
- [x] More plotting options
- [ ] Exporting to Graphviz, planned for v0.4.0 ([#69](https://github.com/optimal-uoft/sgtlearn/issues/69))
- [x] Exporting to Graphviz with `export_graphviz` ([#69](https://github.com/optimal-uoft/sgtlearn/issues/69))
- [x] Feature importances matching scikit-learn's API for SGTs and SGT$_K$
- [x] Adding TAO Refinement
- [x] **Sklearn-style NaN support**: split search uses finite values only, and each univariate node learns which child receives missing values.
Expand Down
363 changes: 363 additions & 0 deletions docs/_static/export_graphviz_iris.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The public API is re-exported from the top-level ``sgtlearn`` package.
plot_tree
configure_feature_dict
export_text
export_graphviz
make_plus
tao.TAO_refine

Expand Down
36 changes: 35 additions & 1 deletion docs/api/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Plotting & Export

.. currentmodule:: sgtlearn

Visualize a fitted SGT, or export it as indented text rules.
Visualize a fitted SGT, or export it as indented text rules or Graphviz DOT.

plot_tree
---------
Expand Down Expand Up @@ -36,3 +36,37 @@ apply to ``X`` rounded to float32: ``1.5 + 1e-9`` rounds to ``1.5`` and follows
| |--- value: 0.00
|--- x > 1.50
| |--- value: 1.00

export_graphviz
---------------

.. autofunction:: export_graphviz

``export_graphviz`` draws the same panels as ``plot_tree`` with Graphviz
HTML-like labels. Each internal node shows its shape function, shaded by the
child each region routes to, and with ``X`` a histogram of the samples that
reach it (a heatmap with marginal histograms for pair nodes). Edges are colored
by child; hover over an edge in a rendered SVG to see the ``export_text`` rule
for that child. The output is plain DOT text and needs no extra package. To
render it, install the ``graphviz`` Python package and the Graphviz binaries:

.. code-block:: python

import graphviz
from sklearn.datasets import load_iris
from sgtlearn import SGTClassifier, export_graphviz

iris = load_iris()
model = SGTClassifier(num_partitions=3, max_depth=2, random_state=0)
model.fit(iris.data, iris.target)
dot = export_graphviz(
model,
X=iris.data,
feature_names=[n.replace(" (cm)", "") for n in iris.feature_names],
class_names=iris.target_names,
)
graphviz.Source(dot).render("tree", format="svg")

.. image:: ../_static/export_graphviz_iris.svg
:alt: An SGT on iris rendered from export_graphviz, with a shape-function
histogram in each internal node.
2 changes: 1 addition & 1 deletion docs/roadmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ v0.2.0

- ✅ Superset branching on categorical features
- ✅ More plotting options
- ⬜ Exporting to Graphviz, planned for v0.4.0 (see
- ✅ Exporting to Graphviz with ``export_graphviz`` (see
`issue #69 <https://github.com/optimal-uoft/sgtlearn/issues/69>`_)
- ✅ Feature importances matching scikit-learn's API for SGTs and :math:`\mathrm{SGT}_K`
- ✅ TAO refinement
Expand Down
3 changes: 2 additions & 1 deletion sgtlearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

from sgtlearn import tao
from sgtlearn._export import export_text, plot_tree
from sgtlearn._export import export_graphviz, export_text, plot_tree
from sgtlearn.base import (
BaseShapeCART,
ProcessedFeatures,
Expand All @@ -25,6 +25,7 @@
"SGTClassifier",
"SGTRegressor",
"configure_feature_dict",
"export_graphviz",
"export_text",
"make_plus",
"plot_tree",
Expand Down
Loading
Loading