MATLAB Examples

function svm_call

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Name - svm_call
% Creation Date - 2nd Dec 2014
% Author - Soumya Banerjee
% Website - https://sites.google.com/site/neelsoumya/
%
%
% Description - Function to call SVM using example data (binary classifer)
%
%
% License - BSD
%
% Change History -
%                   2nd Dec 2014   - Creation by Soumya Banerjee
%                   30th June 2017 - Modified by Soumya Banerjee generic
%                                       kernel
%                   3rd July 2017 -  Modified by Soumya Banerjee generic
%                                       one class label
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

meas_1 = [10          9           10.5        8.7         7.1         9           8.5         9.3         12           3          2.1       3.4        4.5        5          1.7      2.2        4           ]';
meas_2 = [log10(0.03) log10(0.05) log10(0.09) log10(0.07) log10(0.15) log10(0.04) log10(0.07) log10(0.12) log10(0.06)  log10(3)   log10(2)  log10(2.2) log10(1.9) log10(1.9) log10(2) log10(2.9) log10(3.2)  ]';
label = [ 'P '; 'P '; 'P '; 'P '; 'P '; 'P '; 'P '; 'P '; 'P ';    'NP'; 'NP'; 'NP'; 'NP'; 'NP'; 'NP'; 'NP'; 'NP';]
one_label = 'NP'

kernel_function = 'linear'
svm_classifier(meas_1,meas_2,label,one_label,kernel_function)

kernel_function = 'rbf'
svm_classifier(meas_1,meas_2,label,one_label,kernel_function)
label =

P 
P 
P 
P 
P 
P 
P 
P 
P 
NP
NP
NP
NP
NP
NP
NP
NP


one_label =

NP


kernel_function =

linear


groups =

  17×1 logical array

   0
   0
   0
   0
   0
   0
   0
   0
   0
   1
   1
   1
   1
   1
   1
   1
   1


ans =

     1

Elapsed time is 0.304356 seconds.

ans = 

  struct with fields:

          SupportVectors: [2×2 double]
                   Alpha: [2×1 double]
                    Bias: 0.2202
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [9×1 logical]
    SupportVectorIndices: [2×1 double]
               ScaleData: [1×1 struct]
           FigureHandles: {[1×1 Axes]  [1×2 Line]  [1×1 Line]}


kernel_function =

rbf


groups =

  17×1 logical array

   0
   0
   0
   0
   0
   0
   0
   0
   0
   1
   1
   1
   1
   1
   1
   1
   1


ans =

     1

Elapsed time is 0.222759 seconds.

ans = 

  struct with fields:

          SupportVectors: [5×2 double]
                   Alpha: [5×1 double]
                    Bias: -0.0388
          KernelFunction: @rbf_kernel
      KernelFunctionArgs: {}
              GroupNames: [9×1 logical]
    SupportVectorIndices: [5×1 double]
               ScaleData: [1×1 struct]
           FigureHandles: {[1×1 Axes]  [1×2 Line]  [1×1 Line]}