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