Code covered by the BSD License  

Highlights from
Geometric Gaussian-Kernel Bolstered Error Estimation for Linear Classification

image thumbnail

Geometric Gaussian-Kernel Bolstered Error Estimation for Linear Classification

by

 

This is fast implementation of bolstered error estimation algorithm for linear SVM classification.

svm(P,T,flag)
function [err, SVMStruct] = svm(P,T,flag)
% Train linear support vector machine classification
% P  - training data m-by-n matrix, m - number of objects, n - number of
% features
% T - m-by-1 vector of class labels 
% flag - 'resub' - calculate resubstitution error, 'cross' - calculate LOO
% error
% Output:
% err - classification error
% SVMstruct- contains information about the trained support vector machine
               
if strcmp(flag,'resub')
    SVMStruct = svmtrain(P, T,'Autoscale', 'off');
    Tpred = svmclassify(SVMStruct,P);
    err = sum(abs(T-Tpred))/length(T);
elseif strcmp(flag,'cross')
    indices = crossvalind('Kfold',T',length(T));
    cp = classperf(T');
    for i = 1:length(indices)
        test = (indices == i); train = ~test;
        SVMStruct = svmtrain(P(train,:), T(train,:),'Autoscale', 'off');
        classes = svmclassify(SVMStruct,P(test,:));
        classperf(cp,classes,test);
    end
    err = cp.ErrorRate;
end

Contact us