我需要我所生成的完整树的图像,但它没有包装,也没有下载或保存图像选项。剩下的唯一选择就是拍摄一个截图,它不能捕捉到整个树。
我怎么弄到整棵树?
我在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)这会生成一个文件classifer.txt,当复制并粘贴到http://webgraphviz.com/中时,它会生成一个决策树。
快照已放大到最大可能的范围。
发布于 2017-11-15 14:15:43
好的,我已经修复了这个解决方案,做了一些广泛的谷歌搜索,现在可以将它保存为一个png。
显示决策树
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’)https://stackoverflow.com/questions/47301472
复制相似问题