AttributeError:模块"tensorflow.contrib.learn"没有属性"TensorFlowDNNClassifier" [英] AttributeError: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowDNNClassifier'

查看:197
本文介绍了AttributeError:模块"tensorflow.contrib.learn"没有属性"TensorFlowDNNClassifier"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要执行的ml张量流代码-

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)

它出现以下错误-

回溯(最近通话最近一次):

Traceback (most recent call last):

文件

分类器= skflow.TensorFlowDNNClassifier(hidden_​​units = [10,20,10],n_classes = 3)AttributeError:module'tensorflow.contrib.learn' 没有属性"TensorFlowDNNClassifier"

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

[在69.3秒内完成,退出代码为1]

[Finished in 69.3s with exit code 1]

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

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

推荐答案

在TensorFlow项目中似乎已经进行了重大重构,并且所有skflow代码都已移至主

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.

尝试仅用DNNClassifier替换TensorFlowDNNClassifier.可以在

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)

这篇关于AttributeError:模块"tensorflow.contrib.learn"没有属性"TensorFlowDNNClassifier"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆