Linear Regression Using TensorFlow PDF
Linear Regression Using TensorFlow PDF
1
In [4]: X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)
In [8]: # Hypothesis
y_pred = tf.add(tf.multiply(X, W), b)
2
writer = tf.summary.FileWriter("logs", sess.graph)
# Feeding each data point into the optimizer using Feed Dictionary
for (_x, _y) in zip(x, y):
sess.run(optimizer, feed_dict = {X : _x, Y : _y})
3
Epoch 1300 : cost = 5.4854755 W = 1.0344176 b = -0.118438624
Epoch 1350 : cost = 5.4795103 W = 1.0347582 b = -0.13458282
Epoch 1400 : cost = 5.4742365 W = 1.0350634 b = -0.14904751
Epoch 1450 : cost = 5.4695716 W = 1.0353369 b = -0.16200735
Epoch 1500 : cost = 5.4654326 W = 1.0355817 b = -0.17361827
4
R2 value: 0.9529184904819711
Exercises:
2. Change the stopping criterion from number of epochs to difference in cost function. If
delta(J) <= 0.000001 stop the training.
3. Train your model with different alpha values (0.05, 0.1, 0.2 and 0.5) and conclude the be-
haviour.