fork download
  1. import tensorflow as tf
  2.  
  3. xData = [1, 2, 3, 4, 5, 6, 7]
  4. yData = [25000, 55000, 75000, 110000, 128000, 155000, 180000]
  5.  
  6. W = tf.Variable(tf.random_uniform([1], -100, 100))
  7. b = tf.Variable(tf.random_uniform([1], -100, 100))
  8.  
  9. X = tf.placeholder(tf.float32)
  10. Y = tf.placeholder(tf.float32)
  11.  
  12. H = W * X + b
  13. cost = tf.reduce_mean(tf.square(H - Y))
  14.  
  15. a = tf.Variable(0.01)
  16.  
  17. optimizer = tf.train.GradientDescentOptimizer(a)
  18.  
  19. train = optimizer.minimize(cost)
  20.  
  21. init = tf.global_variables_initializer()
  22. sess = tf.Session()
  23. sess.run(init)
  24.  
  25. for i in range(5001):
  26. sess.run(train, feed_dict={X: xData, Y: yData})
  27. if i % 500 == 0:
  28. print(i, sess.run(cost, feed_dict={X: xData, Y: yData}), sess.run(W), sess.run(b))
  29.  
  30. print(sess.run(H, feed_dict={X: [8]}))
  31.  
Success #stdin #stdout #stderr 3.53s 209836KB
stdin
Standard input is empty
stdout
(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]
stderr
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.