Why different result with PCA and SVD in Matlab?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello
I have implemented my PCA function in Matlab in the following way:
function e = myPCA(X)
[D, N] = size(X);
m = mean(X, 2);
X = X - repmat(m, 1, N);
[e, ~, ~] = svd(X,'econ');
end
When I use now the built in Matlab function
[e, ~, ~] = pca(X');
I'm getting the same absolute values as with my function but for some columns of U the sign is flipped.
Which ones is the right way to go and why is there this difference in sign?
Edit: I'm interested in retrieving all the eigenvalues and eigenvectors of the covariance matrix. If I'm using Matlab's pca method the eigenvectors are the columns in "e" from [e, ~, ~] = pca(X');. Is this right? But how can I retrieve the eigenvalues?
I have another point: "Compute the Principal components and eigenvalues of the Covariance/Correlation matrix". Are the principal components equal to the eigenvectors? Should I use in this case the pca method or SVD method from Matlab or does it not matter?
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!