Code covered by the BSD License  

Highlights from
Multi Class SVM

3.92857
3.9 | 15 ratings Rate this file 301 Downloads (last 30 days) File Size: 1.5 KB File ID: #39352 Version: 1.0

Multi Class SVM

by

Cody (view profile)

  • 1 file
  • 301 downloads
  • 3.92857

 

Model and classify training/test data sets into more than 2 classes with SVM.

| Watch this File

File Information
Description

Support Vector Machines only classify data into two classes. This function removes that restriction by "searching" for the correct class for each row in the test data set.

This code is a clarification and optimization of Anand Mishra's code found here:
http://www.mathworks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine

Use only with more than 2 classes, otherwise use svmtrain() directly.

Usage Example:

%% SVM Multiclass Example
% SVM is inherently one vs one classification.
% This is an example of how to implement multiclassification using the
% one vs all approach.
TrainingSet=[ 1 10;2 20;3 30;4 40;5 50;6 66;3 30;4.1 42];
TestSet=[3 34; 1 14; 2.2 25; 6.2 63];
GroupTrain=[1;1;2;2;3;3;2;2];
results = multisvm(TrainingSet, GroupTrain, TestSet);
disp('multi class problem');
disp(results);

Acknowledgements

Multi Class Support Vector Machine inspired this file.

Required Products Bioinformatics Toolbox
Statistics and Machine Learning Toolbox
MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (44)
02 Jul 2015 A B

A B (view profile)

what do you do to run correctely this code

Comment only
11 Jun 2015 Srinaganya Gopalrathnam

hai,

i am working on query classification using matlab 2013b. i planned to using svm. but there is no svm tool box in matlab 2013b. can u help to add the svm tool for query classification.

Comment only
28 May 2015 Andres Saavedra

He has worked very well, thank you very much

As I can reference the code owner?

can you help me with the reference to call it on my thesis, correctly?

Thanks!

Comment only
28 May 2015 Jack

Jack (view profile)

Thank you for this effective code. But, can you please add an evaluation code for this classification, and how we can get the classification accuracy for that. ( on the same example please) .

Thanks in advance.

Comment only
25 Apr 2015 aqilah chesulaiman

Dear Cody..

i just wanna ask,
how do we modify the holdout sampling coding to be the bootstrap sampling coding. The simplest coding.

12 Mar 2015 Deepa AS

I loaded the training set and my test data set.But it always throws an error saying undefined function or variable GroupTrain.Can anybody please tell me how to overcome this error?

Comment only
26 Feb 2015 sunil ds

Dear Cody, please help me in developing SVM to recognize Handwritten digits from 0 to 9.I tried using multiclass SVM function, but of no use.I'm waiting for your response. In the above program, how to consider values for TrainingSet,TestSet and Group Train. I Have ICDAR13 dataset ,over which i calculated statistical features for over 30 samples for each digits(0 -9).from next i strucked.please give suggestion.

Comment only
16 Dec 2014 Samuel Pedro  
24 Nov 2014 Amruta

Amruta (view profile)

is it GroupTrain vector must be column vector or row vector?
while i am running it for classfication in one program using 'group' as column vector giving me correct answer but for another program it is giving me answer as 1 for all.Then i was tried it for 'group' as row vector it is giving me 6 correct answers out of 10 classes.
Then what to do to get correct classification output?

28 Oct 2014 shayla sharmin

what is your output?? Everytime it is showing 1.. am i not get which group it is belong?? for example your test set value 3 34 is a group of 2 but it is also showing 1 , why?

Comment only
10 Oct 2014 mustafa alnasser

Dear All;

I am trying to use this function for more than three classes , it does not work , in the group train , I have { 1,2,3,4}
could you help me

Comment only
23 Sep 2014 Anwesh

Anwesh (view profile)

Amazing code...I have got the results...how can i give cell aray strings as grouptrain input

Comment only
08 Sep 2014 Shailesh

Hello, I have implemented the code, but getting output as all one only. please help me as soon as possible..

Comment only
07 Aug 2014 Abdullah Masroor Hashmi

@aabiya Group train is the class of the training set.

Comment only
11 Jul 2014 aabiya

aabiya (view profile)

please let me know how to calculate the group train matrix. I have calculated the train and the test set but can't understand group train variable.

Comment only
27 Jun 2014 Amarjot

Amarjot (view profile)

Thanks for the code!

26 Jun 2014 Peter

Peter (view profile)

Thanks for the code. With the latest version of MATLAB (2014a) you don't need the Bioinformatics Toolbox to run the code.

Comment only
29 May 2014 ashok

ashok (view profile)

sir, i think the code will not check for the next class predicted, please check if it is 5 class

Comment only
23 Apr 2014 Borja Heriz

Thank you so much Cody. It has been really helpfull for my current project!!!!!

22 Apr 2014 shah

shah (view profile)

Please cody help me how to put matrix of my image data set in training set,test set and group set ?II am new so no idea!

I do not undersand how to do these steps for my data set
TrainingSet=[ 1 10;2 20;3 30;4 40;5 50;6 66;3 30;4.1 42];
TestSet=[3 34; 1 14; 2.2 25; 6.2 63];
GroupTrain=[1;1;2;2;3;3;2;2];

Comment only
11 Apr 2014 Hamid Ramezani

It seems that the code considered each set of data individually, and not jointly. Do you have any reference for your algorithm? If so, I would be thankful if you share that.

Comment only
11 Feb 2014 Walid

Walid (view profile)

Hi, and thanks for the code. Although I think there is a minor mistake in the code. In the last line, before the "end", the line "result(j) = k;" should be "result(j) = u(k);".

21 Jan 2014 Javed

Javed (view profile)

 
05 Nov 2013 mahdi

mahdi (view profile)

Hi.Thanks for your implementation but I think it is incorrect. When you return 0 or 1 from svmclassify, you maybe have several zeros or ones with different classes!!!
I think you need to compute the real values(before execute sign function) and assign the test data to the class which has the biggest positive ouput.

Comment only
25 Oct 2013 Lulin

Lulin (view profile)

This code can be improved if it can determine a class membership when a test observation belongs to multiple classes.

Comment only
21 Oct 2013 raji

raji (view profile)

thanks for the updated contents!!! very much helpful...

17 Jun 2013 joy barbosa

thank you so much for sharing your code sir Cody. It saved my day!!! 2thumbs up!

Comment only
17 Jun 2013 joy barbosa  
13 Jun 2013 Matthew Klingensmith  
10 Apr 2013 B mohan

I am doing project on facial expression recognition using LBP(Local Binary pattern). i.e finding expressions whetherit is fear, anger, surprise, disguist, happy, joy. First I loaded jaffee database. Then applied preprocessing on it. And the features are extracted using LBP(Local Binary pattern). I don't know how to use multiclass SVM(Support vector Machine). Can this code be useful to my project. What shoud I take input TrainingSet ,GroupTrain,TestSet. Please help me.

Comment only
10 Apr 2013 B mohan

I am doing project on facial expression recognition using LBP(Local Binary pattern). i.e finding expressions whetherit is fear, anger, surprise, disguist, happy, joy. First I loaded jaffee database. Then applied preprocessing on it. And the features are extracted using LBP(Local Binary pattern). I don't know how to use multiclass SVM(Support vector Machine). Can this code be useful to my project. What shoud I take input TrainingSet ,GroupTrain,TestSet. Please help me.

08 Apr 2013 Nimmi

Nimmi (view profile)

Can this be used in model predictive control algorithm.

14 Mar 2013 Subha

Subha (view profile)

Sir is it possible for us to add weights for the feature with this code??? if so how to proceed with it..?

Comment only
16 Feb 2013 Subha

Subha (view profile)

Thank you sir.. now trying out with best possible combination...

Comment only
11 Feb 2013 Cody

Cody (view profile)

  • 1 file
  • 301 downloads
  • 3.92857

If you are getting all 1s, you should try using different options for the svmtrain function. for example:
options = statset('MaxIter',2000000);
models(k) = svmtrain(X_Train,G1vAll,'options',options,...
'kernel_function','rbf','rbf_sigma',16);

Comment only
02 Feb 2013 Subha

Subha (view profile)

sir,
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..

Comment only
27 Jan 2013 Subha

Subha (view profile)

oh.. ok sir.. now its working.. thank a lot...

23 Jan 2013 Cody

Cody (view profile)

  • 1 file
  • 301 downloads
  • 3.92857

Ok, you are not using the function correctly.

load your .mat file, then pass your new variables as parameters to the function.

Comment only
22 Jan 2013 Subha

Subha (view profile)

Sir,
I've loaded data and worked in 2 class problem. its works well...
this is my code.. i've just loaded the data and didnt change anything more.
....
function [result] = multisvm(TrainingSet,GroupTrain,TestSet)
load TrainingSet
load GroupTrain
load TestSet
u=unique(GroupTrain);
numClasses=length(u);
result = zeros(length(TestSet(:,1)),1);

%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k))
models(k) = svmtrain(TrainingSet,G1vAll,'kernel_function','rbf');
end

%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(svmclassify(models(k),TestSet(j,:)))
break;
end
end
result(j) = k;
end

where,
training set is 16*4
test set is 4*4
grouptrain is 16*1
I'm using Matlab (R2010a)

Comment only
21 Jan 2013 Cody

Cody (view profile)

  • 1 file
  • 301 downloads
  • 3.92857

It sounds like you need to learn how to load .mat files. Simply type 'load xxx.mat' where xxx is the file name. You would then need to sample your data into training, test, and label sets for use with this function.

Can you show the code you are using?

Comment only
21 Jan 2013 Subha

Subha (view profile)

Hello Sir,
Thanks for the code.. it works well when we give data... but i'm working with large set of data, where i need to load it(.mat)..
I cant load data, if i do so then it showing error message
??? Undefined function or variable 'GroupTrain'.

Error in ==> neuro_multisuport at 40
u=unique(GroupTrain);
where grouptrain is a column vector(16*1) in .mat format
.. can u please suggest me how to modify the code when i load data...

Comment only
21 Dec 2012 Niyalatul

Hello,
Thanks for your program. I am still new to learn this topic. This is very helpful

Comment only
21 Dec 2012 Niyalatul  
21 Dec 2012 Niyalatul  

Contact us