0
我使用sklearn做PCA,當我有更多的樣本比我想要使用它的組件數量更多的樣本時,我正在測試一些虛擬數據的功能。蠻好的: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)
所以看起來,組件的數量不僅受特徵數量的限制,而且受限於樣本數量。這是爲什麼?