【发布时间】:2019-01-10 02:59:34
【问题描述】:
我想在 18 维的热图上应用 PCA。
dim(heatmaps)=(224,224,18)
由于 PCA 仅采用 dim
heatmaps=heatmaps.reshape(-1,18)
heatmaps.shape
(50176, 18)
现在,我将应用 PCA 并采用保留 95% 方差的第一个组件。
from sklearn.decomposition import PCA
pca = PCA(n_components=18)
reduced_heatmaps=pca.transform(heatmaps)
但是reduced_heatmaps 的尺寸与原来的heatmaps 相同(50176, 18)。
我的问题如下: 如何在保留 95% 的方差的同时降低热图的维度?
奇怪的事情
pca.explained_variance_ratio_.cumsum()
array([ 0.05744624, 0.11482341, 0.17167621, 0.22837643, 0.284996 ,
0.34127299, 0.39716828, 0.45296374, 0.50849681, 0.56382308,
0.61910508, 0.67425335, 0.72897448, 0.78361028, 0.83813329,
0.89247688, 0.94636864, 1. ])
这意味着,我需要保留 17 个组件来减少我的数据的维度,这样我就有 18 个维度。
怎么了?
编辑:遵循 Eric Yang 的建议
heatmaps=heatmaps.reshape(18,-1)
heatmaps.shape
(18,50176)
然后应用 PCA 如下:
pca = PCA(n_components=11)
reduced_heatmaps=pca.fit_transform(heatmaps)
pca.explained_variance_ratio_.cumsum()
results the following :
array([ 0.21121199, 0.33070526, 0.44827572, 0.55748779, 0.64454442,
0.72588593, 0.7933346 , 0.85083687, 0.89990991, 0.9306283 ,
0.9596194 ], dtype=float32)
需要 11 个分量来解释我的数据的 95% 方差。
reduced_heatmaps.shape
(18, 11)
因此我们从 (18,50176) 到 (18, 11)
感谢您的帮助
【问题讨论】:
标签: python-2.7 scikit-learn heatmap pca