PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/exercises/mlclass-ex1/featureNormalize.m

http://github.com/jneira/machine-learning-course
Objective C | 39 lines | 35 code | 4 blank | 0 comment | 3 complexity | aaf20bd98e6320e582f1652bdcb2e8f8 MD5 | raw file
 1function [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
 9X_norm = X;
10mu = zeros(1, size(X, 2));
11sigma = zeros(1, size(X, 2));
12
13% by @dnene
14% x_size = length(X);
15% X_norm = (X_norm - repmat(mu,x_size,1)) ./ repmat(sigma,x_size,1);
16
17% ====================== YOUR CODE HERE ======================
18% Instructions: First, for each feature dimension, compute the mean
19%               of the feature and subtract it from the dataset,
20%               storing the mean value in mu. Next, compute the 
21%               standard deviation of each feature and divide
22%               each feature by it's standard deviation, storing
23%               the standard deviation in sigma. 
24%
25%               Note that X is a matrix where each column is a 
26%               feature and each row is an example. You need 
27%               to perform the normalization separately for 
28%               each feature. 
29%
30% Hint: You might find the 'mean' and 'std' functions useful.
31%       
32mu=mean(X);
33sigma=std(X);
34for i=1:size(X,2)
35  X_norm(:,i)=(X(:,i).-mu(i))./sigma(i);
36end
37% ============================================================
38
39end