可视化输出 把决策树结构写入文件: http://sklearn.lzjqsdd.com/modules/tree.html Mac报错:pydotplus.graphviz.InvocationException: GraphViz's executables not found 解决方案:sudo brew install graphviz 参考写入: http://www.jianshu.com/p/59b510bafb4d
(clf)
| 77 | |
| 78 | |
| 79 | def show_pdf(clf): |
| 80 | ''' |
| 81 | 可视化输出 |
| 82 | 把决策树结构写入文件: http://sklearn.lzjqsdd.com/modules/tree.html |
| 83 | |
| 84 | Mac报错:pydotplus.graphviz.InvocationException: GraphViz's executables not found |
| 85 | 解决方案:sudo brew install graphviz |
| 86 | 参考写入: http://www.jianshu.com/p/59b510bafb4d |
| 87 | ''' |
| 88 | # with open("testResult/tree.dot", 'w') as f: |
| 89 | # from sklearn.externals.six import StringIO |
| 90 | # tree.export_graphviz(clf, out_file=f) |
| 91 | |
| 92 | import pydotplus |
| 93 | from sklearn.externals.six import StringIO |
| 94 | dot_data = StringIO() |
| 95 | tree.export_graphviz(clf, out_file=dot_data) |
| 96 | graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) |
| 97 | graph.write_pdf("output/3.DecisionTree/tree.pdf") |
| 98 | |
| 99 | # from IPython.display import Image |
| 100 | # Image(graph.create_png()) |
| 101 | |
| 102 | |
| 103 | if __name__ == '__main__': |