我正在尝试显示树输出,但是当我运行下面的脚本时,我收到如下错误:
InvocationException:找不到 GraphViz 的可执行文件
我在这里搜索过类似的主题,但大多数都与 Mac 相关。我使用的是 Windows 10 64 位操作系统,我使用的是 Anaconda-3 64 位。我很想听听您对此的建议。
#Displaying the decision tree
from sklearn import tree
#from StringIO import StringIO
from io import StringIO
#from StringIO import StringIO
from IPython.display import Image
out = StringIO()
tree.export_graphviz(classifier, out_file=out)
import pydotplus
graph=pydotplus.graph_from_dot_data(out.getvalue())
Image(graph.create_png())
编辑:我再次安装了 graphviz 和 pydotplus 模块,但现在仍在工作。
原文由 Cagdas Kanar 发布,翻译遵循 CC BY-SA 4.0 许可协议
我有同样的问题。这是 ((Win10, Anaconda3, Jupyter notebook, python 3.x) 的解决方案
下载并安装 https://graphviz.gitlab.io/_pages/Download/Download_windows.html
将 graphviz 安装路径 (C:…\graphviz\bin) 添加到控制面板 > 系统和安全 > 系统 > 高级系统设置 > 环境变量 > 路径 > 编辑 > 新建
非常重要:重启你的 Jupyter notebook/机器。我尝试重新启动机器并且它起作用了。
这个问题针对不同的操作系统在这里得到了回答: Graphviz’s executables are not found (Python 3.4)