AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

This is the ml tensorflow code I am trying to execute -

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):

File "C:\Users\admin\test3.py", line 5, in

classifier = skflow.TensorFlowDNNClassifier(hidden_units=[10, 20, 10], n_classes=3) AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'

[Finished in 69.3s with exit code 1]

[shell_cmd: python -u "C:\Users\admin\test3.py"]

回答1:

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.

Try to replace TensorFlowDNNClassifier with just DNNClassifier. 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) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!