python - 属性错误: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowLinearClassifier'

标签 python tensorflow neural-network

我是神经网络和 TensorFlow 的新手,遇到了以下错误:

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

这个警告:

WARNING:tensorflow:From C:\Users\virat\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.

这是我的代码:

import tensorflow.contrib.learn as skflow
from sklearn import datasets, metrics
iris=datasets.load_iris()
classifier = skflow.TensorFlowLinearClassifier(n_classes=3)
classifier.fit(iris.data, iris.target)
score = metrics.accuracy_score(iris.target,classifier.predict(iris.data))
print("Accuracy: %f" % score)

我已经在这个网站上浏览过类似的答案,但它们并不令人满意。请帮助消除此错误和警告。

最佳答案

来自tensorflow.contrib.learn.python.learn.datasets.base已被弃用,因此要使用线性分类器请执行以下操作:

  1. 用tensorflow.estimator替换tensorflow.contrib.learn

  2. 将 TensorFlowLinearClassifier() 更改为 LinearClassifier(feature_columns)

其中 feature_columns:包含模型使用的所有特征列的迭代。集合中的所有项目都应该是从FeatureColumn 派生的类的实例。

检查这个Tensorflow Documention , Deprecated message and Fix

关于python - 属性错误: module 'tensorflow.contrib.learn' has no attribute 'TensorFlowLinearClassifier' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49597498/

相关文章:

python - Elasticsearch 滚动结束不返回任何内容

python - 更新 pandas 数据框(具有复杂条件的元素的部分总和)的最快方法

python:国际象棋移动验证

machine-learning - 如何在tensorflow train API中使用我自己的激活函数?

python - 为什么我的tensorflow暂停了?

python - 即使使用最新的 Keras/Theano,ValueError : Invalid argument 'metric' passed to K. 也会起作用

python - 如何使用 Python 检查用户和密码是否已在 MySQL 数据库中?

python-3.x - 在 tf.keras 中创建自定义损失函数

multithreading - 多线程 AForge.NET 培训

matlab - matlab 工具中的 nnstart 问题