About PCA and 'manual' decomposition
1 view (last 30 days)
Show older comments
If I try to perform a PCA with elementary functions, I use this code (MATLAB 7.10):
load acetylene.mat
dataset = [x1 x2 x3 y];
[M,N]=size(dataset);
mn=mean(dataset,1);
data=dataset-repmat(mn,M,1);
covariance = 1 / (M-1) * (data')*(data);
[PrinComp,L]=eig(covariance);
L=diag(L);
[values,Lind]=sort(-1*L);
PC = PC(:,Lind);
At this point I tried to compare what I've done with: [a,b]=PCA(dataset). Well, eigenvalues are the same, but the matrix is a little bit different (the second column has the opposite signs).
Thanks.
0 Comments
Accepted Answer
Thorsten
on 28 Oct 2015
This is discussed here: http://stackoverflow.com/questions/18152052/matlab-eig-returns-inverted-signs-sometimes
More Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!