imodels.viz: nice viz for interpretable models

🗂 Doc, 💻 Code


Visualization is critical to understanding fitted models. imodels.viz lets you visualize any imodels model and most sklearn models nicely. It produces either a static figure (SVG, PNG, PDF) or an interactive page (for html or notebooks).

Quickstart
from imodels import FIGSClassifier
from imodels import viz
from sklearn.datasets import load_breast_cancer

X, y = load_breast_cancer(return_X_y=True, as_frame=True)
model = FIGSClassifier(max_rules=8).fit(X, y)

viz.draw(model, X, y).save("figs.svg")             # static: .svg .png .pdf .html
viz.interactive(model, X, y).save("figs.html")     # one offline page; also renders inline in Jupyter
print(model)                                       # the model as readable text

Both calls take the fitted model and, optionally, the training data. With data, every split shows the distribution of its feature and every leaf its class mix or target range; without it, the figure falls back to what the model stores. Other arguments set names (feature_names, class_names, target_name), highlight one sample's path (x=), limit the depth drawn (max_depth), and switch theme, orientation and style. See the API docs.

1. Supported models

scikit-learnimodels · Scaling pipelines are drawn in raw units. Not supported: models without readable structure (kNN, kernel SVMs, MLPs).

Every tree is a scikit-learn tree, so dtreeviz works too

imodels.viz has no drawing code for any particular imodels tree. Every tree-based model is first exported to the scikit-learn estimator that makes the same predictions, with imodels.to_sklearn, and then drawn like any scikit-learn model: single trees (CART variants, HSTree, TAO, C4.5, FastSmallTree) become a DecisionTreeClassifier or DecisionTreeRegressor, IRF becomes a RandomForestClassifier, and FIGS becomes a list of regression trees whose predictions add up, the same view as gradient boosting. The tests check every export against the model's own predict / predict_proba.

import imodels
tree = imodels.to_sklearn(model, X)    # X (optional) recounts each node's samples

# anything that reads scikit-learn trees now reads imodels trees, e.g. dtreeviz
import dtreeviz
dtreeviz.model(tree, X, y, feature_names=list(X.columns)).view()
sklearn.tree.plot_tree(tree)

So the export also makes every tree-based imodels model work with dtreeviz, including ones dtreeviz could not read before, such as C4.5, FastSmallTree and IRF.

2. Interactive mode

viz.interactive writes one self-contained HTML file with no server and no network requests. Across all models the page offers the same tools:

  • Try a sample. Type feature values or load a random training row. The path it takes lights up, and a waterfall shows how the prediction is built (leaf values, rule weights, points or shape-function terms).
  • What would change it. The smallest single-feature and two-feature changes that flip a class, or move a regression prediction the most, with round values just past each threshold.
  • Features panel. Each feature's importance and marginal distribution; click one to highlight every split or rule that uses it.
  • Fold and simplify. Click a split to fold its subtree; the Simple toggle swaps the charts for boxes filled by class proportions. Export the current view as SVG.

Fig 1. A depth-3 tree on iris. Open Predict and change petal length to watch the path move. Open full page.

32 examples, each made by the code in its card. Click a card to see the whole figure, its code and, for live examples, the interactive page.

Classification with training data

Classification with training data

01
DecisionTreeClassifierlive
Simple mode

Simple mode

02
DecisionTreeClassifierlive
A bigger tree

A bigger tree

03
DecisionTreeClassifierlive
Binary and integer features

Binary and integer features

04
DecisionTreeClassifierlive
Regression and one sample's decision path

Regression and one sample's decision path

05
DecisionTreeRegressorlive
Dark theme

Dark theme

06
DecisionTreeClassifier
Left-to-right layout

Left-to-right layout

07
DecisionTreeRegressor
Model only, no data

Model only, no data

08
DecisionTreeClassifier
Deep tree, truncated view

Deep tree, truncated view

09
DecisionTreeClassifierlive
Many classes, compact style

Many classes, compact style

10
DecisionTreeClassifierlive
One tree from a random forest

One tree from a random forest

11
RandomForestClassifier
A gradient boosting stage

A gradient boosting stage

12
GradientBoostingRegressor
Hierarchical shrinkage (HSTree)

Hierarchical shrinkage (HSTree)

13
HSTreeClassifierlive
FIGS: a sum of trees

FIGS: a sum of trees

14
FIGSRegressorlive
C4.5 tree

C4.5 tree

15
C45TreeClassifierlive
Iterative random forest (IRF)

Iterative random forest (IRF)

16
IRFClassifierlive
Greedy rule list

Greedy rule list

17
GreedyRuleListClassifierlive
Bayesian rule list

Bayesian rule list

18
BayesianRuleListClassifierlive
RuleFit

RuleFit

19
RuleFitClassifierlive
Skope rules

Skope rules

20
SkopeRulesClassifierlive
Boosted rules

Boosted rules

21
BoostedRulesClassifierlive
FastRiskScore

FastRiskScore

22
FastRiskScoreClassifierlive
FastRiskScore with categories and missing values

FastRiskScore with categories and missing values

23
FastRiskScoreClassifierlive
SLIM

SLIM

24
SLIMClassifierlive
TreeGAM

TreeGAM

25
TreeGAMRegressorlive
TreeGAM classifier

TreeGAM classifier

26
TreeGAMClassifierlive
Linear model with marginal shrinkage

Linear model with marginal shrinkage

27
MarginalShrinkageLinearModelRegressorlive
Random forest

Random forest

28
RandomForestClassifierlive
Gradient boosting

Gradient boosting

29
GradientBoostingRegressorlive
Histogram gradient boosting

Histogram gradient boosting

30
HistGradientBoostingClassifierlive
Logistic regression in a pipeline

Logistic regression in a pipeline

31
LogisticRegressionlive
Isotonic regression

Isotonic regression

32
IsotonicRegressionlive

Generated by docs/pages/viz_gallery.py on 2026-10-06.