在一个简单的例子中,我尝试使用TensorFlow LinearRegressor,但结果不正确。有什么建议吗?
import tensorflow as tf
import numpy as np
x_data =np.array([ 44.57, 42.71, 119.25, 40.83, 46.87, 71.44,
113.5, 39.83, 39.48,
77.3, 53.32 , 21.68 , 113.55 , 40.1 , 77.39 , 46.01 ,
35.42 , 93.81,
84.71, 51.7 , 73.57, 102.21 , 98.05 , 99.53 ,
98.65 , 50.1, 108.4,
62.06, 48.34 , 71.45 , 53.21 , 72.57 , 48.14 ,
71.32 , 41.01 , 96.71,
112.09, 54.87 , 63.17 , 44.95])
y_data= np.array([ 127.42 , 121.09 , 294.53, 96.73, 125.04, 195.08,
287.84, 106.97, 107.94,
204.45, 116.09 , 57.64 , 296.82 , 123.5 , 180.11 , 116.81 ,
96.73 ,233.71,
237.07, 130. , 182.61 , 260.22, 238.86 , 238.02 ,
248.05, 101.41, 269.69,
156.43 , 121.27 , 172.64 , 139.62 , 203.87 , 134.78 ,
176.24 , 106.22 , 252.93,
282.96 ,141.95 ,161. , 123.42])
features = [tf.contrib.layers.real_valued_column("x", dimension=1)]
estimator = tf.contrib.learn.LinearRegressor(feature_columns=features,
model_dir='./linear_estimator')
input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x_data}, y_data,
num_epochs=1000)
estimator.fit(input_fn=input_fn, steps=2000)
np.asarray([i for i in estimator.predict(x={'x': x_data})])
结果是
array([1539.31665039,1476.55419922,4059.26489258,1413.11694336, 1616.92626953,2445.9987793,3865.2409668,1379.37365723, 1367.56335449,2643.734375,1834.57043457,766.93310547, 3866.92822266,1388.48425293,2646.77124023,1587.90698242, 1230.56567383,320083569696,2893.77197266,1779.90625, 2517.87182617,3484.27929688,3343.9074707,3393。84741211, 3364.15332031,1725.91699219,3693.15039062,2129.48681641, 1666.52893066,2446.3359375,1830.85864258,2484.12866211, 1659.78015137,2441.94946289,1419.19055176,3298.69140625, 3817.6628418,18868727652,21,666,94165039,1552.13916016],dtype = float32)
答案 0 :(得分:0)
现在可行。
我删除了导出目录并拥有新版本1.1.0。
感谢所有答案。