[英]AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'
This is the ml tensorflow code I am trying to execute - 这是我试图执行的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)
It gives the following error - 它给出以下错误 -
Traceback (most recent call last): Traceback(最近一次调用最后一次):
File "C:\\Users\\admin\\test3.py", line 5, in 文件“C:\\ Users \\ admin \\ test3.py”,第5行,in
classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3) AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier' classifier = skflow.TensorFlowDNNClassifier(hidden_units = [10,20,10],n_classes = 3)AttributeError:模块'tensorflow.contrib.learn'没有属性'TensorFlowDNNClassifier'
[Finished in 69.3s with exit code 1] [完成69.3s,退出代码1]
[shell_cmd: python -u "C:\\Users\\admin\\test3.py"] [shell_cmd:python -u“C:\\ Users \\ admin \\ test3.py”]
There seems to have been a major refactor in the TensorFlow project, and all the skflow
code has been moved under the main tensorflow repository. TensorFlow项目中似乎有一个主要的重构,并且所有skflow
代码都已在主tensorflow存储库下移动。
Try to replace TensorFlowDNNClassifier
with just DNNClassifier
. 尝试用DNNClassifier
替换TensorFlowDNNClassifier
。 The new class can be found out here . 新课程可以在这里找到。 Your corrected code will look like, 您的更正后的代码看起来像,
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)
import tensorflow.contrib.learn.python from tensorflow.contrib.learn.python import learn as learn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.