单变量回归分析

for i=1:1000
theta1=theta(:,1)-a/m**sum(X**theta'-Y);
theta2=theta(:,2)-a/m*(X(:,2)'**(X**theta'-Y));
theta=[theta1,theta2];
cost_0=[cost_0,cost(X,Y,theta)];
end
plot(cost_0)
function J=cost(X,Y,theta)
m=length(Y);
J=sum((X*theta'-Y).^2)/(2*m);

散点图 - MATLAB scatter

散点图的外观和行为 - MATLAB