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())