My implementation (see below) gives the scalar value 3.18, which is not the right answer. The value should be 0.693. Where does my code deviate from the equation?
Her
This is the code for the sigmoid function which I think you have made mistake in:
function g = sigmoid(z)
g = zeros(size(z));
temp=1+exp(-1.*z);
g=1./temp;
end
function [J, grad] = costFunction(theta, X, y)
m = length(y);
J = 0;
grad = zeros(size(theta));
h=X*theta;
xtemp=sigmoid(h);
temp1=(-y'*log(xtemp));
temp2=(1-y)'*log(1-xtemp);
J=1/m*sum(temp1-temp2);
grad=1/m*(X'*(xtemp-y));
end
And I think it should be (1-y)' as shown in temp2=(1-y)'