我正在按照Siraj Raval的YouTube视频教程,构建一个用于鸢尾花数据集的简单分类器。视频发布于2016年5月,因此我确定Tensorflow的一些部分已经更新。我遇到了一个错误,提示“请切换到tf.train.get.global_step”。我使用的是较旧版本的Tensorflow库,并且我尝试通过研究feature_columns来解决这个问题。我以为这样可以解决问题,但错误仍然存在。任何帮助都将不胜感激,并且关于如何成为Tensorflow的熟练用户的任何建议都将非常欢迎。
这是我的代码
import tensorflow.contrib.learn as skflowfrom sklearn import datasets, metricsiris = datasets.load_iris()feature_columns = skflow.infer_real_valued_columns_from_input(iris.data)classifier = skflow.LinearClassifier(feature_columns=feature_columns, n_classes=3)classifier.fit(iris.data, iris.target)score = metrics.accuracy_score(iris.target, classifier.predict(iris.data))print("Accuracy: %f" % score)
这是错误信息:
WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.WARNING:tensorflow:Using temporary folder as model directory: C:\Users\isaia\AppData\Local\Temp\tmp8be6vyhqWARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with x is deprecated and will be removed after 2016-12-01.Instructions for updating:Estimator is decoupled from Scikit Learn interface by moving intoseparate class SKCompat. Arguments x, y and batch_size are onlyavailable in the SKCompat class, Estimator will only accept input_fn.Example conversion: est = Estimator(...) -> est = SKCompat(Estimator(...))WARNING:tensorflow:From C:/Users/isaia/PycharmProjects/untitled5/ml.py:10: calling BaseEstimator.fit (from tensorflow.contrib.learn.python.learn.estimators.estimator) with y is deprecated and will be removed after 2016-12-01.Instructions for updating:Estimator is decoupled from Scikit Learn interface by moving intoseparate class SKCompat. Arguments x, y and batch_size are onlyavailable in the SKCompat class, Estimator will only accept input_fn.Example conversion: est = Estimator(...) -> est = SKCompat(Estimator(...))WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.WARNING:tensorflow:From C:\Users\isaia\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\linear.py:173: get_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.Instructions for updating:Please switch to tf.train.get_global_step
提前感谢您的帮助
回答:
这个估计器基本上已经废弃,可能会在Tensorflow的下一个版本中被移除(您会收到多个相关的警告),您应该使用tf.estimator.LinearClassifier
。它的API略有不同,但基本思想是一样的。以下是完整代码: