【发布时间】:2023-03-06 14:01:01
【问题描述】:
我正在尝试在线学习数据科学,当我从一个 Google 视频运行脚本时,我收到了以下错误:
File "/documents/testpython.py", line 547, in <module>
graph.write_pdf("iris pdf")
File "/anaconda/lib/python3.5/site-packages/pydotplus/graphviz.py", line 1810, in <lambda>
prog=self.prog: self.write(path, format=f, prog=prog)
File "/anaconda/lib/python3.5/site-packages/pydotplus/graphviz.py", line 1918, in write
fobj.write(self.create(prog, format))
File "/anaconda/lib/python3.5/site-packages/pydotplus/graphviz.py", line 1960, in create
'GraphViz\'s executables not found')
pydotplus.graphviz.InvocationException: GraphViz's executables not found
这是脚本:
from sklearn.datasets import load_iris
import numpy as np
from sklearn import tree
iris = load_iris()
test_idx = [0,50,100]
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis = 0)
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]
clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target)
from sklearn.externals.six import StringIO
import pydotplus
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data, feature_names=iris.feature_names, class_names=iris.target_names, filled=True, rounded=True, impurity=False)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf("iris pdf")
如果有人有任何想法,我不确定问题是否来自我的 python 版本或库或其他任何东西......
谢谢
【问题讨论】:
标签: python decision-tree data-science