Last active
January 13, 2017 07:08
-
-
Save jw0201/2d84f917729e85814fdfb0e1f3748f2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| x_data = [1., 2., 3.] | |
| y_data = [1., 2., 3.] | |
| X = tf.placeholder(tf.float32) | |
| Y = tf.placeholder(tf.float32) | |
| W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) | |
| b = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) | |
| hypothesis = W * X + b | |
| cost = tf.reduce_mean(tf.square(hypothesis - Y)) | |
| a = tf.Variable(0.1) | |
| optimizer = tf.train.GradientDescentOptimizer(a) | |
| train = optimizer.minimize(cost) | |
| init = tf.initialize_all_variables() | |
| sess = tf.Session() | |
| sess.run(init) | |
| for step in xrange(2001): | |
| sess.run(train, feed_dict={X:x_data, Y:y_data}) | |
| if step % 20 == 0: | |
| print step, sess.run(cost, feed_dict={X:x_data, Y:y_data}), sess.run(W), sess.run(b) | |
| print sess.run(hypothesis, feed_dict={X:5}) | |
| print sess.run(hypothesis, feed_dict={X:2.5}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment