diff --git a/Andrew Ng Stanford Coursera/Week 03/machine-learning-ex2/ex2/costFunctionReg.m b/Andrew Ng Stanford Coursera/Week 03/machine-learning-ex2/ex2/costFunctionReg.m index 0f04176..0a770b6 100644 --- a/Andrew Ng Stanford Coursera/Week 03/machine-learning-ex2/ex2/costFunctionReg.m +++ b/Andrew Ng Stanford Coursera/Week 03/machine-learning-ex2/ex2/costFunctionReg.m @@ -18,8 +18,8 @@ % derivatives of the cost w.r.t. each parameter in theta h_theta = sigmoid(X*theta); J = (-1/m)*sum(y.*log(h_theta) + (1-y).*log(1-h_theta)) + (lambda/(2*m))*sum(theta(2:length(theta)).^2) -grad(1) = (1/m)*(X'(1,:))*(h_theta - y); -grad(2:size(theta,1)) = 1/m * (X'(2:size(X',1),:)*(h_theta - y) + lambda*theta(2:size(theta,1),:)) +grad(1) = (1/m).*((X(:,1)')*(h_theta - y)); +grad(2:size(theta,1)) = 1/m * (X(:,2:size(X',1))'*(h_theta - y) + lambda*theta(2:size(theta,1),:)); % ============================================================= end