我试图在一个大小为m x n的矩阵上运行PCA,其中m是特征数量,n是样本数量。
假设我想保留具有最大方差的nf
个特征。使用scikit-learn
,我可以这样做:
from sklearn.decomposition import PCA
nf = 100
pca = PCA(n_components=nf)
# X is the matrix transposed (n samples on the rows, m features on the columns)
pca.fit(X)
X_new = pca.transform(X)
现在,我得到了一个新的矩阵X_new
,其形状为n x nf。是否可以知道哪些特征被丢弃或保留了?
谢谢
(n, nf)
,而不是(nf, n)
。 - eickenberg