Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 6/Programming Assignment - 5/machine-learning-ex5/ex5/polyFeatures.m
864 views
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
8
9
% You need to return the following variables correctly.
10
X_poly = zeros(numel(X), p);
11
12
% ====================== YOUR CODE HERE ======================
13
% Instructions: Given a vector X, return a matrix X_poly where the p-th
14
% column of X contains the values of X to the p-th power.
15
%
16
%
17
fprintf("Before feature-mapping\n");
18
disp(X_poly);
19
for i = 1:p
20
X_poly(:,i) = X.^i;
21
end
22
fprintf("After feature-mapping\n");
23
disp(X_poly);
24
% =========================================================================
25
26
end
27
28