标签:
http://ufldl.stanford.edu/wiki/index.php/主成分分析
if ~exist(‘train_IM_all‘,‘var‘)||~exist(‘train_LA_all‘,‘var‘)%为加快程序运行,以便重复运行本文件时不需要重复载入数据
load train_res; %用的还是上次手写数字识别的数据,只是在此之前已经将数据转换为mat文件,所以可以直接用load载入数据
end
X0_te= train_IM_all(:,train_LA_all == 0); %将要处理的数据单独挑出来,注意由于svmtrain函数需要的数据矩阵是每一行存储一个样本值各特征,所以此处要用转置
X1_te = train_IM_all(:,train_LA_all == 1);%同上
X2_te = train_IM_all(:,train_LA_all == 2);%同上
X3_te = train_IM_all(:,train_LA_all == 3);%同上
X4_te = train_IM_all(:,train_LA_all == 4);%同上
X5_te = train_IM_all(:,train_LA_all == 5);%同上
X6_te = train_IM_all(:,train_LA_all == 6);%同上
X7_te = train_IM_all(:,train_LA_all == 7);%同上
X8_te = train_IM_all(:,train_LA_all == 8);%同上
X9_te = train_IM_all(:,train_LA_all == 9);%同上
Xte={X0_te,X1_te,X2_te,X3_te,X4_te,X5_te,X6_te,X7_te,X8_te,X9_te};
w={};%元胞数组以便存储降维矩阵
for i=1:10
avg = mean(Xte{i}, 2); %求每个图像像素强度均值
d=avg*ones(1,size(Xte{i},2));
Xte{i} = Xte{i} -d ;%去均值化
sigma = Xte{i} * Xte{i}‘ / size(Xte{i}, 2);%求出signa值
[U,S,V] = svd(sigma);
%xRot = U‘ * x; % 旋转的数据
xTilde = U(:,1:256)‘ * Xte{i}; % 降维后的数据
w=[w,U(:,1:256)‘]; %选取前256个特征向量(这里可以看多少特征更好来选取)
end
然后把原来的样本乘上转化矩阵就好了
有待考究,因为我改了那里的实现代码,昨天直接用那个教程代码,训练到半夜还没出来,正确率很低
结果如下:
所以从现在到期末为止,我不用再做模式识别啦,在23,59分之前把论文写好交了
还有几个游戏要做= =
标签:
原文地址:http://www.cnblogs.com/lqs-zsjky/p/4190871.html