相关资源下载github:https://github.com/parrt/dtreeviz
安装:
pip install dtreeviz # install dtreeviz for sklearn
pip install dtreeviz[xgboost] # install XGBoost related dependency
pip install dtreeviz[pyspark] # install pyspark related dependency
pip install dtreeviz[lightgbm] # install LightGBM related dependency
pip install dtreeviz[tensorflow_decision_forests] # install tensorflow_decision_forests related dependency
pip install dtreeviz[all] # install all related dependencies
例子1:鸢尾属植物数据集
代码:
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
import dtreeviz
iris = load_iris()
X = iris.data
y = iris.target
clf = DecisionTreeClassifier(max_depth=4)
clf.fit(X, y)
viz_model = dtreeviz.model(clf,
X_train=X, y_train=y,
feature_names=iris.feature_names,
target_name='iris',
class_names=iris.target_names)
v = viz_model.view() # render as SVG into internal object
v.show() # pop up window
# v.save("/tmp/iris.svg") # optionally save as svg