我試圖遵循Google的機器學習影片我特別停留在這一點上(https://youtu.be/tNa99PG8hR8?t=265)NameError:全局名稱「dot_parser」沒有定義/ PydotPlus/Pyparsing 2 /蟒蛇
我在一個工作的Spyder/Python的2.7:
from sklearn.datasets import load_iris
import numpy as np
from sklearn import tree
iris = load_iris()
test_idx = [0,50,100]
#Training Data
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis=0)
#testing data
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]
clf = tree.DecisionTreeClassifier()
clf.fit(train_data, train_target)
print test_target
print clf.predict(test_data)
#Copied code
from sklearn.externals.six import StringIO
import pydot
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,
special_characters=True)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf("iris.pdf")
輸出繼電器是
NameError: global name 'dot_parser' is not defined
im使用PydotPlus和Pyparsing 2的指示: NameError: global name 'dot_parser' is not defined
從conda list
我得到
pyparsing 2.0.3 py27_0 defaults
pydotplus 2.0.2 <pip> defaults
任何幫助,將不勝感激,首次海報:-O