import tensorflow as tf xData = [1, 2, 3, 4, 5, 6, 7] yData = [25000, 55000, 75000, 110000, 128000, 155000, 180000] W = tf.Variable(tf.random_uniform([1], -100, 100)) b = tf.Variable(tf.random_uniform([1], -100, 100)) X = tf.placeholder(tf.float32) Y = tf.placeholder(tf.float32) H = W * X + b cost = tf.reduce_mean(tf.square(H - Y)) a = tf.Variable(0.01) optimizer = tf.train.GradientDescentOptimizer(a) train = optimizer.minimize(cost) init = tf.global_variables_initializer() sess = tf.Session() sess.run(init) for i in range(5001): sess.run(train, feed_dict={X: xData, Y: yData}) if i % 500 == 0: print(i, sess.run(cost, feed_dict={X: xData, Y: yData}), sess.run(W), sess.run(b)) print(sess.run(H, feed_dict={X: [8]}))
Standard input is empty
(0, 4594727400.0, array([10357.982], dtype=float32), array([2139.721], dtype=float32)) (500, 8689221.0, array([25535.479], dtype=float32), array([1960.3041], dtype=float32)) (1000, 8633856.0, array([25627.21], dtype=float32), array([1506.056], dtype=float32)) (1500, 8632680.0, array([25640.576], dtype=float32), array([1439.8679], dtype=float32)) (2000, 8632652.0, array([25642.525], dtype=float32), array([1430.2173], dtype=float32)) (2500, 8632654.0, array([25642.805], dtype=float32), array([1428.824], dtype=float32)) (3000, 8632657.0, array([25642.844], dtype=float32), array([1428.6343], dtype=float32)) (3500, 8632657.0, array([25642.848], dtype=float32), array([1428.6133], dtype=float32)) (4000, 8632657.0, array([25642.848], dtype=float32), array([1428.6133], dtype=float32)) (4500, 8632657.0, array([25642.848], dtype=float32), array([1428.6133], dtype=float32)) (5000, 8632657.0, array([25642.848], dtype=float32), array([1428.6133], dtype=float32)) [206571.39]
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.