我尝试在线学习数据科学,当我从某个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版本还是库或其他任何内容......
由于