dtreeviz: Decision Tree Visualization

raw JSON →
2.3.2 verified Fri May 01 auth: no python

A Python 3 library for visualizing decision trees from scikit-learn, XGBoost, LightGBM, Spark, and TensorFlow. Version 2.3.2 supports AI chat integration for sklearn, categorical variables, and various tree model backends. Releases are frequent, approximately every few months.

pip install dtreeviz
error TypeError: dict() argument after ** must be a mapping, not float
cause Incompatibility with newer versions of numpy or other dependencies, fixed in 2.2.1.
fix
Upgrade dtreeviz to >=2.2.1 or pin numpy to a compatible version.
error KeyError when using decision_boundaries function
cause Bug in version 2.0.x, fixed in 2.1.0.
fix
Upgrade dtreeviz to >=2.1.0.
breaking Version 2.1.0 introduced a major refactoring. Functions like 'ctree_feature_space' changed signature; older code may break.
fix Update function calls to match new signatures. Refer to changelog for specific changes.
gotcha When using categorical features, ensure they are numeric-encoded. dtreeviz does not handle string categories natively in older versions; supported from 2.2.0 onward.
fix Upgrade to >=2.2.0 or encode categories as integers before fitting.

Train a simple decision tree regressor and visualize it with dtreeviz.

from sklearn.datasets import load_diabetes
from sklearn.tree import DecisionTreeRegressor
from dtreeviz import dtreeviz

diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target

regr = DecisionTreeRegressor(max_depth=3)
regr.fit(X, y)

viz = dtreeviz(regr, X, y, target_name='diabetes', feature_names=diabetes.feature_names)
viz.view()