In [32]:
import numpy as np
import tensorflow as tf
In [33]:
W = tf.Variable([.3],dtype = "float32")
b = tf.Variable([-.3],dtype = "float32")
In [52]:
x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)
In [35]:
hypothesis = W * x + b
In [36]:
loss = tf.reduce_sum(tf.square(hypothesis- y))
In [53]:
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)
In [54]:
x_train = [1,2,3,4]
y_train = [0,-1,-2,-3]
In [39]:
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
In [40]:
for i in range(1000):
sess.run(train,{x:x_train,y:y_train})
In [51]:
curr_W,curr_b= sess.run([W,b])
print (curr_W,curr_b)
In [48]:
curr_W,curr_b,curr_loss = sess.run([W,b,loss],{x:x_train,y:y_train})
print (curr_W,curr_b,curr_loss)