In [12]:
J = 0
dw1 = 0
dw2 = 0
db = 0
for i in range(m):
z[i] = w.T*x + b
a[i] = o(z[i])
J += -( y[i] * log(a(i)) + (1-y[i]) * log(1-a(i)) )
dz[i] = a[i] - y[i]
dw1 += x[i,1] * dz[i]
dw2 += x[i,2] * dz[i]
db += dz[i]
J /= m
dw1 /= m
dw2 /= m
db /= m
# Ajustando pelo gradiente
w1 = w1 - alpha*dw1
w2 = w2 - alpha*dw2
b = b - alpha*db