Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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