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
Year Fixed EffectsI have a general question about the year fixed effects. Actually I want to include both year fixed e…
Multilevel SEMI have a question about SEM and would like to learn some solutions. Suppose I use three indicators …
Panel data dummy variables are being omittedI tried to do a regression on the overestimation of companies, including two dummy variables: the se…
Altering size of dots when using marginsplotI am graphing my output using -marginsplot- and am running into trouble altering the size of the mar…
Export Tables into Excel Using PutexcelHello, I was trying to export the table into Excel. Here is my code: Code: local excel = "C:\User…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with plotting a decision tree using Stata 16's Stata/Python integration
Post a Comment