You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

polyFeatures.m 707 B

8 years ago
12345678910111213141516171819202122
  1. function [X_poly] = polyFeatures(X, p)
  2. %POLYFEATURES Maps X (1D vector) into the p-th power
  3. % [X_poly] = POLYFEATURES(X, p) takes a data matrix X (size m x 1) and
  4. % maps each example into its polynomial features where
  5. % X_poly(i, :) = [X(i) X(i).^2 X(i).^3 ... X(i).^p];
  6. %
  7. % You need to return the following variables correctly.
  8. X_poly = zeros(numel(X), p);
  9. % ====================== YOUR CODE HERE ======================
  10. % Instructions: Given a vector X, return a matrix X_poly where the p-th
  11. % column of X contains the values of X to the p-th power.
  12. %
  13. %
  14. for i = 1 : p
  15. X_poly(:, i) = [X .^ i ];
  16. end
  17. % =========================================================================
  18. end

机器学习

Contributors (1)