Last active
August 8, 2017 01:54
-
-
Save ratchetwrench/3c8782b8d431f4a62329a8031fac9b78 to your computer and use it in GitHub Desktop.
Plot a CART Decision Tree from sklearn with pydotplus and graphviz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_tree(): | |
"""Make sure you have the correct imports. | |
Imports: | |
from sklearn import tree | |
import pydotplus | |
from IPython.display import Image | |
Note: Make sure you already have a 'tree'. | |
... | |
clf = tree.DecisionTreeClassifier() | |
clf = clf.fit(X, y) | |
... | |
""" | |
dot_data = tree.export_graphviz(clf, out_file=None) | |
graph = pydotplus.graph_from_dot_data(dot_data) | |
return Image(graph.create_png()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment