本文介绍了使用PCA提取MNIST图像的特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Matlab读取MNIST数据库.这些图像最初是28x28(= 784)像素.因此,我有一个2D 784x1000阵列(意味着,我已读取1000张图像).

I use Matlab to read the MNIST database. Those images are, originally, 28x28 (=784) pixels. So, I have a 2D 784x1000 array (meaning, I have read 1000 images).

假设我的2D数组的名称为IMGS,那么Matlab表达式:IMGS(:, 1),会给我第一张图像.

Supposing my 2D array's name is IMGS, the Matlab expression: IMGS(:, 1), would give me the first image.

为了执行PCA,因此要提取图像的某些特征(从784种特征中提取):

In order to perform PCA, so to extract some of the features of the image (from the 784 of them):

  1. 我在称为IMGS_T的数组中转置了IMGS数组,将图像放入行中并将特征(维)放入列中(IMGS_T(1,:)对应于第一张图像).
  2. 我这样使用princomp函数:[COEFF,SCORES] = princomp(IMGS_T];

  1. I transpose the array IMGS, putting the images to rows and features (dimensions) to columns, in an array called IMGS_T (IMGS_T(1, :) corresponds to first image).
  2. I use the princomp function like this: [COEFF, SCORES] = princomp(IMGS_T];

我的问题是这个(这可能有点琐碎,但是,我想确定这一点):假设我要从784个特征中总共提取100个特征,我需要的只是SCORES的前100列?

My question is this (and it may be a little trivial but, I want to be sure for this):Supposing I want to extract 100 features from the overall of the 784 of them, all I need is the first 100 columns of SCORES?

所以,用Matlab的话,我只需要写:IMGS_PCA = IMGS(:, 100)'我将创建一个名为IMGS_PCA的100x1000数组,该数组将在其列中保存我的1000个MNIST图像,并在其行中保存它们的前100个最重要的功能?

So, in Matlab terms, all I need is to write: IMGS_PCA = IMGS(:, 100)'and I will have created an 100x1000 array, called IMGS_PCA which will hold my 1000 MNIST images in its columns and the first 100 most important features of them in its rows?

推荐答案

基本上是正确的.请注意,在princomp中,输入行对应于观察值,列对应变量.

Basically it's correct. Note that in princomp rows of input correspond to observations, and columns to variables.

为说明您的过程,

IMGS = rand(1000,784);
[COEFF, SCORE] = princomp(IMGS);

要证明该功能的使用正确无误,可以尝试恢复原始图像,

To prove the use of function is correct, you can try to recover the original image,

recovered_IMGS = SCORE / COEFF + repmat(mean(IMGS,1), 1000, 1);

然后IMGS - recovered_IMGS将为您提供零矩阵(在数值误差内).

then IMGS - recovered_IMGS will give you the zero matrix (within numerical error).

要仅使用前100个功能,只需

To use only the first 100 features, you can just

for i=101:784
    SCORE(:,i) = zeros(1000,1);
end

然后使用相同的代码恢复图像:

Then use the same code to recover the images:

recovered_IMGS_100 = SCORE / COEFF + repmat(mean(IMGS,1), 1000, 1);

或者,正如您提到的,您可以创建另一个100 x 1000的阵列来获得相同的结果.

Or you can, as you mentioned , created another 100 x 1000 array to achieve the same result.

这篇关于使用PCA提取MNIST图像的特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:31