首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sklearn.decomposition.PCA:按给定比率获取组件

Sklearn.decomposition.PCA:按给定比率获取组件
EN

Stack Overflow用户
提问于 2019-10-23 22:01:57
回答 1查看 191关注 0票数 0

我想使用PCA对一些数据,以获得最重要的主成分的矩阵,捕捉95%的总方差。我在找一个函数来做这个,但我找不到办法。

我只知道以下几点:

代码语言:javascript
复制
from sklearn.decomposition import PCA
# W_0 is a matrix 
pca = PCA().fit(W_0)
# get the index of the component which has variance higher than 0.95
index_component = np.min(np.argwhere(np.cumsum(pca.explained_variance_ratio_)>0.95))
# Now fit again with the given component 
pca = PCA(n_components= index_component+1)
pca.fit(W_0)

这种方法的问题是,我需要进行两次拟合,这是性能瓶颈。有更好的方法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-23 22:16:09

文档中,您可以看到如果0< n_components <1和svd_solver == 'full',则选择组件数,以便需要解释的方差量大于n_components指定的百分比。

若要获得至少95%方差的组件,请使用主成分分析(n_components=0.95,svd_solver='full')。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58531538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档