Reputation: 23
The multivariate linear regression cost function:
Is the following code in Matlab correct?
function J = computeCostMulti(X, y, theta)
m = length(y);
J = 0;
J=(1/(2*m)*(X*theta-y)'*(X*theta-y);
end
Upvotes: 2
Views: 5979
Reputation: 21
Your are missing a )
in the end:
J=(1/(2*m))*(X*theta-y)'*(X*theta-y);
^
Upvotes: 2
Reputation: 351
There is two ways i tried which is essentially the same code.
J = (X * theta - y)'*(X * theta - y)/2*m;
or you can try:
J = (1/(2*m))*(X * theta - y)'*(X * theta - y)
Upvotes: 2