Last active
August 7, 2018 15:01
-
-
Save marciok/11fa795dff3aca0fb621891b8af2951e to your computer and use it in GitHub Desktop.
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
def gradient_descent(points, b, m, learning_rate): | |
m_gradient = 0 | |
b_gradient = 0 | |
N = float(len(points)) | |
for i in range(0, len(points)): | |
x = points[i, 0] | |
y = points[i, 1] | |
# Caluclating the partial derivative | |
b_gradient += -(2/N) * (y - ((m * x) + b)) | |
m_gradient += -(2/N) * x * (y - ((m * x) + b)) | |
# Multiplying by learning rate and updating values | |
m_updated = m - (m_gradient * learning_rate) | |
b_updated = b - (b_gradient * learning_rate) | |
return b_updated, m_updated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment