You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

estimateGaussian.m 974 B

8 years ago
12345678910111213141516171819202122232425262728293031323334
  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 = zeros(n, 1);
  13. sigma2 = zeros(n, 1);
  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. mu = mean(X)';
  21. for i = 1 : n
  22. sigma2(i) = sum((X(:, i) - mu(i)) .^2) /m;
  23. end
  24. % =============================================================
  25. end

机器学习

Contributors (1)