w22116972
7/23/2015 - 1:10 PM

Cost function of logistic regression

Cost function of logistic regression

function [J, grad] = costFunction(theta, X, y)
hx = sigmoid(X * theta);
m = length(X);

J = sum(-y' * log(hx) - (1 - y')*log(1 - hx)) / m;
grad = X' * (hx - y) / m;

end