单变量

H(x)=theta*x;

惩罚函数

J=sum(H(x)-y).^2/(2*m)

 

阶梯下降计算变量参数

T=theta(theta1,theta2);

如何计算 theta1和theta2

 

一步到位计算

theta1=theta1-apha((X*theta-y).*X(:1))

theta2=theta2-apha((X*theta-y).*X(:2))

 

吴恩达作业1

 

Comput Cost
for i=1:m
J=J+(X(i,:)*theta-y(i)).^2/(2*m);
end

Gradiet descent

 
theta(1)=theta(1)-alpha*(1/m)*(sum((X*theta-y).*X(:,1)));;
theta(2)=theta(2)-alpha*(1/m)*(sum((X*theta-y).*X(:,2)));;