Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Last active August 29, 2015 14:26
Show Gist options
  • Save vaclavcadek/390ea0351b4db30ea6e9 to your computer and use it in GitHub Desktop.
Save vaclavcadek/390ea0351b4db30ea6e9 to your computer and use it in GitHub Desktop.
Vizualize sklearn decision tree using graphviz
from sklearn.externals.six import StringIO
from sklearn import tree
from graphviz import Source
from IPython.display import SVG
def vizualize_tree(model, figsize=(14,8)):
out = StringIO()
tree.export_graphviz(model, out_file=out)
graph = Source(out.getvalue())
graph.format = 'svg'
graph.render(cleanup=True)
return SVG(filename='Source.gv.svg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment