SaoudAlawi / auto-regression

AutoML Application
1 stars 0 forks source link

Visualize RandomTreeForest #5

Open SaoudAlawi opened 2 years ago

SaoudAlawi commented 2 years ago

Dtreeviz — Plot a decision tree on a classification dataset

This lib provides wonderful visuals.

Example code for visualizing classification tree

from sklearn.datasets import load_wine
from sklearn.ensemble import RandomForestClassifier
from dtreeviz.trees import dtreeviz

wine = load_wine()
X = wine.data
y = wine.target

rf = RandomForestClassifier(n_estimators=100,
                            max_depth=3,
                            max_features='auto',
                            min_samples_leaf=4,
                            bootstrap=True,
                            n_jobs=-1,
                            random_state=0)
rf.fit(X, y)

viz = dtreeviz(rf.estimators_[99], X, y,
               target_name="wine category",
               feature_names=wine.feature_names,
               class_names=list(wine.target_names),
               title="100th decision tree - Wine data")

viz.save("decision_tree_wine.svg")

from google.colab import files
files.download("decision_tree_wine.svg")