在Tensor flow Python中使用线性回归模型预测

时间:2018-06-10 04:29:33

标签: python tensorflow machine-learning tensorflow-estimator

我是张贴流量的新手,并且遵循其建议的初学者教程。以下是与线性回归量相关的代码片段。

#Configure the linear regressor model
linear_regressor = tf.estimator.LinearRegressor(
    feature_columns = feature_columns,
    optimizer = my_optimizer,
    model_dir = "/Users/nickglidden/Desktop/pythonwork/aidentensor

aidentensor是包含本教程所需的所有文件的文件夹(这个python文件和一个CSV文件)直观地说,那就是我应该存储我训练好的模型的权利吗?

然而,当我执行我的代码时..

Traceback (most recent call last):
File "/Users/nickglidden/Desktop/pythonwork/aidentensor/first.py", line 85, in <module>
predictions = np.array([item['predictions'][0] for item in predictions])
File "/Users/nickglidden/Desktop/pythonwork/aidentensor/first.py", line 85, in <listcomp>
predictions = np.array([item['predictions'][0] for item in predictions])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 488, in predict
self._model_dir))
ValueError: Could not find trained model in model_dir: /Users/nickglidden/Desktop/pythonwork/aidentensor.

我看到错误与预测语句有关,这里是:

predictions = linear_regressor.predict(input_fn=prediction_input_fn)

predictions = np.array([item['predictions'][0] for item in predictions])

原始教程甚至没有在线性回归代码中包含model_dir =“”,我偶然发现了遇到此问题的其他人,并且有人建议添加model_dir是所述解决方案。我包括或不包括相同的错误。有什么想法吗?

0 个答案:

没有答案