<jupyter_start><jupyter_text>Lab-02-1 Linear Regression ---<jupyter_code>import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
tf.set_random_seed(777)  # for reprducibilty<jupyter_output><empty_output><jupyter_text>---  X and Y data<jupyter_code>x_train = [1, 2, 3]
y_train = [1, 2, 3]<jupyter_output><empty_output><jupyter_text>Variable<jupyter_code># Try to find value for W and b to compute y_data = x_data * W + b  
# We know that W should be 1 and b should be 0
# But let's TensorFlow figure it out 

W = tf.Variable(tf.random_normal([1]), name='Weight')
b = tf.Variable(tf.random_normal([1]), name='bias')<jupyter_output><empty_output><jupyter_text>Our Model<jupyter_code># our hypothesis Wx+b
hypothesis = x_train * W + b

# cost/loss function
cost = tf.reduce_mean(tf.square(hypothesis - y_train))<jupyter_output><empty_output><jupyter_text>Minimizing<jupyter_code>optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
train = optimizer.minimize(cost)<jupyter_output><empty_output><jupyter_text>Preparing Session<jupyter_code># Launch the graph in a session.
sess = tf.Session()
# Initializes global variables in the graph.
sess.run(tf.global_variables_initializer())<jupyter_output><empty_output><jupyter_text>Fitting the Line<jupyter_code>for step in range(2001):
  sess.run(train)
  if step % 200 == 0:
    print(step, sess.run(cost), sess.run(W), sess.run(b))<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup