[英]Cost function for linear regression with multiple variables in Matlab
The multivariate linear regression cost function: 多元线性回归成本函数:
Is the following code in Matlab correct? Matlab中的以下代码正确吗?
function J = computeCostMulti(X, y, theta)
m = length(y);
J = 0;
J=(1/(2*m)*(X*theta-y)'*(X*theta-y);
end
Your are missing a )
in the end: 您最后缺少)
:
J=(1/(2*m))*(X*theta-y)'*(X*theta-y);
^
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.