Skip to content

Instantly share code, notes, and snippets.

@marciok
Last active August 7, 2018 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciok/11fa795dff3aca0fb621891b8af2951e to your computer and use it in GitHub Desktop.
Save marciok/11fa795dff3aca0fb621891b8af2951e to your computer and use it in GitHub Desktop.
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