Cursera: machine learning ex2.
This commit is contained in:
21
machine_learning/mlclass-ex2-008/mlclass-ex2/mapFeature.m
Normal file
21
machine_learning/mlclass-ex2-008/mlclass-ex2/mapFeature.m
Normal file
@@ -0,0 +1,21 @@
|
||||
function out = mapFeature(X1, X2)
|
||||
% MAPFEATURE Feature mapping function to polynomial features
|
||||
%
|
||||
% MAPFEATURE(X1, X2) maps the two input features
|
||||
% to quadratic features used in the regularization exercise.
|
||||
%
|
||||
% Returns a new feature array with more features, comprising of
|
||||
% X1, X2, X1.^2, X2.^2, X1*X2, X1*X2.^2, etc..
|
||||
%
|
||||
% Inputs X1, X2 must be the same size
|
||||
%
|
||||
|
||||
degree = 6;
|
||||
out = ones(size(X1(:,1)));
|
||||
for i = 1:degree
|
||||
for j = 0:i
|
||||
out(:, end+1) = (X1.^(i-j)).*(X2.^j);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user