TensorFlowDNNClassifier

TensorFlowDNNClassifier

这是我试图执行的ml tensorflow 代码-

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics
iris = datasets.load_iris()
classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))

print("Accuracy: %f" % score)

它给出以下错误-

最佳答案

TensorFlow项目中似乎已经进行了重大重构,并且所有skflow代码都已移至tensorflow主存储库下。

尝试仅用TensorFlowDNNClassifier替换DNNClassifier。可以在here中找到新的类。您更正后的代码如下所示:

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics
iris = datasets.load_iris()
# made a change in the next line
classifier = skflow.DNNClassifier(hidden_units=[10, 20, 10], n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))

print("Accuracy: %f" % score)

关于python - AttributeError : module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41372375/

10-12 21:56