Decision Tree Visualization with pydotplus

 

A useful snippet for visualizing decision trees with pydotplus. It took some digging to find the proper output and viz parameters among different documentation releases, so thought I’d share it here for quick reference.

The tree here looks at sample characteristics of hired and non-hired job applicants.

from sklearn import tree
from IPython.display import Image
import pydotplus
dt = tree.DecisionTreeClassifier(random_state=3, criterion='entropy',
splitter='best', max_depth=None, min_samples_split=1)

clf = dt.fit(X, Y)
dot_data = tree.export_graphviz(clf, out_file="resume.dot",
feature_names=list(data.drop('Class',1)),class_names=['hired','not-hired'],
filled=True, rounded=True, special_characters=True, leaves_parallel=False)

graph = pydotplus.graphviz.graph_from_dot_file("resume.dot")
Image(graph.create_png())

download-40

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s