myex5.m 692 B

1234567891011121314151617181920212223
  1. % =========== Part 2: Regularized Linear Regression Cost =============
  2. % You should now implement the cost function for regularized linear
  3. % regression.
  4. %
  5. theta = [1 ; 1];
  6. J = linearRegCostFunction([ones(m, 1) X], y, theta, 1);
  7. fprintf(['Cost at theta = [1 ; 1]: %f '...
  8. '\n(this value should be about 303.993192)\n'], J);
  9. fprintf('Program paused. Press enter to continue.\n');
  10. theta = [1 ; 1];
  11. [J, grad] = linearRegCostFunction([ones(m, 1) X], y, theta, 1);
  12. fprintf(['Gradient at theta = [1 ; 1]: [%f; %f] '...
  13. '\n(this value should be about [-15.303016; 598.250744])\n'], ...
  14. grad(1), grad(2));
  15. fprintf('Program paused. Press enter to continue.\n');