【问题标题】:Number of components on PCA limited by the number of samplesPCA 上的组件数量受样本数量限制
【发布时间】:2017-02-04 03:51:57
【问题描述】:

我正在使用 sklearn 进行 PCA,我正在使用一些虚拟数据测试函数,当我的样本数量超过我想要使用的组件数量时,它可以正常工作:

from sklearn.decomposition import PCA
import numpy as np    

features_training = np.random.rand(10,30)
components = 8
pca = PCA(n_components=int(components))
X_pca = pca.fit_transform(features_training)

从上面的代码我得到一个 10*8 的矩阵。

X_pca.shape
(10, 8)

但是对于相同的数据,如果我尝试保留 15 个组件:

features_training = np.random.rand(10,30)
components = 15
pca = PCA(n_components=int(components))
X_pca = pca.fit_transform(features_training)

我没有得到一个 10*15 的矩阵,而是一个 10*10 的矩阵。

X_pca.shape
(10, 10)

因此,组件的数量似乎不仅受特征数量的限制,还受样本数量的限制。这是为什么呢?

【问题讨论】:

    标签: python machine-learning scikit-learn pca


    【解决方案1】:

    我无法告诉您 PCA 的实际工作方式。但是在Scikit-learn documentation for PCA中,提到了actual n_components = min(n_samples, specified n_components)

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 2014-02-26
      • 2017-09-21
      • 1970-01-01
      • 2021-01-08
      相关资源
      最近更新 更多