【问题标题】:How can I print the decision tree classifier in Jupyter notebook?如何在 Jupyter notebook 中打印决策树分类器?
【发布时间】:2017-02-28 20:55:31
【问题描述】:

export_graphviz(treeclf, out_file='tree_titanic.dot', feature_names=feature_cols)

在命令行中,运行此命令以转换为 PNG:

dot -Tpng tree_titanic.dot -o tree_titanic.png

我正在使用上面的代码,但是当我尝试在终端中运行(点命令)时,它不起作用。如何在 jupyter 中运行此命令以可视化树?谢谢。

【问题讨论】:

    标签: scikit-learn decision-tree


    【解决方案1】:

    您可以在 jupyter 中运行终端命令,方法是在命令前添加 !。例如:

    ! dot -Tpng tree_titanic.dot -o tree_titanic.png
    

    您可能需要在系统上安装 Graphviz 才能使用 dot 程序。

    然后您可以使用 jupyter/ipython 中的显示子模块来显示本地文件系统之外的图像。

    【讨论】:

      猜你喜欢
      • 2020-12-12
      • 2019-06-19
      • 2021-05-27
      • 2018-11-18
      • 2019-01-26
      • 2018-10-20
      • 1970-01-01
      • 2021-09-23
      • 2016-01-10
      相关资源
      最近更新 更多