how to use PCA coefficients (princomp)

5 Ansichten (letzte 30 Tage)
A
A am 10 Dez. 2012
Beantwortet: Aditya am 8 Feb. 2025
I have matrix of 10000 rows and 500 columns where rows are observations and columns for features. The data is for three different classes (appx 3300 samples of each class). Now I want to apply princomp for PCA to reduce dimension of data. The coefficients matrix results in 500X500 and score is same matrix dimension as original (10000X500).
Kindly help me how can I modify my original data (10000X500) using coefficients and score matrices ? what is the procedure?
Thanks and in advance!

Antworten (1)

Aditya
Aditya am 8 Feb. 2025
Hi A,
To apply Principal Component Analysis (PCA) using MATLAB's princomp (or the updated pca function), and then transform your original data into a reduced-dimensionality space, follow these steps:
% Assume your data matrix is named 'dataMatrix' with size 10000x500
[coeff, score, latent, tsquared, explained, mu] = pca(dataMatrix);
cumulativeVariance = cumsum(explained);
plot(cumulativeVariance);
xlabel('Number of Principal Components');
ylabel('Cumulative Explained Variance (%)');
% Choose the number of components to keep
k = 50; % for example, keep the first 50 components
% Transform the original data
reducedData = score(:, 1:k);
% Reconstruct the data from the reduced dimensions
reconstructedData = reducedData * coeff(:, 1:k)' + mu;

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by