Dear all,

I have a problem with the Stata/Python integration. I would like to plot a tree after using the "DecisionTreeClassifier()" from the Scikit-Learn Python library. When I run the code (see below) into Python it works perfectly, but when I run the same code into Stata it comes up with this error:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.7/site-packages/pydotplus/graphviz.py", line 1797, in <lambda>
lambda f=frmt, prog=self.prog: self.create(format=f, prog=prog)
File "/anaconda3/lib/python3.7/site-packages/pydotplus/graphviz.py", line 1960, in create
'GraphViz\'s executables not found')
pydotplus.graphviz.InvocationException: GraphViz's executables not found
(1 line skipped)


It seems Stata does not find and executable file when using graphviz.

The Stata code I run is this one (the Python code is the same except for the line "import sfi").

-------------------------------------------------------------------------
python:
# Load libraries
import sfi
from sklearn.tree import DecisionTreeClassifier
from sklearn import datasets
from IPython.display import Image
from sklearn import tree
import pydotplus
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Create decision tree classifer object
clf = DecisionTreeClassifier(random_state=0)
# Train model
model = clf.fit(X, y)
# Create DOT data
dot_data = tree.export_graphviz(clf, out_file=None,
feature_names=iris.feature_names,
class_names=iris.target_names)
# Draw graph
graph = pydotplus.graph_from_dot_data(dot_data)
# Show graph
Image(graph.create_png())
end

-------------------------------------------------------------------------


Any help?

Thanks in advance.

Best,

Giovanni









--

Dr. Giovanni Cerulli

IRcRES-CNR

Phone: 003949937846

Mobile: 00393475283966