Coursera_machine_learning_assignment1 / 线性回归 梯度下降

Posted by Yan on June 21, 2020

Linear Regression

m: number of samples

alpha: learning rate

  • Cost function: ()
    • where as:

  • Gradient descent:
    • In this case:
  • Code for Vectorisation:
    • Cost Function: J=sum((X*theta-y).^2)/(2*m);
    • Gradient Descent:
      for iter = 1:num_iters
      h=X*theta;
      theta=theta-alpha/m*X'*(h-y);
      end
      

Another solution for linear regression:

  • Normal Equations

  • Code: theta=pinv(X'*X)*X'*y;