/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
- function [X_norm, mu, sigma] = featureNormalize(X)
- %FEATURENORMALIZE Normalizes the features in X
- % FEATURENORMALIZE(X) returns a normalized version of X where
- % the mean value of each feature is 0 and the standard deviation
- % is 1. This is often a good preprocessing step to do when
- % working with learning algorithms.
- % You need to set these values correctly
- X_norm = X;
- mu = zeros(1, size(X, 2));
- sigma = zeros(1, size(X, 2));
- % by @dnene
- % x_size = length(X);
- % X_norm = (X_norm - repmat(mu,x_size,1)) ./ repmat(sigma,x_size,1);
- % ====================== YOUR CODE HERE ======================
- % Instructions: First, for each feature dimension, compute the mean
- % of the feature and subtract it from the dataset,
- % storing the mean value in mu. Next, compute the
- % standard deviation of each feature and divide
- % each feature by it's standard deviation, storing
- % the standard deviation in sigma.
- %
- % Note that X is a matrix where each column is a
- % feature and each row is an example. You need
- % to perform the normalization separately for
- % each feature.
- %
- % Hint: You might find the 'mean' and 'std' functions useful.
- %
- mu=mean(X);
- sigma=std(X);
- for i=1:size(X,2)
- X_norm(:,i)=(X(:,i).-mu(i))./sigma(i);
- end
- % ============================================================
- end