Cost Function, Gradient Descent.
(logistic) function def sigmoid(z): return 1 / (1 + np.exp(-z)) # Cost function for logistic regression def cost_function(theta, X, y): m = len(y) h = sigmoid(X.dot(theta)) cost = -1/m * (y.T.dot(np.log(h)) + (1 - y).T.dot(np.log(1 - h))) return cost.item() # Gradient descent to update parameters