0

I need the image of the complete tree that I generated but it does not wrap around neither there is a download or save image option. The only remaining option is to take a screenshot which doesn't capture the entire tree.

How do I get the entire tree?

I've generated a tree using this method in Spyder

#Displaying the decision tree
from sklearn import tree
#from StringIO import StringIO
from io import StringIO
#from StringIO import StringIO 
with open("classifier.txt", "w") as f:
 f = tree.export_graphviz(classifier, out_file=f)

This generates a file classifer.txt which when copied and pasted into http://webgraphviz.com/ generates a decision tree

Here is the image of the output

The snapshot has zoomed out to the maximum possible extent.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tegr4
  • 13
  • 6
  • first, you are outputting your data not in a correct way, according to the [documentation](http://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html) use `tree.export_graphviz(classifier, out_file=f)` or use `f = tree.export_graphviz(classifier)` Second read this maybe this can help https://stackoverflow.com/questions/1494492/graphviz-how-to-go-from-dot-to-a-graph – Himanshu Bansal Nov 15 '17 at 07:58

1 Answers1

0

Ok So I've fixed the solution by doing some extensive googling and now am able to save it as a png.

Displaying the decision tree

graph=pydotplus.graph_from_dot_data(out.getvalue())

“’ # Display inline image of Tree - Inline image is not useful

Img=(Image(graph.create_png()))

display(Img)

”’

#Write image to file so it can be rotated and expanded

graph.write_png('Your_File_Name.png’)
Community
  • 1
  • 1
Tegr4
  • 13
  • 6