Last active
September 22, 2021 13:17
-
-
Save antondevv/aa14aec3621e98dc0da6001254e1b7eb to your computer and use it in GitHub Desktop.
gradient_descent
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(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