-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyFeatures.m
More file actions
25 lines (17 loc) · 707 Bytes
/
polyFeatures.m
File metadata and controls
25 lines (17 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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; % size m × 1
for i = 2:p
% polynomial regression
X_poly(:,i) = X .* X_poly(:,(i-1));
end
end