
Multivariate Gaussian Distribution Plotting of 4 Variable Data
1 view (last 30 days)
Show older comments
Taha Erkam Orhan
on 9 May 2020
Commented: Taha Erkam Orhan
on 10 May 2020
Hello I'm working on classification of Iris data set which has 4 variable: Setal length-width, Petal length-width. I have calculated the 4x4 covariance and mean values. How can I plot Gaussian distribution of this data set. I couldn't plot it via using Mvnpdf function in the link. I would be appreciated if you could help me. Thanks.
0 Comments
Accepted Answer
Ameer Hamza
on 9 May 2020
You are trying to visualize a 5D function. It is not easy to visualize such a function on a single graph. The easiest way is to make several graphs and show a higher dimensional slice of the function. See the following example. It uses the Setal length (SL) and Setal width (SW) on the x and y-axis. And uses the values of Petal length (PL) and Petal Width (PW) is used the higher dimensional variables to create several graphs.
rng(0);
mu = rand(1, 4);
sigma = rand(4);
sigma = sigma*sigma.'; % positive definite
sl = -3:0.1:3;
sw = -3:0.1:3;
pl = 0:1:2;
pw = 0:1:2;
[SL, SW, PL, PW] = ndgrid(sl, sw, pl, pw);
X = [SL(:) SW(:) PL(:) PW(:)];
Y = mvnpdf(X, mu, sigma);
Y = reshape(Y, size(SL));
figure;
tiledlayout('flow');
for i=1:numel(pl)
for j=1:numel(pw)
nexttile
surf(sl, sw, Y(:,:,i,j));
title(sprintf('PL=%.2f, PW=%.2f', pl(i), pw(j)));
shading interp
end
end

More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!