Multivariate Gaussian Distribution Plotting of 4 Variable Data

1 次查看(过去 30 天)
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.

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-9
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by