Question about different results using PCA and SVD
3 views (last 30 days)
Show older comments
Hello
I'm in the process of larning about SVD and PCA, and have been experimenting by using Matlab
I have a 3D set of points as a nx3 column vector called XYZ_orig
I subtracted the mean from X, Y, and Z and perform SVD and PCA on the data:
cent=[mean(XYZ_orig(:,1)), mean(XYZ_orig(:,2)), mean(XYZ_orig(:,3))];
XYZ = [XYZ_orig(:,1)-cent(1),XYZ_orig(:,2)-cent(2),XYZ_orig(:,3)-cent(3)];
[U,S,V] = svd(XYZ);
[coeff,~,~,~,~,~] = pca(XYZ);
my understanding is the basis vectors/coefficients for SVD in 'V' and PCA in 'coeff' should be the same, however, although the 1st column is always the same, I am finding that the second and third columns are always of different sign with the same coefficients.
V =
0.5926 -0.2694 -0.7591
0.7193 -0.2470 0.6493
-0.3624 -0.9308 0.0474
coeff =
0.5926 0.2694 0.7591
0.7193 0.2470 -0.6493
-0.3624 0.9308 -0.0474
Can someone explain why there is this sign difference for columns 2 and 3?
thanks!
hpw
0 Comments
Accepted Answer
Steven Lord
on 16 Aug 2022
From the Algorithms section on the pca documentation page: "The pca function imposes a sign convention, forcing the element with the largest magnitude in each column of coefs to be positive. Changing the sign of a coefficient vector does not change its meaning."
More Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!