开发者

Non sorted eigenvalues for finding features in Python

开发者 https://www.devze.com 2023-03-10 00:44 出处:网络
I am now trying some stuff with PCA but it\'s very important for me to know which are the features responsible for each eigenvalue.

I am now trying some stuff with PCA but it's very important for me to know which are the features responsible for each eigenvalue.

numpy.linalg.eig gives us the diagonal matrix already sorte开发者_开发问答d but I wanted this matrix with them at the original positions. Does anybody know how I can make it?


What Sven mentioned in his comments is correct. There is no "default" ordering of the eigenvalues. Each eigenvalue is associated with an eigenvector, and it is important is that the eigenvalue-eigenvector pair is matched correctly. You'll find that all languages and packages will do so.

So if R gives you eigenvalues [e1,e2,e3 and eigenvectors [v1,v2,v3], python probably will give you (say) [e3,e2,e1] and [v3,v2,v1].

Recall that an eigenvalue tells you how much of the variance in your data is explained by the eigenvector associated with it. So, a natural sorting of the eigenvalues (that is intuitive to us) that is useful in PCA, is by size (either ascending or descending). That way, you can easily look at the eigenvalues and identify which ones to keep (large, as they explain most of the data) and which ones to throw (small, which could be high frequency features or just noise)


(Not an answer, but I need advanced formatting for this comment.)

You have to specify what ordering gyou want. E.g., the eigenvalues of this matrix

    / 0  1 \
A = |      |
    \ 1  0 /

are +1 and -1, corresponding to the eigenvectors (1 1) and (1 -1). How would you like these eigenvalues to be ordered, and why?

0

精彩评论

暂无评论...
验证码 换一张
取 消