用于在 Python 中查找特征的未排序特征值

发布于 2024-11-13 08:59:45 字数 119 浏览 4 评论 0原文

我现在正在尝试使用 PCA 进行一些操作,但了解每个特征值的特征对我来说非常重要。

numpy.linalg.eig 为我们提供了已经排序的对角矩阵,但我希望这个矩阵位于原始位置。有人知道我怎样才能做到吗?

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 sorted but I wanted this matrix with them at the original positions. Does anybody know how I can make it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

动次打次papapa 2024-11-20 08:59:45

斯文在评论中提到的内容是正确的。特征值没有“默认”排序。每个特征值都与一个特征向量相关联,并且特征值-特征向量对正确匹配是很重要的。您会发现所有语言和包都会这样做。

因此,如果 R 给你特征值 [e1,e2,e3 和特征向量 [v1,v2,v3],python 可能会给你(比如)[e3, e2,e1][v3,v2,v1]

回想一下,特征值告诉您数据中的方差有多少是由与其关联的特征向量解释的。因此,在 PCA 中有用的特征值自然排序(对我们来说很直观)是按大小(升序或降序)排序。这样,您可以轻松查看特征值并确定要保留哪些特征值(大,因为它们解释了大部分数据)以及要丢弃哪些特征值(小,可能是高频特征或只是噪声)

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)

讽刺将军 2024-11-20 08:59:45

(不是答案,但我需要此评论的高级格式。)

您必须指定您想要的排序。例如,该矩阵的特征

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

值为+1-1,对应于特征向量(1 1)(1 - 1)。您希望如何对这些特征值进行排序,为什么?

(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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文