www.pudn.com > snippets(1).rar > learn_classification_ova.m, change:2009-10-12,size:633b


function classifier = learn_classification_ova(data, classes, Globals)
%
% train an OVA-SVM for each class to classify the data

data = data';
classes = classes';
numclasses = length(unique(classes));
[m,n] = size(data);

classifier = cell(numclasses,1);

for u = 1:numclasses

  if Globals.DISPLAY, fprintf('.'); end

  % convert to two-class data (one vs. all)
  curr_classes = double(classes==u);
  curr_classes(curr_classes<1) = -1;

  % now, train classifier
  curr_classifier = svm(n, Globals.svm_kernel, Globals.svm_kernelpar, Globals.svm_maxweight(u,:));
  classifier{u} = svmtrain(curr_classifier, data, curr_classes);

end