Created
June 3, 2019 17:21
-
-
Save KhyatiMahendru/d5c0021c94c96c3003b68a6adda94705 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 update_weights_MSE(m, b, X, Y, learning_rate): | |
m_deriv = 0 | |
b_deriv = 0 | |
N = len(X) | |
for i in range(N): | |
# Calculate partial derivatives | |
# -2x(y - (mx + b)) | |
m_deriv += -2*X[i] * (Y[i] - (m*X[i] + b)) | |
# -2(y - (mx + b)) | |
b_deriv += -2*(Y[i] - (m*X[i] + b)) | |
# We subtract because the derivatives point in direction of steepest ascent | |
m -= (m_deriv / float(N)) * learning_rate | |
b -= (b_deriv / float(N)) * learning_rate | |
return m, b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment