Why pca() returns 1 less principal component?
Ältere Kommentare anzeigen
a = diag([1 2 3]);
disp(pca(a));
I expected that it will display 3 principal components, since my matrix "a" is full-rank 3-by-3 one. However, only two PCs are displayed. Actually, when I do the same in R, it does give me 3 PCs, the first two of which are exactly the same as the two that matlab provides.
However, when the number of row exceeds the number of columns, pca() function seems to work well, for example:
a = [diag([1 2 3]); 0, 0, 4];
disp(pca(a));
Is it because I didn't use pca() properly, or do I need to specify the style for the result to be displayed? Thanks...
Akzeptierte Antwort
Weitere Antworten (1)
Soma Mbadiwe
am 6 Sep. 2018
[coeff,score,latent] = pca(X, 'Economy',false);
The code above will tell MATLAB to return all the PCs and PVs even if some are zero.
No need re-inventing the wheel, especially because MATLAB's 'pca' function can give you so much more than just the PCs (coeff) and PVs (latent).
PS: I know this is more of an answer to the title of this question than the question itself, but Google brings this page up quite often.
1 Kommentar
Changoleon
am 29 Jan. 2019
This is correct! Thank you for the clarification. If the number of observation is less than variables, pca function must be used with Economy as false.
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!