在 sklearn 中通过 PCA 降维
Reduce dimension by PCA in sklearn
我想在 sklearn 中通过 PCA 将图像的维度从 (480,640,3) 降低到 (1,512)。所以我将图像重塑为 (1, 921600)。之后,我执行 pca 来减少尺寸。但它变为 (1,1) 而不是 (1,512)
>>> img.shape
(1, 921600)
>>> pca = PCA(n_components=512)
>>> pca.fit_transform(img).shape
(1, 1)
谁能告诉我怎么把单张图片降维?谢谢
这是意料之中的。 Wiki says (bold annotation by me):
PCA is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components (or sometimes, principal modes of variation)
在形状 (1, 921600)
上拟合 PCA 意味着,这是一个具有 921600 个特征的样本。
n_components == min(n_samples, n_features)
我想在 sklearn 中通过 PCA 将图像的维度从 (480,640,3) 降低到 (1,512)。所以我将图像重塑为 (1, 921600)。之后,我执行 pca 来减少尺寸。但它变为 (1,1) 而不是 (1,512)
>>> img.shape
(1, 921600)
>>> pca = PCA(n_components=512)
>>> pca.fit_transform(img).shape
(1, 1)
谁能告诉我怎么把单张图片降维?谢谢
这是意料之中的。 Wiki says (bold annotation by me):
PCA is a statistical procedure that uses an orthogonal transformation to convert a set of observations of possibly correlated variables into a set of values of linearly uncorrelated variables called principal components (or sometimes, principal modes of variation)
在形状 (1, 921600)
上拟合 PCA 意味着,这是一个具有 921600 个特征的样本。
n_components == min(n_samples, n_features)