【问题标题】:Export PDF of decisiontree导出决策树的 PDF
【发布时间】:2019-07-09 10:24:49
【问题描述】:

我正在使用 scikitlearn 向我介绍机器学习,我正在关注本教程 link to yt 但是如果我尝试导出 pdf 决策树,则会出现此错误: 我尝试做:open -w review iris.pdf 结果是:

Impossibile ottenere un descrittore di file che si riferisce alla console

如果我从终端编译我有错误:

Traceback (most recent call last)  File "fstraining.py", line 2, in <module>
import graphviz ImportError: No module named graphviz

感谢关注

【问题讨论】:

  • 错误提示您缺少必需的模块,您是否尝试安装graphviz
  • 谢谢你的回答,但我已经安装了 anaconda,现在它问我一些模块,我如何检查它是否看到我正在为那个模块使用 anaconda? @EdChum
  • 在anaconda提示符下输入conda install graphviz

标签: python machine-learning scikit-learn


【解决方案1】:

构建决策树clf 后,只需:

from sklearn.externals.six import StringIO   
from sklearn.tree import export_graphviz
import pydotplus

# Export resulting tree to DOT source code string
dot_data = export_graphviz(clf,
                           feature_names=col_names,
                           out_file=None,
                           filled=True,
                           rounded=True)

#Export to pdf
pydot_graph = pydotplus.graph_from_dot_data(dot_data)
pydot_graph.write_pdf('tree.pdf')

此答案改编自here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-03
    • 2016-03-03
    • 2021-10-30
    • 2012-12-02
    • 2017-06-05
    • 1970-01-01
    • 2012-08-20
    • 2015-02-06
    相关资源
    最近更新 更多