Path: blob/master/Week 2/Programming Assignment-1/featureNormalize.m
626 views
function [X_norm, mu, sigma] = featureNormalize(X)1%FEATURENORMALIZE Normalizes the features in X2% FEATURENORMALIZE(X) returns a normalized version of X where3% the mean value of each feature is 0 and the standard deviation4% is 1. This is often a good preprocessing step to do when5% working with learning algorithms.67% You need to set these values correctly8X_norm = X;9mu = zeros(1, size(X, 2));10sigma = ones(1, size(X, 2));1112% ====================== YOUR CODE HERE ======================13% Instructions: First, for each feature dimension, compute the mean14% of the feature and subtract it from the dataset,15% storing the mean value in mu. Next, compute the16% standard deviation of each feature and divide17% each feature by it's standard deviation, storing18% the standard deviation in sigma.19%20% Note that X is a matrix where each column is a21% feature and each row is an example. You need22% to perform the normalization separately for23% each feature.24%25% Hint: You might find the 'mean' and 'std' functions useful.26%2728for i = 1:size(X,2),29mu(:,i) = mean(X(:,i));30sigma(:,i) = std(X(:,i));31X_norm(:,i) = (X(:,i) - mu(:,i))/(std(X(:,i)));32end;33fprintf("After featuring scaling, X is:\n");34disp(X_norm);35% ============================================================3637end383940