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
-lnoffset- and -exposure- options from -glm-Dear All, Good afternoon. I do hope this one finds you well. While challenging myself with the examp…
How to convert daily data to yearly dataHi, I am currently having daily data and I would like to convert it to yearly data. Ultimately, I wo…
Graph with a binomial category. Example in post!Good afternoon! https://cdn.jamanetwork.com/ama/cont...5G5CRDK6RD3PGA If I wanted to make a gra…
Curious histogram glitch?Array I can't find this reported before, and I am pretty sure it's NOT my data. Array Above, the re…
converting string variables to numericI have a string variable that I want to change to numeric but I can't. Can you help me please stora…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with plotting a decision tree using Stata 16's Stata/Python integration
Post a Comment