Code covered by the BSD License  

Highlights from
Multi Class Support Vector Machine


3.6 | 12 ratings Rate this file 285 Downloads (last 30 days) File Size: 2.17 KB File ID: #33170
image thumbnail

Multi Class Support Vector Machine



07 Oct 2011 (Updated )

This function removes out the limitation of MATLAB SVM function of two class and uses more classes.

| Watch this File

File Information

This function can classify more than two classes which is limited in MATLAB SVM. This is primary work and does not include plotting function for SVM.
This is version 3.0 of original function which removes some limitations of first & Second one.


This file inspired Multi Class Svm.

Required Products Bioinformatics Toolbox
MATLAB release MATLAB 7.12 (R2011a)
Other requirements Bioinformatics Toolbox only.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
04 Nov 2014 shila

Hello sir. i have used this function. i have to classify 3 classes. but its not getting expected result.. its shows only one class its unable to group rest two classes.. whts the problme?

27 Oct 2014 jie

Could you please tell me the reference of your aglorithm? Thanks a lot.

24 Sep 2014 mustafa alnasser

I am using neural network for classification of four classes and I am trying to use SVM to do the same analysis but I do not how to reflect 4 input vectors on the three sets (group, test.)

28 May 2014 Ansuman Mahapatra  
16 Jan 2014 raha

i am new in svm
i wonder how calculate accuracy in this algorithm
plz help me

01 Oct 2013 Weizhi Li

Error using seqminopt>seqminoptImpl (line 198)
No convergence achieved within maximum number of iterations.

Error in seqminopt (line 81)
[alphas offset] = seqminoptImpl(data, targetLabels, ...

Error in svmtrain (line 499)
[alpha, bias] = seqminopt(training, groupIndex, ...

Error in multisvm (line 20)
models(k) = svmtrain(TrainingSet,G1vAll);

I think it does not work

12 May 2013 billel madridi

hey ; why i can't see the file could you send it to me to( )
please i really need it it's emergency

24 Apr 2013 Aya

please i need to know it's one vs all or one vs one relation??

13 Apr 2013 jamila

thank you for this code, it great ; but i have an error when i try to change the kernel function. The error is " Error using ==> seqminopt>seqminoptImpl at 203
No convergence achieved within maximum number of iterations.

Error in ==> seqminopt at 84
[alphas offset] = seqminoptImpl(data, targetLabels, ...

Error in ==> svmtrain at 541
[alpha bias] = seqminopt(training, groupIndex, ...

Error in ==> multisvm at 49
svmStruct = svmtrain(T,newClass,'kernel_function','linear' ); %
I am using rbf kernel function, you must change it also

Error in ==> teststa at 61
[itrfin] = multisvm( data,classa,test )"

can you help me please?

06 Feb 2013 Subha

is it possible to plot confusion matrix for this program... if so how to do tat.. we have tried many combinations but does not working...
else any method to calculate the performance of the overall system from test data's..

11 Jan 2013 Mehrdad Azh


Could you please upload a test case for us to see how to use it?


11 Jan 2013 Mehrdad Azh


Could you please upload a test case for us to see how to use it?


21 Dec 2012 Niyalatul

I'm still new to learn this topic.
How can I learn multiclass svm more specific (literature suggestions that I can use, like the books and other)?


08 Dec 2012 Cody

Please see my revision of this code here:

07 Dec 2012 Cody

Hello, thanks for your contribution. It helped me out, but it was confusing and I have re-written and uploaded a clearer function that does the same thing. It is only about 15 lines of code. I'll provide a link when it is approved.

07 Dec 2012 Cody  
08 Nov 2012 yavuzca23

does this code work with 6 inputs which include 3200 samples , and 30 classes(outputs)?

14 Aug 2012 M@lik Ali

Can any one tel me how i can run this program, please i am new in mat-lab.
what and how to give input to the function,
i have a feature vector of the images how i can use it.

13 Jul 2012 Anirban

Hey Anand

Thank for sharing 'multisvm' code, its really useful! But can you tell is there any way to get the learned models so that while testing for next time I dot need to train again. Because training in every test step is pretty time consuming.

Thanks in advance for your suggestion

26 Jun 2012 MML

thanks a lot Anand for sharing your code.
I found it very useful.

@Chaou and @Yap
The class-vector (C) should be a row vector. I had the same problem when I tried to use a column vector for C. I hope this resolves the problem.

29 May 2012 Yap

me too, my result output all 1 1 1 1.....I hope some1 could help!

27 May 2012 Chaou

Hello, I'd like first to thank you for this program. But unfortunately, it doesn't work in my case.
I'm obtaining a itrfin=1 in all cases. I'm using a test vector of 30 elements, and I obtain a itrfin vector = 1 1 1 1.... 1.

Why ? I really appreciate your help. Thanks !

20 Apr 2012 Shikha  
12 Apr 2012 LEONG

I am searching a way of plotting the multi-svm.

Description about my project:
My application is actually is to classify 4 four classes of different input signals. i have three trial for each subject which each of them need to four different of movement..

Here is my some questions:

1. Does multi-svm that Anand provided able to plot the graph?
2. If yes, how to plot it ..i mean the algorithm..
3. beside, i want to know whether the multi-svm support for classperf ? because i test it before.. it come out with error as:

??? Error using ==> classperf at
The classifier output CLASSOUT
does not have the same size
as the ground truth and there was
not any TESTIDX provided.

Error in ==>
multisvm_classification2 at 63

4. What does that mean..i got find the error at internet but the the problem still did'nt solve..
any solution for it ?

5. Can i use more than two training data but with one test in multi-svm version 2.0 or 3.0 ?can i use it to obtain classperformance of multi-training and test for many data?

Your suggestion will be appreciated..
thank you

05 Apr 2012 kamil kamil

Thank you for this program.
How we can determine the best (Sigma, C) with this method ?

04 Apr 2012 Anand Mishra

Download Version 3.0 of this function and give suggestions for improving it. Version 3.0 includes the usage of multiple row testing matrix input.

04 Apr 2012 Anand Mishra

Sorry for late reply, but I was little bit busy.
You can use '|' instead of '||' or '&' instead of '&&' in function,hope this will work for your application. You can refer Operators and Flow Control in Matlab for more information.
Thank You for taking help.

04 Apr 2012 Anand Mishra

@Gomathi C,
Sorry for late reply, but I was little bit busy.
By the way you don't have to worry about using this function for two class SVM. You can not use this function for two classes, because their is an inbuilt MATLAB function for two classes classification present in MATLAB IDE. I created this function to extend the facilities of inbuilt MATLAB function.
I am not able to understand your output of GLCM but you can look image associated with my file in MATLAB file exchange for example of using my SVM function.
If you still find any problem in using your inputs for your program then please clarify me whole parameters you are using for GLCM like autoc, contr etc. So that I am able to tell you more clearly.
Hope this will help you.
Thanks for using my function.

22 Mar 2012 Gomathi C

I actually obtained the texture features using GLCM. My output for that was

stats =

autoc: [1.857855266614132e+000 1.857955341199538e+000]
contr: [5.103143332457753e-002 5.030548650257343e-002]
corrm: [9.512661919561399e-001 9.519459060378332e-001]
corrp: [9.512661919561385e-001 9.519459060378338e-001]
cprom: [7.885631654779597e+001 7.905268525471267e+001]

Now how should I give this as an input to the SVM program. Kindly guide me.

16 Feb 2012 pallavi

when I run the program , I fet an error:
??? Operands to the || and && operators must be convertible to logical scalar values.
how to solve it?

14 Oct 2011 Anand Mishra

Hi, you correctly spotted the algorithm behind this file.
Now take an example,
T=[1 2 3 4;2 3 4 5;3 4 5 6;4 5 6 7]
C=[1 2 3 4]
tst=[3 4 5 6]
then run the function and then debug it step by step to understand algorithm.
It becomes clearer how the class is calculated.
Thanks for your interest.

13 Oct 2011 guo

Hi again. I wonder how you solve an multi-class problem. It is likely that you decompose an M-class problem into a series of two-class problems using one-against-all implementation, right?

13 Oct 2011 guo

Helloļ¼Could you please give a detailed example for input parameter specification?

11 Oct 2011 Anand Mishra

Dear Aziz, svmclassify never makes 'classes' variable as a row vector of 0 and 1. The 'classes' can used only for checking loop condition i.e.,whether loop is to be terminate or not (check in while condition).
Variables 'newClass' and 'c1' can takes form of vector(0 and 1) and changing their sizes in each iteration.

I am using operands || and && because I am working on C Programming also so I am habitual of using this instead of logical scalar values.

May this solve out your confusions. Read Comments on file thoroughly. Thanks for taking help.
Regards...Anand Mishra.

10 Oct 2011 Aziz

This is great but I wonder what purpose the 'classes' variable serve? At first it looks like an indicator to keep looping if the 'classes' variable still not equal 1 (line 32, line 65-67) but then you use it as result from svmclassify (line 39), which will make it a row vector of 0 and 1. Hence it couldn't be used in loop indicators. It would make this appear

??? Operands to the || and && operators must be convertible to logical scalar values.

Am I missing something?

14 Oct 2011

This is Version 2.0 of Original Function.

04 Apr 2012

This is the update version 3.0 of original created Multi-Class SVM function by me.

04 Apr 2012

This is version 3.0 of original function.

Contact us