Created
May 6, 2018 02:13
-
-
Save hackintoshrao/23a7532a5866b01207a4ff7e0f357805 to your computer and use it in GitHub Desktop.
Linear regression cost function and optimizer in tensorflow
This file contains hidden or 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
def get_cost_optimizer_tensor(Y, model, size, learning_rate): | |
""" | |
Tensor for calculating the cost function and the the optimizer for | |
minimizing the cost. | |
""" | |
# Cost function tensor. | |
cost_function = tf.reduce_sum(tf.pow(model - Y, 2))/(2 * size) | |
# gradient descent tensor. | |
gradient_descent = tf.train.GradientDescentOptimizer(learning_rate) | |
# optimization tensor. | |
optimizer = gradient_descent.minimize(cost_function) | |
return optimizer, cost_function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment