Skip to content

nekoumei/dtreeplt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dtreeplt

it draws Decision Tree not using Graphviz, but only matplotlib.
If interactive == True, it draws Interactive Decision Tree on Notebook.

Note

On sklearn newer than 0.21, sklearn.tree.plot_tree is implemented.
This also draws trees not using Graphviz.

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
from sklearn.tree import plot_tree
%matplotlib inline

iris = load_iris()
model = DecisionTreeClassifier()
model.fit(iris.data, iris.target)

fig = plt.figure(figsize=(15, 8))
ax = fig.add_subplot()
plot_tree(model, feature_names=iris.feature_names, ax=ax, class_names=iris.target_names, filled=True);

graphviz

Output Image using proposed method: dtreeplt (using only matplotlib)

graphviz

Output Image using conventional method: export_graphviz (Using Graphviz)

graphviz

Output Image using dtreeplt Interactive Decision Tree

graphviz

Installation

If you want to use the latest version, please use them on git.

pip install git+https://github.com/nekoumei/dtreeplt.git

when it comes to update, command like below.

pip install git+https://github.com/nekoumei/dtreeplt.git -U

Requirements: see requirements.txt
Python 3.6.X.

Usage

Quick Start

from dtreeplt import dtreeplt
dtree = dtreeplt()
dtree.view()
# If you want to use interactive mode, set the parameter like below.
# dtree.view(interactive=True)

Using trained DecisionTreeClassifier

# You should prepare trained model,feature_names, target_names.
# in this example, use iris datasets.
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from dtreeplt import dtreeplt

iris = load_iris()
model = DecisionTreeClassifier()
model.fit(iris.data, iris.target)

dtree = dtreeplt(
    model=model,
    feature_names=iris.feature_names,
    target_names=iris.target_names
)
fig = dtree.view()
#if you want save figure, use savefig method in returned figure object.
#fig.savefig('output.png')

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published