Skip to content

Instantly share code, notes, and snippets.

@DerekChia
Last active November 14, 2021 23:50
Show Gist options
  • Save DerekChia/1cadf98eb3f00beb47e685840c2e5e10 to your computer and use it in GitHub Desktop.
Save DerekChia/1cadf98eb3f00beb47e685840c2e5e10 to your computer and use it in GitHub Desktop.
def linear_regression():
x = tf.placeholder(tf.float32, shape=(None, ), name='x')
y = tf.placeholder(tf.float32, shape=(None, ), name='y')
with tf.variable_scope('lreg') as scope:
w = tf.Variable(np.random.normal(), name='W')
b = tf.Variable(np.random.normal(), name='b')
y_pred = tf.add(tf.multiply(w, x), b)
loss = tf.reduce_mean(tf.square(y_pred - y))
return x, y, y_pred, loss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment