estimateGaussian.m 949 B

123456789101112131415161718192021222324252627282930313233343536
  1. function [mu sigma2] = estimateGaussian(X)
  2. %ESTIMATEGAUSSIAN This function estimates the parameters of a
  3. %Gaussian distribution using the data in X
  4. % [mu sigma2] = estimateGaussian(X),
  5. % The input X is the dataset with each n-dimensional data point in one row
  6. % The output is an n-dimensional vector mu, the mean of the data set
  7. % and the variances sigma^2, an n x 1 vector
  8. %
  9. % Useful variables
  10. [m, n] = size(X);
  11. % You should return these values correctly
  12. mu = sum(X) / m;
  13. sigma2 = sum((X - mu) .^ 2) / m;
  14. % ====================== YOUR CODE HERE ======================
  15. % Instructions: Compute the mean of the data and the variances
  16. % In particular, mu(i) should contain the mean of
  17. % the data for the i-th feature and sigma2(i)
  18. % should contain variance of the i-th feature.
  19. %
  20. % =============================================================
  21. end