使用Scikit Learn DecisionTreeClassifier保存Graphviz决策树图

问题描述 投票:0回答:1

我能够使用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个回答
0
投票

您应该在tree.export_graphviz()的末尾添加参数“out_file = None”。

© www.soinside.com 2019 - 2024. All rights reserved.