我正在尝试使用PCA来降低特征维度。我已经能够将PCA应用到我的训练数据上,但我不明白为什么降维后的特征集(X_train_pca
)与原始特征(X_train
)没有任何相似之处。
print(X_train.shape) # (26215, 727)pca = PCA(0.5)pca.fit(X_train)X_train_pca = pca.transform(X_train)print(X_train_pca.shape) # (26215, 100)most_important_features_indicies = [np.abs(pca.components_[i]).argmax() for i in range(pca.n_components_)]most_important_feature_index = most_important_features_indicies[0]
X_train_pca
中的第一个特征向量不应该只是X_train
中第一个特征向量的子集吗?例如,为什么下面的表达式不等于True?
print(X_train[0][most_important_feature_index] == X_train_pca[0][0]) # False
此外,X_train
的第一个特征向量中的任何特征都不在X_train_pca
的第一个特征向量中:
for i in X_train[0]: print(i in X_train_pca[0])# False# False# False# ...
回答:
PCA将你的高维特征向量转换为低维特征向量。它不只是简单地确定原始空间中最不重要的索引并删除那个维度。