I am trying to implement one vs rest multiclass classification using LIBSVM.
This link was useful http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/ovr_multiclass/ but i get an error in the function 'ovrpredict()'.
The function is as below:
function [pred, ac, decv] = ovrpredict(y, x, model)
labelSet = model.labelSet;
labelSetSize = length(labelSet);
models = model.models;
decv= zeros(size(y, 1), labelSetSize);
for i=1:labelSetSize
[l,a,d] = svmpredict(double(y == labelSet(i)), x, models{i});
decv(:, i) = d * (2 * models{i}.Label(1) - 1); % ERROR IN THIS LINE
end
[tmp,pred] = max(decv, [], 2);
pred = labelSet(pred);
ac = sum(y==pred) / size(x, 1);
The error message i get is Reference to non-existent field 'Label'
.
Any suggestions will be really helpful.
EDIT 1
The code used to call the functions:\
[trainY trainX]=libsvmread('libfacecombine.train');
[testY testX]=libsvmread('libfacetest.train');
model=ovrtrain(trainY,trainX,'-c 8 -g 4');
[~,accuracy,~]=ovrpredict(testY,testX,model);
The training and testing data viz 'libfacecombine.train' and 'libfacetest.train' is written obtained from .csv files:
f1=createdabase(f); % where createdatabase is a function to read various images from a folder and arrange into 1D array
[sig1 mn1]=pcam(f1); % where pcam is a function to find 'pca'(sig1) and 'mean'(mn1) of the data
%labelling is done this way:
%Positive class
label=[];
for i=1:length(sig1)
for j=1:1
label(i,j)=+1;
end
end
csvwrite('face1.csv',[label sig1]);
%Negative class
label1=[];
for i=1:length(sig2) % sig2 obtained in same way as sig1
for j=1:1
label1(i,j)=-1;
end
end
csvwrite('face2.csv',[label sig2]);
Using "append" mode both these files are joined and converted to .train files. Same thing is done for the testing data.
EDIT 2
I have 5 classes. And labeling is done as: Class 1: +1 contains features from 4 images of Face 1 and -1 contains features from 4 images of not Face 1(faces 2,3,4 and 5). Class 2: +2 contains features from 4 images of Face 2 and -2 contains features from 4 images of not Face 2(faces 1,3,4 and 5).... Class 5: +5 contains features from 4 images of Face 5 and -5 contains features from 4 images of not Face 5(faces 1,2,3 and 4). All these features along with the labels are written in the above given order to .csv files and then converted to .train format. Hence i obtain the training file.
For the test image i take one image of face 1 and give its true label i.e +1 and written into .csv file and then converted to .train. Hence i obtain the testing file. When i run the program i obtain results such as:
Accuracy=92%(12/13)classification;
Accuracy=61%(8/13)classification;
Accuracy=100%(13/13)classification;
Accuracy=100%(13/13)classification;
Accuracy=100%(13/13)classification;
Accuracy=100%(13/13)classification;
Why am i obtaining 6 accuracy values when i have only 5 classes?