Skip to content

Commit

Permalink
Update Linear Regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang Yuan committed Apr 27, 2018
1 parent 19b13ef commit 04c13d3
Show file tree
Hide file tree
Showing 43 changed files with 37 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions tensorflow/TensorBasic/LinearRegression/LinearRegression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf

x_data = np.random.rand(100).astype(np.float32)
y_data = 3.0 * x_data + 1.0
print("x_data: ", x_data)
print("y_data: ", y_data)

# Define trainable variables
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))

# Define graph operations
y = tf.multiply(W, x_data) + b

# Define loss
loss = tf.reduce_mean(tf.square(y - y_data))

# Define optimizer for training
train_optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.5).minimize(loss)

# Define the operation that initializes variables
init = tf.global_variables_initializer()

# Launch the graph
with tf.Session() as sess:
# Initialization
sess.run(init)

# Start training
training_iters = 1000
for step in range(training_iters):
if step % 20 == 0 or (step + 1)==training_iters:
print(step, sess.run(W), sess.run(b))

_ = sess.run([train_optimizer])

0 comments on commit 04c13d3

Please sign in to comment.