AttributeError: module 'tensorflow.contrib.learn' does not have the attribute 'TensorFlowDNNClassifier'

This is the ml tensorflow code I'm 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) 

He gives the following error -

Traceback (last last call):

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' does not have the attribute 'TensorFlowDNNClassifier'

[Finished in 69.3 with exit code 1]

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

+8
python scikit-learn machine-learning tensorflow
source share
2 answers

It seems like a serious refactoring has skflow place in the skflow project, and all the skflow code skflow been moved to the main tensor stream repository.

Try replacing TensorFlowDNNClassifier with only DNNClassifier . A new class can be found here . Your corrected code will look like this:

 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) 
+6
source share
 import tensorflow.contrib.learn.python from tensorflow.contrib.learn.python import learn as learn 
0
source share

All Articles