featureNormalize.m 510 B

1234567891011121314151617
  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. mu = mean(X);
  8. X_norm = bsxfun(@minus, X, mu);
  9. sigma = std(X_norm);
  10. X_norm = bsxfun(@rdivide, X_norm, sigma);
  11. % ============================================================
  12. end