Skip to content

Instantly share code, notes, and snippets.

@jinhoyoo
Created June 14, 2016 03:46
Show Gist options
  • Save jinhoyoo/072af4b8436c85cb960e6a6354d9a4f5 to your computer and use it in GitHub Desktop.
Save jinhoyoo/072af4b8436c85cb960e6a6354d9a4f5 to your computer and use it in GitHub Desktop.
tenssor flow: linear regression
import tensorflow as tf
x1_data = [1, 0, 3, 0, 5]
x2_data = [0, 2, 0, 4, 0]
y_data = [1, 2, 3, 4, 5]
W1 = tf.Variable(tf.random_uniform([1], -1.0, 1.0) )
W2 = tf.Variable(tf.random_uniform([1], -1.0, 1.0) )
b = tf.Variable(tf.random_uniform([1], -1.0, 1.0) )
hypothesis = W1*x1_data + W2*x2_data + b
# Cost function
cost = tf.reduce_mean(tf.square(y_data - hypothesis))
# Optimizer confifuration
train = tf.train.GradientDescentOptimizer(learning_rate =0.01).minimize(cost)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
for step in range(100):
sess.run(train)
if step % 10 == 0:
print (step, sess.run(cost), sess.run(W1), sess.run(W2), sess.run(b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment