[英]Why is the accuracy coming as 0% ? MATLAB LIBSVM
我使用以下方法提取PCA功能:
function [mn,A1,A2,Eigenfaces] = pca(T,f1,nf1)
m=mean(T,2), %T is the whole training set
train=size(T,2);
A=[];
for i=1:train
temp=double(T(:,i))-m;
A=[A temp];
end
train=size(f1,2); %f1 - Face 1 images from training set 'T'
A=[];
for i=1:train
temp=double(f1(:,i))-m;
A1=[A1 temp];
end
train=size(nf1,2); %nf1 - Images other than face 1 from training set 'T'
A=[];
for i=1:train
temp=double(nf1(:,i))-m;
A2=[A2 temp];
end
L=A'*A;
[V D]=eig(L);
for i=1:size(V,2)
if(D(i,i)>1)
L_eig=[L_eig V(:,1)];
end
end
Eigenfaces=A*L_eig;
end
然后我只從訓練數據中投射出面部1(+1級):
功能1
for i=1:15 %number of images of face 1 in training set
temp=Eigenfaces'*A1(:,i);
proj_img1=[proj_img1 temp];
end
然后我從訓練數據中投射出其余的面(-1級):
功能2
for i=1:221 %number of images of faces other than face 1 in training set
temp=Eigenfaces'*A2(:,i);
proj_img2=[proj_img2 temp];
end
功能3然后使用以下方法獲得輸入圖像矢量:
diff=double(inputimg)-mn; %mn is the mean of training data
testfeaturevector=Eigenfaces'*diff;
我將功能1和2的結果寫在CSV文件中,標簽分別為+1和-1。 然后我使用LIBSVM來獲得真實標簽時的准確度,它返回0%,當我試圖預測標簽時它是-1而不是+1。
准確度為0%?
基本上我的模型沒有正確訓練,我沒有看到錯誤。
任何建議將不勝感激。
使用Eigenfaces
作為訓練集,用1或-1組成label
向量(如果Eigenfaces
的第i列引用1,則label
的第i個元素為1,否則為-1)。 並在svmtrain
函數中使用Eigenfaces
和label
。
@ lennon310:
for i=1:length(Eigenfaces)
temp=Eigenfaces'*A(:,i);
proj_imgs=[proj_imgs temp];
end
@ lennon310:
diff=double(inputimg)-mn; %mn is the mean of training data
testfeaturevector=Eigenfaces'*diff;
@lennon310:
temp=double(testimg)-m; %where 'm' is the mean of the training images
L=temp'*temp;
[V D]=eig(L);
for i=1:size(V,2)
if(D(i,i)>1)
L_eig=[L_eig V(:,1)];
end
end
Eigenfaces=temp*L_eig;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.