How to do multi class classification using Support Vector Machines (SVM)

后端 未结 8 1964
孤独总比滥情好
孤独总比滥情好 2021-01-30 16:08

In every book and example always they show only binary classification (two classes) and new vector can belong to any one class.

Here the problem is I have 4 classes(c1,

相关标签:
8条回答
  • 2021-01-30 16:32

    You can always reduce a multi-class classification problem to a binary problem by choosing random partititions of the set of classes, recursively. This is not necessarily any less effective or efficient than learning all at once, since the sub-learning problems require less examples since the partitioning problem is smaller. (It may require at most a constant order time more, e.g. twice as long). It may also lead to more accurate learning.

    I'm not necessarily recommending this, but it is one answer to your question, and is a general technique that can be applied to any binary learning algorithm.

    0 讨论(0)
  • 2021-01-30 16:39

    It does not have a specific switch (command) for multi-class prediction. it automatically handles multi-class prediction if your training dataset contains more than two classes.

    0 讨论(0)
  • 2021-01-30 16:43

    Use the SVM Multiclass library. Find it at the SVM page by Thorsten Joachims

    0 讨论(0)
  • 2021-01-30 16:44
    data=load('E:\dataset\scene_categories\all_dataset.mat');
        meas = data.all_dataset;
        species = data.dataset_label;
        [g gn] = grp2idx(species);                      %# nominal class to numeric
    
    %# split training/testing sets
    [trainIdx testIdx] = crossvalind('HoldOut', species, 1/10);
    %# 1-vs-1 pairwise models
    num_labels = length(gn);
    clear gn;
    num_classifiers = num_labels*(num_labels-1)/2;
    pairwise = zeros(num_classifiers ,2);
    row_end = 0;
    for i=1:num_labels - 1
        row_start = row_end + 1;
        row_end = row_start + num_labels - i -1;
        pairwise(row_start : row_end, 1) = i;
        count = 0;
        for j = i+1 : num_labels        
            pairwise( row_start + count , 2) = j;
            count = count + 1;
        end    
    end
    clear row_start row_end count i j num_labels num_classifiers;
    svmModel = cell(size(pairwise,1),1);            %# store binary-classifers
    predTest = zeros(sum(testIdx),numel(svmModel)); %# store binary predictions
    
    %# classify using one-against-one approach, SVM with 3rd degree poly kernel
    for k=1:numel(svmModel)
        %# get only training instances belonging to this pair
        idx = trainIdx & any( bsxfun(@eq, g, pairwise(k,:)) , 2 );
    
        %# train
        svmModel{k} = svmtrain(meas(idx,:), g(idx), ...
                     'Autoscale',true, 'Showplot',false, 'Method','QP', ...
                     'BoxConstraint',2e-1, 'Kernel_Function','rbf', 'RBF_Sigma',1);
    
        %# test
        predTest(:,k) = svmclassify(svmModel{k}, meas(testIdx,:));
    end
    pred = mode(predTest,2);   %# voting: clasify as the class receiving most votes
    
    %# performance
    cmat = confusionmat(g(testIdx),pred);
    acc = 100*sum(diag(cmat))./sum(cmat(:));
    fprintf('SVM (1-against-1):\naccuracy = %.2f%%\n', acc);
    fprintf('Confusion Matrix:\n'), disp(cmat)
    
    0 讨论(0)
  • 2021-01-30 16:45

    Commonly used methods are One vs. Rest and One vs. One. In the first method you get n classifiers and the resulting class will have the highest score. In the second method the resulting class is obtained by majority votes of all classifiers.

    AFAIR, libsvm supports both strategies of multiclass classification.

    0 讨论(0)
  • 2021-01-30 16:51

    LibSVM uses the one-against-one approach for multi-class learning problems. From the FAQ:

    Q: What method does libsvm use for multi-class SVM ? Why don't you use the "1-against-the rest" method ?

    It is one-against-one. We chose it after doing the following comparison: C.-W. Hsu and C.-J. Lin. A comparison of methods for multi-class support vector machines, IEEE Transactions on Neural Networks, 13(2002), 415-425.

    "1-against-the rest" is a good method whose performance is comparable to "1-against-1." We do the latter simply because its training time is shorter.

    0 讨论(0)
提交回复
热议问题