Cursera: machine learning ex5.

This commit is contained in:
2015-03-15 19:06:51 +04:00
parent d8ecf43e80
commit 97bf613378
13 changed files with 1236 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
function [X_poly] = polyFeatures(X, p)
%POLYFEATURES Maps X (1D vector) into the p-th power
% [X_poly] = POLYFEATURES(X, p) takes a data matrix X (size m x 1) and
% maps each example into its polynomial features where
% X_poly(i, :) = [X(i) X(i).^2 X(i).^3 ... X(i).^p];
%
% You need to return the following variables correctly.
X_poly = zeros(numel(X), p);
% ====================== YOUR CODE HERE ======================
% Instructions: Given a vector X, return a matrix X_poly where the p-th
% column of X contains the values of X to the p-th power.
%
%
X_poly(:,1) = X;
for i = 2:p
X_poly(:,i) = X_poly(:,i-1).*X;
end
% =========================================================================
end