Transform points from PCA space to the original space!
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dears, I am using PCA to better represent my data so I could fit a gaussian distribution on them more easily. This is my code
MyMatrix=rand(2,hight*width); [COEFF,SCORE] = princomp(MyMatrix'); MyMatrix =SCORE';
hold on
options = statset('Display','final');
GMModel = fitgmdist(MyMatrix',2,'Options',options);
Means=GMModel.mu;
g=ezcontour(@(x,y)pdf(GMModel,[x y]),[min(MyMatrix(1,:)) ...
max(MyMatrix(1,:))],[min(MyMatrix(2,:)) max(MyMatrix(2,:))] );
plot(Means(1,1),Means(1,2),'+');
plot(Means(2,1),Means(2,2),'+');
hold off
Now I want to find the Means that I just calculated in the 2D original space, My question is : how to transform Means from the PCA coordinate space back to the original space.
I will appreciate any help! Thank you.
0 Kommentare
Antworten (1)
Aditya
am 5 Feb. 2025
Hi Najah,
To transform the means of the Gaussian Mixture Model (GMM) back from the PCA-transformed space to the original feature space, you need to perform an inverse transformation using the PCA coefficients. Here's how you can do it:
% Generate random data
MyMatrix = rand(2, height * width);
% Perform PCA
[COEFF, SCORE, latent, tsquared, explained, mu] = pca(MyMatrix');
% Fit Gaussian Mixture Model
options = statset('Display', 'final');
GMModel = fitgmdist(SCORE, 2, 'Options', options);
% Get the means in the PCA-transformed space
MeansPCA = GMModel.mu;
% Transform means back to the original space
MeansOriginal = MeansPCA * COEFF' + mu;
% Plot the results
hold on;
g = ezcontour(@(x, y) pdf(GMModel, [x y]), ...
[min(SCORE(:, 1)) max(SCORE(:, 1))], ...
[min(SCORE(:, 2)) max(SCORE(:, 2))]);
% Plot means in PCA space
plot(MeansPCA(:, 1), MeansPCA(:, 2), '+');
% Plot means in original space
plot(MeansOriginal(:, 1), MeansOriginal(:, 2), 'o');
hold off;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!