Skip to content

Instantly share code, notes, and snippets.

@crawles
Last active October 17, 2017 21:32
Show Gist options
  • Save crawles/556b0d56852c493a1388274cc8932135 to your computer and use it in GitHub Desktop.
Save crawles/556b0d56852c493a1388274cc8932135 to your computer and use it in GitHub Desktop.
Plot a sklearn decision tree
import pydot
from IPython.display import Image
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
dot_data = StringIO()
export_graphviz(cl, out_file=dot_data,
feature_names=Xtrain.columns,
class_names=['class0','class1'],
filled=True, rounded=True,
special_characters=True)
graph = pydot.graph_from_dot_data(dot_data.getvalue())[0]
Image(graph.create_png())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment