featureNormalize.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. % You need to set these values correctly
  8. mu = mean(X);
  9. sigma = std(X);
  10. X_norm = (X - ones(length(X),1)*mu ) ./ (ones(length(X),1)*sigma);
  11. % ====================== YOUR CODE HERE ======================
  12. % Instructions: First, for each feature dimension, compute the mean
  13. % of the feature and subtract it from the dataset,
  14. % storing the mean value in mu. Next, compute the
  15. % standard deviation of each feature and divide
  16. % each feature by it's standard deviation, storing
  17. % the standard deviation in sigma.
  18. %
  19. % Note that X is a matrix where each column is a
  20. % feature and each row is an example. You need
  21. % to perform the normalization separately for
  22. % each feature.
  23. %
  24. % Hint: You might find the 'mean' and 'std' functions useful.
  25. %
  26. % ============================================================
  27. end