【问题标题】:Saving Graphviz decision tree plot using Scikit Learn DecisionTreeClassifier使用 Scikit Learn DecisionTreeClassifier 保存 Graphviz 决策树图
【发布时间】:2019-06-12 03:03:19
【问题描述】:

我可以使用 graphviz 生成决策树图,但是当我尝试保存它时(即 out_file)

我收到以下错误:

CalledProcessError:命令 '['dot', '-Tsvg']' 返回非零退出 状态 1。

这是我的代码:

# create plot for decision tree
dot_data = tree.export_graphviz(model, 
                                out_file='tree.dot', # this is what triggers the error
                                feature_names=X_test.columns,
                                class_names=['Active','Churned']) 

graph = graphviz.Source(dot_data) 

# view plot 
graph

out_file 参数是触发错误的参数。我认为这应该是一个非常简单的解决方案,但我没有从搜索中找到答案。

提前谢谢你。

【问题讨论】:

标签: python plot scikit-learn graphviz decision-tree


【解决方案1】:

您应该在 tree.export_graphviz() 的末尾添加一个参数 "out_file = None"

【讨论】:

  • 您能否详细说明您的答案?
猜你喜欢
  • 2017-02-23
  • 2020-04-05
  • 2017-03-26
  • 2017-01-21
  • 1970-01-01
  • 2019-12-26
  • 2015-03-05
  • 2014-06-26
相关资源
最近更新 更多