I've studied the solutions outlined here:
However, none of these solutions work for me. In particular, when I try the check_call method, I get the following error:
File "/Users/anaconda/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
When I use pydot, I get this error: (graph,)=pydot.graph_from_dot_data(dotfile.getvalue())
TypeError: 'Dot' object is not iterable
Here is some example code I found on one of the above posts that I've been testing:
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")
Thanks in advance.