Number of components on PCA limited by the number of samples
我正在使用sklearn进行PCA,正在使用一些虚拟数据测试功能,当我的样本数量超过了我想使用的组件数量时,它就可以正常工作:
1 2 3 4 5 6 7 | 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的矩阵。
1 2 | X_pca.shape (10, 8) |
但是对于相同的数据,如果我尝试保留15个组件:
1 2 3 4 | 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的矩阵。
1 2 | X_pca.shape (10, 10) |
因此,似乎组件的数量不仅受到特征数量的限制,而且还受到样本数量的限制。 这是为什么?
我无法告诉您PCA的实际工作方式。 但是在PCA的Scikit学习文档中,提到了