相关疑难解决方法(0)

将决策树直接转换为png

我正在尝试生成一个我想使用点进行可视化的决策树。生成的点文件应转换为 png。

虽然我可以使用类似的东西在 dos 中完成最后一个转换步骤

export_graphviz(dectree, out_file="graph.dot")
Run Code Online (Sandbox Code Playgroud)

后跟一个 DOS 命令

dot -Tps graph.dot -o outfile.ps
Run Code Online (Sandbox Code Playgroud)

直接在 python dows 中执行所有这些操作不起作用并产生错误

AttributeError: 'list' object has no attribute 'write_png'
Run Code Online (Sandbox Code Playgroud)

这是我试过的程序代码:

from sklearn import tree  
import pydot
import StringIO

# Define training and target set for the classifier
train = [[1,2,3],[2,5,1],[2,1,7]]
target = [10,20,30]

# Initialize Classifier. Random values are initialized with always the same random seed of value 0 
# (allows reproducible results)
dectree = tree.DecisionTreeClassifier(random_state=0)
dectree.fit(train, target)

# Test classifier with other, …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

scikit-learn ×1