Path: blob/master/Week 9/Programming Assignment - 8/ex8/estimateGaussian.m
616 views
function [mu sigma2] = estimateGaussian(X)1%ESTIMATEGAUSSIAN This function estimates the parameters of a2%Gaussian distribution using the data in X3% [mu sigma2] = estimateGaussian(X),4% The input X is the dataset with each n-dimensional data point in one row5% The output is an n-dimensional vector mu, the mean of the data set6% and the variances sigma^2, an n x 1 vector7%89% Useful variables10[m, n] = size(X);1112% You should return these values correctly13mu = zeros(n, 1);14sigma2 = zeros(n, 1);1516% ====================== YOUR CODE HERE ======================17% Instructions: Compute the mean of the data and the variances18% In particular, mu(i) should contain the mean of19% the data for the i-th feature and sigma2(i)20% should contain variance of the i-th feature.21%22%for i=1:m,23%for j = 1:n,24%mu(i) = (1/m) * sum(X(:,j));25%sigma2(i) = (1/m) * sum((X(:,j) - mu(i)).^2);26%endfor27%endfor28mu = (1/m) * sum(X(:,[1:n]));29disp(mu);30sigma2 = (1/m) * sum((X - mu).^2);31disp(sigma2);32% =============================================================333435end363738