MATLAB Examples

Multi-Class SVM

Contents

Demo Begin

Initialize all to default

clc
clear all
close all

number of samples and Class initialization

nOfSamples=100;
nOfClassInstance=10;
Sample=rand(nOfSamples,60);
class=round(rand(nOfSamples,1)*(nOfClassInstance-1));

SVM Classification

Model=svm.train(Sample,class);
predict=svm.predict(Model,Sample);
% [Model,predict] = svm.classify(Sample,class,Sample);
disp('class predict')
disp([class predict])
Multi Class SVM Model for Class Instance 0 --->
          SupportVectors: [23x60 double]
                   Alpha: [23x1 double]
                    Bias: -1.4875
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [23x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 1 --->
          SupportVectors: [33x60 double]
                   Alpha: [33x1 double]
                    Bias: -2.0619
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [33x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 2 --->
          SupportVectors: [41x60 double]
                   Alpha: [41x1 double]
                    Bias: -2.0265
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [41x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 3 --->
          SupportVectors: [44x60 double]
                   Alpha: [44x1 double]
                    Bias: -2.0773
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [44x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 4 --->
          SupportVectors: [42x60 double]
                   Alpha: [42x1 double]
                    Bias: -1.7984
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [42x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 5 --->
          SupportVectors: [36x60 double]
                   Alpha: [36x1 double]
                    Bias: -1.8401
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [36x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 6 --->
          SupportVectors: [25x60 double]
                   Alpha: [25x1 double]
                    Bias: -1.5757
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [25x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 7 --->
          SupportVectors: [43x60 double]
                   Alpha: [43x1 double]
                    Bias: -1.9318
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [43x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 8 --->
          SupportVectors: [42x60 double]
                   Alpha: [42x1 double]
                    Bias: -1.5907
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [42x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []

Multi Class SVM Model for Class Instance 9 --->
          SupportVectors: [31x60 double]
                   Alpha: [31x1 double]
                    Bias: -1.7759
          KernelFunction: @linear_kernel
      KernelFunctionArgs: {}
              GroupNames: [100x1 double]
    SupportVectorIndices: [31x1 double]
               ScaleData: [1x1 struct]
           FigureHandles: []


Train Model Completed

Multi Class SVM classify values Claculated  for Class Instance 0 
Multi Class SVM classify values Claculated  for Class Instance 1 
Multi Class SVM classify values Claculated  for Class Instance 2 
Multi Class SVM classify values Claculated  for Class Instance 3 
Multi Class SVM classify values Claculated  for Class Instance 4 
Multi Class SVM classify values Claculated  for Class Instance 5 
Multi Class SVM classify values Claculated  for Class Instance 6 
Multi Class SVM classify values Claculated  for Class Instance 7 
Multi Class SVM classify values Claculated  for Class Instance 8 
Multi Class SVM classify values Claculated  for Class Instance 9 
 SVM Classification is completed
class predict
     3     3
     2     2
     3     3
     7     7
     4     4
     1     1
     1     1
     8     8
     8     8
     3     3
     4     4
     3     3
     5     5
     7     7
     7     7
     6     6
     1     1
     2     2
     2     2
     0     0
     3     3
     8     8
     1     1
     8     8
     2     2
     3     3
     3     3
     0     0
     6     6
     3     3
     1     1
     6     6
     8     8
     9     9
     2     2
     2     2
     5     5
     3     3
     5     5
     7     7
     5     5
     8     8
     3     3
     3     3
     7     7
     2     2
     8     8
     4     4
     2     2
     2     2
     7     7
     6     6
     4     4
     8     8
     9     9
     9     9
     3     3
     2     2
     3     3
     7     7
     7     7
     8     8
     8     8
     2     2
     4     4
     1     1
     8     8
     3     3
     6     6
     7     7
     3     3
     4     4
     5     5
     5     5
     4     4
     5     5
     4     4
     9     9
     8     8
     5     5
     7     7
     4     4
     0     0
     5     5
     5     5
     2     2
     3     3
     7     7
     1     1
     4     4
     3     3
     1     1
     1     1
     4     4
     4     4
     2     2
     7     7
     9     9
     7     7
     8     8

Find Accuracy

Accuracy=mean(class==predict)*100;
fprintf('\nAccuracy =%d\n',Accuracy)
Accuracy =100