GMM - gaussian mixture as summation of pdf

조회 수: 2 (최근 30일)
Azzam Albalawi
Azzam Albalawi 2023년 3월 27일
답변: the cyclist 2023년 3월 28일
I will provide my code that do GMM Modeling, I need to plot the gaussian mixture as summation of pdf and lay down the scatter of data on top of the summation of pdf:
clear variables;
% Load CSV dataset
data = csvread('reduced_dataset_10.csv');
% Prepare the dataset
X = data; % Select relevant features
X_norm = zscore(X); % Normalize the dat
% Define the maximum number of Gaussians to consider
max_k = 10;
% Fit GMM models with different numbers of Gaussians and replicates
models = cell(max_k, 1);
for k = 1:max_k
models{k} = fitgmdist(X_norm, k, 'Replicates', 5);
end
% Calculate AIC for each model
AIC = zeros(max_k, 1);
for k = 1:max_k
AIC(k) = models{k}.AIC;
end
% Choose the model with the lowest AIC
[~, best_k] = min(AIC);
best_model = models{best_k};
% Get the PDFs, Gaussians, means, and standard deviations
pdfs = @(x)pdf(best_model, x); % PDFs
gaussians = @(x)best_model.pdf(x); % Gaussians
% Get the means and standard deviations
means = best_model.mu; % Means
stds = sqrt(best_model.Sigma);
% Display the best fit number of Gaussians
fprintf('Best fit number of Gaussians: %d\n', best_k);
% Plot the means and standard deviations in a 3D plot with an improved viewing angle
figure;
hold on;
for i = 1:size(means,1)
for j = 1:size(means,2)
plot3(means(i,j), j, i, 'ro', 'MarkerSize', 10, 'MarkerFaceColor', 'r');
plot3([means(i,j)-stds(i,j) means(i,j)+stds(i,j)], [j j], [i i], 'b', 'LineWidth', 2);
end
end
xlabel('Feature Mean');
ylabel('Gaussian Component');
zlabel('Feature Number');
set(gca, 'YTick', 1:size(means,2), 'YTickLabel', {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10'});
view(60, 30); % Set the viewing angle to 45 degrees azimuth and 30 degrees elevation
clear k X X_norm;
  댓글 수: 1
the cyclist
the cyclist 2023년 3월 28일
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2023년 3월 28일
It will be easier to help when we see the data, but the general idea would be to sum the pdfs of your best_model, weighted by the ComponentProportion property.

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by