Skip to content

Instantly share code, notes, and snippets.

@KhyatiMahendru
Last active January 24, 2022 09:48
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 KhyatiMahendru/b7d7991f8cbaf09b5c43643f726ba3d8 to your computer and use it in GitHub Desktop.
Save KhyatiMahendru/b7d7991f8cbaf09b5c43643f726ba3d8 to your computer and use it in GitHub Desktop.
def update_weights_BCE(m1, m2, b, X1, X2, Y, learning_rate):
m1_deriv = 0
m2_deriv = 0
b_deriv = 0
N = len(X1)
for i in range(N):
s = 1 / (1 / (1 + math.exp(-m1*X1[i] - m2*X2[i] - b)))
# Calculate partial derivatives
m1_deriv += -X1[i] * (s - Y[i])
m2_deriv += -X2[i] * (s - Y[i])
b_deriv += -(s - Y[i])
# We subtract because the derivatives point in direction of steepest ascent
m1 -= (m1_deriv / float(N)) * learning_rate
m2 -= (m2_deriv / float(N)) * learning_rate
b -= (b_deriv / float(N)) * learning_rate
return m1, m2, b
@thasan3003
Copy link

Is line no 7 right for sigmoid function? I think you inverted twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment