Reputation: 351
I am using IPython on Windows10 to train and draw out a decision tree. I know the following code worked on linux some time back. I installed pydot and also have graphviz (with the path correctly specified).
# Train and draw out a decision tree
from IPython import display
from sklearn import datasets, tree, utils
from sklearn.externals.six import StringIO
import pydot
# Train a small decision tree on the iris dataset
dataset = datasets.load_iris()
X_iris, y_iris = utils.shuffle(dataset.data, dataset.target,random_state=42)
tree_clf = tree.DecisionTreeClassifier(max_depth=3).fit(X_iris, y_iris)
# Generate a plot of the decision tree
dot_data = StringIO()
tree.export_graphviz(tree_clf, out_file=dot_data)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
display.Image(graph.create_png())
I get the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-3452aa5e9794> in <module>()
15 tree.export_graphviz(tree_clf, out_file=dot_data)
16 graph = pydot.graph_from_dot_data(dot_data.getvalue())
---> 17 display.Image(graph.create_png())
AttributeError: 'list' object has no attribute 'create_png'
Upvotes: 1
Views: 1559
Reputation: 41
I solved this problem by changing all the pydot
command into pydotplus
.(including import pydotplus
)It may be possible use !pip install pydotplus
to install pydotplus package.
Reference https://github.com/scikit-learn/scikit-learn/pull/7342/files
Upvotes: 1