我正在尝试生成一个我想使用点进行可视化的决策树。生成的点文件应转换为 png。
虽然我可以使用类似的东西在 dos 中完成最后一个转换步骤
export_graphviz(dectree, out_file="graph.dot")
后跟一个 DOS 命令
dot -Tps graph.dot -o outfile.ps
直接在 python dows 中执行所有这些操作不起作用并产生错误
AttributeError: 'list' object has no attribute 'write_png'
这是我试过的程序代码:
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, …