AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'
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)