Skip to content

Instantly share code, notes, and snippets.

@antondevv
Last active September 22, 2021 13:17
Show Gist options
  • Save antondevv/aa14aec3621e98dc0da6001254e1b7eb to your computer and use it in GitHub Desktop.
Save antondevv/aa14aec3621e98dc0da6001254e1b7eb to your computer and use it in GitHub Desktop.
gradient_descent
def gradient_descent(m_now, b_now, points, L):
the_slope_of_thecost_depending_on_m = 0
the_slope_of_thecost_depending_on_b = 0
n = len(points)
for i in range(n):
x = points.iloc[i].weight
y = points.iloc[i].height
the_slope_of_thecost_depending_on_m += - (2/n) * x * (y - (m_now * x + b_now))
the_slope_of_thecost_depending_on_b += - (2/n) * (y - (m_now * x + b_now))
m = m_now - L * the_slope_of_thecost_depending_on_m
b = b_now - the_slope_of_thecost_depending_on_b * L
return m, b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment