Search code examples
pythonpcasvd

Different order of eigenvalues computed with PCA and SVD


I really don't know why, when i computed the eigenvalues with PCA from my dataset i obtain a vector which have values in different order respect of SVD

This is the result

This is the code

Thanks for help!!!


Solution

  • Your PCA is incomplete when you use np.linalg.eig because after eigen-decomposition you have to reorder the terms so the eigenvalues in the diagonal matrix are in descending order (this is not part of the eigen-decomposition itself). Furthermore, the eig docs do not guarantee any order in your results, whereas the SVD docs explicitly state that your values are returned in descending order.