import tensorflow as tfx1_data = [73., 93., 89., 96., 73.]
x2_data = [80., 88., 91., 98., 66.]
x3_data = [75., 93., 90., 100., 70.]
y_data = [152., 185., 180., 196., 142.]x1 = tf.placeholder(tf.float32)
x2 = tf.placeholder(tf.float32)
x3 = tf.placeholder(tf.float32)Y = tf.placeholder(tf.float32)w1 = tf.Variable(tf.random_normal([1]), tf.float32, name='w1')
w2 = tf.Variable(tf.random_normal([1]), tf.float32, name='w2')
w3 = tf.Variable(tf.random_normal([1]), tf.float32, name='w3')b = tf.Variable(tf.random_normal([1]), tf.float32, name='b')hypothesis = w1 * x1 + w2 * x2 + w3 * x3 + bcost = tf.reduce_mean(tf.square(hypothesis - Y))optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.00001)train = optimizer.minimize(cost)with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(2000):
_, _cost, _predict = sess.run([train, cost, hypothesis], feed_dict={x1:x1_data, x2:x2_data, x3:x3_data, Y:y_data})
if epoch % 100 == 0:
print(_cost,"\n",_predict)7947.0117
[79.13513 84.964035 88.98191 98.46066 60.634403]
32.08985
[157.85564 179.97876 182.3948 200.20078 133.19283]
30.524317
[157.65059 180.12009 182.33295 200.14856 133.38457]
29.040844
[157.45111 180.2576 182.27278 200.09763 133.57129]
27.635244
[157.25706 180.39136 182.21428 200.0479 133.7531 ]
26.303051
[157.06828 180.52155 182.15738 199.99936 133.93018]
25.040623
[156.88461 180.6482 182.10205 199.95195 134.1026 ]
23.844303
[156.70595 180.77141 182.04826 199.90569 134.27052]
22.710495
[156.53214 180.8913 181.99593 199.8605 134.43405]
21.635935
[156.36305 181.00797 181.94507 199.81638 134.5933 ]
20.617533
[156.19856 181.12144 181.89558 199.7733 134.74841]
19.652359
[156.03857 181.2319 181.84753 199.73126 134.89948]
18.737497
[155.88292 181.33934 181.80077 199.69019 135.0466 ]
17.870474
[155.73152 181.44383 181.7553 199.65004 135.18987]
17.048563
[155.58424 181.54553 181.7111 199.61084 135.32942]
16.269506
[155.44096 181.64445 181.6681 199.57256 135.46533]
15.531018
[155.30164 181.74074 181.62636 199.53517 135.59773]
14.830976
[155.1661 181.83438 181.58575 199.49863 135.72668]
14.167334
[155.03426 181.92548 181.54625 199.4629 135.85226]
13.53824
[154.90604 182.01411 181.5079 199.42802 135.9746 ]