mapFeature.m 508 B

123456789101112131415161718192021
  1. function out = mapFeature(X1, X2)
  2. % MAPFEATURE Feature mapping function to polynomial features
  3. %
  4. % MAPFEATURE(X1, X2) maps the two input features
  5. % to quadratic features used in the regularization exercise.
  6. %
  7. % Returns a new feature array with more features, comprising of
  8. % X1, X2, X1.^2, X2.^2, X1*X2, X1*X2.^2, etc..
  9. %
  10. % Inputs X1, X2 must be the same size
  11. %
  12. degree = 6;
  13. out = ones(size(X1(:,1)));
  14. for i = 1:degree
  15. for j = 0:i
  16. out(:, end+1) = (X1.^(i-j)).*(X2.^j);
  17. end
  18. end
  19. end