GMM - gaussian mixture as summation of pdf

5 visualizzazioni (ultimi 30 giorni)
Azzam Albalawi
Azzam Albalawi il 27 Mar 2023
Risposto: the cyclist il 28 Mar 2023
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 Commento
the cyclist
the cyclist il 28 Mar 2023
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.

Accedi per commentare.

Risposte (1)

the cyclist
the cyclist il 28 Mar 2023
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.

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by