Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/Coursera-Machine-Learning
Path: blob/master/Week 9/Programming Assignment - 8/ex8/estimateGaussian.m
616 views
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
10
% Useful variables
11
[m, n] = size(X);
12
13
% You should return these values correctly
14
mu = zeros(n, 1);
15
sigma2 = zeros(n, 1);
16
17
% ====================== YOUR CODE HERE ======================
18
% Instructions: Compute the mean of the data and the variances
19
% In particular, mu(i) should contain the mean of
20
% the data for the i-th feature and sigma2(i)
21
% should contain variance of the i-th feature.
22
%
23
%for i=1:m,
24
%for j = 1:n,
25
%mu(i) = (1/m) * sum(X(:,j));
26
%sigma2(i) = (1/m) * sum((X(:,j) - mu(i)).^2);
27
%endfor
28
%endfor
29
mu = (1/m) * sum(X(:,[1:n]));
30
disp(mu);
31
sigma2 = (1/m) * sum((X - mu).^2);
32
disp(sigma2);
33
% =============================================================
34
35
36
end
37
38