使用Python进行PCA分解:功能相关性 [英] PCA decomposition with python: features relevances

查看:276
本文介绍了使用Python进行PCA分解:功能相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在关注下一个主题:

I'm following now next topic: How can I use PCA/SVD in Python for feature selection AND identification? Now, we decompose our data set in Python with PCA method and use for this the sklearn.decomposition.PCA With the usage of attributes components_ we get all components. Now we have very similar goal: want take only first several components (this part is not a problem) and see, what the input features proportions has every PCA component (to know, which features are much important for us). How is possible to do it? Another question is, has the python lybrary another implementations of Principal Component Analysis?

推荐答案

每个PCA组件的输入要素比例是多少(要知道,哪些要素对我们非常重要).怎么可能呢?

what the input features proportions has every PCA component (to know, which features are much important for us). How is possible to do it?

components_数组的形状为(n_components, n_features),因此components_[i, j]已经为您提供了特征j对分量i的贡献的(有符号)权重.

The components_ array has shape (n_components, n_features) so components_[i, j] is already giving you the (signed) weights of the contribution of feature j to component i.

如果要获取构成分量i的前3个特征的索引,而与符号无关,则可以执行以下操作:

If you want to get the indices of the top 3 features contributing to component i irrespective of the sign, you can do:

numpy.abs(pca.component_[i]).argsort()[::-1][:3]

注意:[::-1]表示法可以反转数组的顺序:

Note: the [::-1] notation makes it possible to reverse the order of an array:

>>> import numpy as np
>>> np.array([1, 2, 3])[::-1]
array([3, 2, 1])

另一个问题是,python库是否还有另一个实现 主成分分析?

Another question is, has the python library another implementations of Principal Component Analysis?

PCA只是中心数据集的截断奇异值分解.您可以根据需要直接使用numpy.linalg.svd.看看的scikit-learn实现的源代码PCA 以获取详细信息.

PCA is just a truncated Singular Value Decomposition of the centered dataset. You can use numpy.linalg.svd directly if you wish. Have a look at the soure code of the scikit-learn implementation of PCA for details.

这篇关于使用Python进行PCA分解:功能相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆