1-Linear Regression and TensorFlow
1-Linear Regression and TensorFlow
(Iterative Solution)
Linear Regression: Gradient
Descent Solution
Linear Regression: Gradient
Descent Solution
TensorFlow
from Google
Deep Learning
Most Common Frameworks
import tensorflow as tf
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
input3 = tf.constant(5.0)
y = W * x_data + b
#Carryout 16 Iterations
for step in range(16):
sess.run(train)
#Draw Predicted data (using calculated weight and bias after training
plt.plot(x_data, sess.run(W) * x_data + sess.run(b))
plt.xlabel('x')
plt.xlim(-2, 2)
plt.ylim(0.1, 0.6)
plt.ylabel('y')
plt.legend()
plt.show()
# print updated weights, bias, and Loss value after current training iteration
print(step, sess.run(W), sess.run(b),sess.run(loss))
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
Iteration 9
Iteration 10
Iteration 11
Iteration 12
Iteration 13
Iteration 14
Iteration 15
Iteration 16
Updated Weights and
Calculated Loss
2-D Data Example
Data Preparation
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
y = W1 * x1_data + W2 * x2_data + b
#Carryout 24 Iterations
#
#
#
# { Continue in Next Slide }
Execute TensorFlow Graph
#Carryout 24 Iterations
for step in range(24):
sess.run(train)
# print updated weights, bias, and Loss value after current training iteration
print(step+1, sess.run(W1), sess.run(W2) , sess.run(b),sess.run(loss))
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
Iteration 9
Iteration 10
Iteration 11
Iteration 12
Iteration 13
Iteration 14
Iteration 15
Iteration 16
Iteration 17
Iteration 18
Iteration 19
Iteration 20
Updated Weights and
Calculated Loss