生成可视化决策树遇到的 GraphViz's executables not found

Scikit的官网上 ,找到的生成可视化的决策树的代码如下:


from IPython.display import Image
import pydotplus

dot_data = sklearn.tree.export_graphviz(clf, out_file=None,
    feature_names=iris.feature_names,
    class_names=iris.target_names,
    filled=True, rounded=True,
    special_characters=True)

graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_pdf("iris.pdf") 
    

运行报错如下:

pydotplus.graphviz.InvocationException: GraphViz's executables not found

  1. 安装GraphViz可以解决。通过 brew install graphviz 命令安装。

  2. 安装完成后重启IDE ,就可以生成可视化的pdf和png了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容