我有 PCA 的问题。我读到 PCA 需要干净的数值。trainDf我从一个名为shape的数据集开始我的分析(1460, 79)。
我通过删除空值、插补和删除列来进行数据清理和处理,我得到了一个transformedDatashape的数据框(1458, 69)。
数据清洗步骤为:
LotFrontage用平均值估算MasVnrArea用 0 估算(小于 10 列)- 分类列的序号编码
Electrical以最频繁的值估算
我发现了 IQR 的异常值并得到withoutOutliers了 shape (1223, 69)。
在此之后,我查看了直方图并决定将其应用于PowerTransformer某些特征和StandardScaler其他特征,然后我得到了normalizedData.
现在我尝试做 PCA,我得到了这个:
pca = PCA().fit(transformedData)
print(pca.explained_variance_ratio_.cumsum())
plt.plot(pca.explained_variance_ratio_.cumsum())
plt.xlabel('number of components')
plt.ylabel('cumulative explained variance')
此 PCA 的输出如下:
[0.67454179 0.8541084 0.98180307 0.99979932 0.99986346 0.9999237
0.99997091 0.99997985 0.99998547 0.99999044 0.99999463 0.99999719
0.99999791 0.99999854 0.99999909 0.99999961 0.99999977 0.99999988
0.99999994 0.99999998 0.99999999 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. ]
然后我尝试了:
pca = PCA().fit(withoutOutliers)
print(pca.explained_variance_ratio_.cumsum())
plt.plot(pca.explained_variance_ratio_.cumsum())
plt.xlabel('number of components')
plt.ylabel('cumulative explained variance')
出去:
[0.68447278 0.86982875 0.99806386 0.99983727 0.99989606 0.99994353
0.99997769 0.99998454 0.99998928 0.99999299 0.9999958 0.99999775
0.99999842 0.99999894 0.99999932 0.99999963 0.9999998 0.9999999
0.99999994 0.99999998 0.99999999 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1.
1. 1. 1. ]
最后:
pca = PCA().fit(normalizedData)
print(pca.explained_variance_ratio_.cumsum())
plt.plot(pca.explained_variance_ratio_.cumsum())
plt.xlabel('number of components')
plt.ylabel('cumulative explained variance')
出去:
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.
1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
最后一次执行怎么可能给出这样的输出?
以下是数据分布
transformedData
withoutOutliers
normalizedData
如有必要,我将添加任何进一步的数据,提前感谢任何可以提供帮助的人!





