Libsvm: SVM assessment using exit permissions

I am trying to use libsvm with MATLAB to evaluate one-vs-all SVM, the only problem is that my dataset is not large enough to guarantee the selection of a specific test suite. Thus, I want to evaluate my classifiers using the leave-one-out method.

I'm not particularly good at using SVM, so forgive me if I'm a little confused about what to do. I need to generate accuracy against recall curves and a mixing matrix for my classifiers, but I don't know where to start.

I let him go and came up with the following as a rough start to finish the vacation, but I'm not sure how to make an assessment.

function model = do_leave_one_out(labels, data)
             acc = [];
             bestC = [];
             bestG = [];
             for ii = 1:length(data)
                  % Training data for this iteration
                  trainData = data;
                  trainData(ii) = [];
                  looLabel = labels(ii);
                  trainLabels = labels;
                  trainLabels(ii) = [];

                  % Do grid search to find the best parameters?

                  acc(ii) = bestReportedAccuracy;
                  bestC(ii) = bestValueForC;
                  bestG(ii) = bestValueForG;
             end
             % After this I am not sure how to train and evaluate the final model
end
+1
source share
1 answer

, , . , .

:

scrambledList = randperm(totalNumberOfData);
trainingData = Data(scrambledList(1:end-1),:);
trainingLabel = Label(scrambledList(1:end-1));
testData = Data(scrambledList(end),:);
testLabel = Label(scrambledList(end));

( ):

acc = 0;
for log2c = -1:3,
  for log2g = -4:1,
    cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
    cv = svmtrain(trainingLabel, trainingData, cmd);
    if (cv >= acc),
      acc = cv; bestC = 2^log2c; bestG = 2^log2g;
    end    
  end
end

One-vs-all ( ):

model = cell(NumofClass,1);
for k = 1:NumofClass
    model{k} = svmtrain(double(trainingLabel==k), trainingData, '-c 1 -g 0.2 -b 1');
end

%% calculate the probability of different labels

pr = zeros(1,NumofClass);
for k = 1:NumofClass
    [~,~,p] = svmpredict(double(testLabel==k), testData, model{k}, '-b 1');
    pr(:,k) = p(:,model{k}.Label==1);    %# probability of class==k
end

%% your label prediction will be the one with highest probability:

[~,predctedLabel] = max(pr,[],2);
+4

All Articles