-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 584be06
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import tensorflow as tf | ||
|
||
# X and Y data | ||
x_train = [1,2,3] | ||
y_train = [1,2,3] | ||
|
||
W = tf.Variable(tf.random_normal([1]), name='weight') | ||
b = tf.Variable(tf.random_normal([1]), name='bias') | ||
|
||
# Our hypothesis XW+b | ||
hypothesis = x_train * W + b | ||
|
||
# cost/loss function | ||
cost = tf.reduce_mean(tf.square(hypothesis-y_train)) | ||
|
||
|
||
# minimize | ||
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01) | ||
train = optimizer.minimize(cost) | ||
|
||
# Launch the graph in a session | ||
sess = tf.Session() | ||
|
||
# Initializes global variables in the graph. | ||
sess.run(tf.global_variables_initializer()) | ||
|
||
#Fit the line | ||
for step in range(2001): | ||
sess.run(train) | ||
if step % 20 == 0: | ||
print(step, sess.run(cost), sess.run(W), sess.run(b)) |