Skip to content

Instantly share code, notes, and snippets.

@jamespaultg
Created March 16, 2018 07:18
Show Gist options
  • Select an option

  • Save jamespaultg/e5dfcb16013d624ee3e86757749b358b to your computer and use it in GitHub Desktop.

Select an option

Save jamespaultg/e5dfcb16013d624ee3e86757749b358b to your computer and use it in GitHub Desktop.
Visualise Decision Tree
# visualise the decision tree
from sklearn.externals.six import StringIO
from IPython.display import Image
from sklearn.tree import export_graphviz
import pydotplus
dot_data = StringIO()
# ensure that variable tree has the decision tree, and features contains the names of the features
export_graphviz(tree,
out_file=dot_data,
feature_names = features,
class_names = ['low','medium','high'],
filled=True, rounded=True,
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment