Octave-CostFunction

假设 X= [1 1;1 2;1 3]

y = [1;2;3]

theta = [0;0]

costFunction J :

1 function J = costFunction(X,y,theta)
2   m = size(X,1);
3   predictions = X*theta;
4   Errors = (predictions - y).^2;
5   J = 1/(2*m)*sum(Errors);
6 endfunction

J = costFunction(X,y,theta)    :得到结果为     杲湩س୔J =  2.3333

posted @ 2019-12-13 19:05  不识人间花火  阅读(266)  评论(1编辑  收藏  举报