You are on page 1of 2

3/22/13

Multi Class SVM - File Exchange - MATLAB Central


Search:

File Exchange
Create Account

File Exchange

Answ ers

New sgroup

Link Exchange

Blogs

Trendy

Cody

Contest

MathWorks.com

Dow nload Submission

Multi Class SVM


3.5 | 3 ratings

by Cody
07 Dec 2012

Code covered by the BSD License

Rate this file

Model and classify training/test data sets into more than 2


classes w ith SVM.

200 Dow nloads (last 30 days)


File Size: 1.5 KB
File ID: #39352

Log In

Watch this File

Highlights from

Multi Class SVM


multisvm(TrainingSet,GroupTra...
Models a given training set w ith a
corresponding group vector and
View all files

File Inform ation


Description Support Vector Machines only classify data into tw o 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://w w w .mathw orks.com/matlabcentral/fileexchange/33170-multi-class-support-vector-machine
Use only w ith more than 2 classes, otherw ise 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);
Acknow ledgem ents The author w ishes to acknow ledge the follow ing in the creation of this submission:
Multi Class Support Vector Machine
Required Products Bioinformatics Toolbox
Statistics Toolbox
MATLAB
MATLAB release MATLAB 7.14 (R2012a)

Tags for This File


Everyone's Tags multiclass, multiclass svm(2), support vector machine(2), svm
Tags I've Applied
Add New Tags Please login to tag files.

Com m ents and Ratings (12)


14 Mar 2013

Subha

Sir is it possible for us to add w eights for the feature w ith this
code??? if so how to proceed w ith it..?

16 Feb 2013

Subha

Thank you sir.. now trying out w ith best possible combination...

11 Feb 2013

Cody

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);

02 Feb 2013

Subha

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

27 Jan 2013

Subha

oh.. ok sir.. now its w orking.. thank a lot...

23 Jan 2013

Cody

Ok, you are not using the function correctly.


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

22 Jan 2013

Subha

Sir,
I've loaded data and w orked in 2 class problem. its w orks w ell...
this is my code.. i've just loaded the data and didnt change anything

https://www.mathworks.com/matlabcentral/fileexchange/39352-multi-class-svm

1/2

3/22/13

Multi Class SVM - File Exchange - MATLAB Central


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
%w here 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
w here,
training set is 16*4
test set is 4*4
grouptrain is 16*1
I'm using Matlab (R2010a)
21 Jan 2013

Cody

It sounds like you need to learn how to load .mat files. Simply type
'load xxx.mat' w here xxx is the file name. You w ould then need to
sample your data into training, test, and label sets for use w ith this
function.
Can you show the code you are using?

21 Jan 2013

Subha

Hello Sir,
Thanks for the code.. it w orks w ell w hen w e give data... but i'm
w orking w ith large set of data, w here i need to load it(.mat)..
I cant load data, if i do so then it show ing error message
??? Undefined function or variable 'GroupTrain'.
Error in ==> neuro_multisuport at 40
u=unique(GroupTrain);
w here grouptrain is a column vector(16*1) in .mat format
.. can u please suggest me how to modify the code w hen i load data...

21 Dec 2012

Niyalatul

21 Dec 2012

Niyalatul

21 Dec 2012

Niyalatul

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

Please login to add a comment or rating.

Tag Activity for this File


Tag

Applied By

Date/Time

svm

Cody

07 Dec 2012 19:58:49

multiclass svm

Cody

07 Dec 2012 19:58:50

support vector machine

Cody

07 Dec 2012 19:58:50

multiclass

Cody

07 Dec 2012 19:58:50

multiclass svm

hum

12 Mar 2013 15:48:14

support vector machine

hum

12 Mar 2013 15:48:19

Contact us

Site Help

1994-2013 The MathWorks, Inc.


Featured MathWorks.com Topics:

New Products

https://www.mathworks.com/matlabcentral/fileexchange/39352-multi-class-svm

Patents
Support

Trademarks

Privacy Policy

Documentation

Training

Preventing Piracy
Webinars

Terms of Use

Newsletters

MATLAB Trials

Careers

2/2

You might also like