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
Related Posts with Problem with plotting a decision tree using Stata 16's Stata/Python integration
Instrument Variable and endogeneity test interpretationsIn my regression, dependent(y) variable is inj_hour independent (x) variable is dummy_recessions_wor…
Mismathing data when summarizing a variableWhen I try to summarize data the information that the functio returns to me doesn't match with what …
How can I multiply two category variables by another category variable to create a new variable? Hi All, I want to create a new variable which is (Age * Education levels). But the problem is that…
Store results of a statsby for use in a graphHi, I am trying to create a graph that depicts average age that a child gets their first phone by a …
In a loop, strtrim() won't work in some of my variablesHello everyone! I'm facing a little difficulty using the strtrim() command here. As always, I looked…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with plotting a decision tree using Stata 16's Stata/Python integration
Post a Comment