http://ufldl.stanford.edu/wiki/index.php/Principal Component Analysis
If ~exist (' Train_im_all ', ' var ') | | ~exist (' Train_la_all ', ' var ')% to speed up the program so that you do not need to load the data repeatedly when you run this file repeatedly
Load Train_res; % is still the last handwritten digit recognition data, just before the data has been converted to mat file, so you can load data directly with load
End
X0_te= Train_im_all (:, Train_la_all = = 0); % the data to be processed is singled out separately, note that since the data matrix required by the Svmtrain function is a sample value per row, the transpose
X1_te = Train_im_all (:, Train_la_all = = 1);% Ibid.
X2_te = Train_im_all (:, Train_la_all = = 2);% Ibid.
X3_te = Train_im_all (:, Train_la_all = = 3);% Ibid.
X4_te = Train_im_all (:, Train_la_all = = 4);% Ibid.
X5_te = Train_im_all (:, Train_la_all = = 5);% Ibid.
X6_te = Train_im_all (:, Train_la_all = = 6);% Ibid.
X7_te = Train_im_all (:, Train_la_all = = 7);% Ibid.
X8_te = Train_im_all (:, Train_la_all = = 8);% Ibid.
X9_te = Train_im_all (:, Train_la_all = = 9);% Ibid.
Xte={x0_te,x1_te,x2_te,x3_te,x4_te,x5_te,x6_te,x7_te,x8_te,x9_te};
w={};% array of cells to store the reduced-dimension matrix
For I=1:10
Avg = mean (Xte{i}, 2); % for each image pixel strength mean value
D=avg*ones (1,size (xte{i},2));
Xte{i} = xte{i}-D;% de-homogenization
Sigma = xte{i} * xte{i} '/Size (Xte{i}, 2);% to find Signa value
[U,s,v] = SVD (sigma);
%xrot = U ' * x; % of rotated data
Xtilde = U (:, 1:256) ' * xte{i}; % REDUCED-dimensionality data
W=[w,u (:, 1:256) ']; % Select the first 256 eigenvectors (here you can see how many features are better to choose)
End
And then multiply the original sample onto the transformation matrix.
To be refined, because I changed the implementation of the code there, yesterday directly with the tutorial code, training until midnight has not come out, the correct rate is very low
The results are as follows:
So from now until the end of the semester, I don't have to do pattern recognition, write the papers in 23, 59 minutes.
There are several games to do = =
PCA Descending Dimension algorithm