gpt4 book ai didi

python - 用python : features relevances进行PCA分解

转载 作者:行者123 更新时间:2023-11-28 20:45:49 25 4
gpt4 key购买 nike

我现在关注下一个主题:How can I use PCA/SVD in Python for feature selection AND identification?现在,我们使用 PCA 方法在 Python 中分解我们的数据集,并为此使用 sklearn.decomposition.PCA 使用属性 components_ 我们得到所有组件。现在我们有非常相似的目标:只想取前几个组件(这部分不是问题),看看每个 PCA 组件的输入特征比例是多少(要知道,哪些特征对我们来说非常重要)。怎么可能呢?另一个问题是,python lybrary是否有另一个主成分分析的实现?

最佳答案

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 的贡献。

如果你想获得对组件 i 贡献最大的 3 个特征的索引而不考虑符号,你可以这样做:

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

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

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

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

PCA 只是中心数据集的截断奇异值分解。如果您愿意,可以直接使用 numpy.linalg.svd。看看 soure code of the scikit-learn implementation of PCA了解详情。

关于python - 用python : features relevances进行PCA分解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22348668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com