I am having some difficulties in implementing logistic regression, in terms of how should I should proceed stepwise. According to what I have done so far I am implementing it in the following way:
First taking
thetaequal to the number of features and making it an*1vector of zeros. Now using thisthetato compute the the followinghtheta = sigmoid(theta' * X');theta = theta - (alpha/m) * sum (htheta' - y)'*XNow using the
thetacomputed in the first step to compute the cost functionJ= 1/m *((sum(-y*log(htheta))) - (sum((1-y) * log(1 - htheta)))) + lambda/(2*m) * sum(theta).^2In the end computing the gradient
grad = (1/m) * sum ((sigmoid(X*theta) - y')*X);
As i am taking theta to be zero. I am getting same value of J throughout the vector, is this the right output?
y=randi(2,[10,1])-1&X=[ones(10,1) randn([10,1]). From what I can see: the cost function should change as you updatetheta. However, it is unclear why you compute the gradient twice (i.e., once at updatingthetaand in the final step). - jvz