我想使用PCA对一些数据,以获得最重要的主成分的矩阵,捕捉95%的总方差。我在找一个函数来做这个,但我找不到办法。
我只知道以下几点:
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)这种方法的问题是,我需要进行两次拟合,这是性能瓶颈。有更好的方法吗?
发布于 2019-10-23 22:16:09
在文档中,您可以看到如果0< n_components <1和svd_solver == 'full',则选择组件数,以便需要解释的方差量大于n_components指定的百分比。
若要获得至少95%方差的组件,请使用主成分分析(n_components=0.95,svd_solver='full')。
https://stackoverflow.com/questions/58531538
复制相似问题