Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 2/Programming Assignment-1/featureNormalize.m
626 views
1
function [X_norm, mu, sigma] = featureNormalize(X)
2
%FEATURENORMALIZE Normalizes the features in X
3
% FEATURENORMALIZE(X) returns a normalized version of X where
4
% the mean value of each feature is 0 and the standard deviation
5
% is 1. This is often a good preprocessing step to do when
6
% working with learning algorithms.
7
8
% You need to set these values correctly
9
X_norm = X;
10
mu = zeros(1, size(X, 2));
11
sigma = ones(1, size(X, 2));
12
13
% ====================== YOUR CODE HERE ======================
14
% Instructions: First, for each feature dimension, compute the mean
15
% of the feature and subtract it from the dataset,
16
% storing the mean value in mu. Next, compute the
17
% standard deviation of each feature and divide
18
% each feature by it's standard deviation, storing
19
% the standard deviation in sigma.
20
%
21
% Note that X is a matrix where each column is a
22
% feature and each row is an example. You need
23
% to perform the normalization separately for
24
% each feature.
25
%
26
% Hint: You might find the 'mean' and 'std' functions useful.
27
%
28
29
for i = 1:size(X,2),
30
mu(:,i) = mean(X(:,i));
31
sigma(:,i) = std(X(:,i));
32
X_norm(:,i) = (X(:,i) - mu(:,i))/(std(X(:,i)));
33
end;
34
fprintf("After featuring scaling, X is:\n");
35
disp(X_norm);
36
% ============================================================
37
38
end
39
40