【发布时间】:2018-01-05 03:18:54
【问题描述】:
我研究了这里列出的解决方案:
但是,这些解决方案都不适合我。特别是,当我尝试 check_call 方法时,我收到以下错误:
File "/Users/anaconda/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
当我使用 pydot 时,我得到这个错误:(graph,)=pydot.graph_from_dot_data(dotfile.getvalue())
TypeError: 'Dot' object is not iterable
这是我在上面的一篇文章中找到的一些示例代码,我一直在测试:
from sklearn import tree
import pydot
import StringIO
from subprocess import check_call
# 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, unknown feature vector
test = [2,2,3]
predicted = dectree.predict(test)
dotfile = StringIO.StringIO()
tree.export_graphviz(dectree, out_file=dotfile)
check_call(['dot','-Tpng','InputFile.dot','-o','OutputFile.png'])
(graph,)=pydot.graph_from_dot_data(dotfile.getvalue())
graph.write_png("dtree.png")
提前致谢。
【问题讨论】: