Created
March 16, 2018 07:18
-
-
Save jamespaultg/e5dfcb16013d624ee3e86757749b358b to your computer and use it in GitHub Desktop.
Visualise Decision Tree
This file contains hidden or 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
| # 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