Skip to content

Instantly share code, notes, and snippets.

@AbhinavMadahar
Last active May 23, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhinavMadahar/96c7c4c8fb60607390fa0990b48242bb to your computer and use it in GitHub Desktop.
Save AbhinavMadahar/96c7c4c8fb60607390fa0990b48242bb to your computer and use it in GitHub Desktop.
import tensorflow as tf
weights = tf.Variable([1., 2., 3.],tf.float32)
biases = tf.Variable([4., 5., 6.], tf.float32)
x = tf.placeholder(tf.float32)
sess = tf.Session()
linear_model = weights * x + biases
sess.run(tf.global_variables_initializer())
y = tf.placeholder(tf.float32)
squared_deltas = tf.square(linear_model - y)
loss = tf.reduce_sum(squared_deltas)
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
print(sess.run([loss, weights, biases], {x:[1,2,3], y:[0,-1,-2]}))
for i in range(1000):
sess.run(train, {x:[1,2,3], y:[0,-1,-2]})
print(sess.run([loss, weights, biases], {x:[1,2,3], y:[0,-1,-2]}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment