Creating a wrapper using support vector machines

Can anyone tell me how to implement a wrapper with Support vector machines.I've been trying to use the following code snippet for the purpose but it is always returning me one feature(which is the first one in case of forward selection and last one in case of sequential backward selection. Can anyone explain why this is happening or give some other example as a demo to explain the feature selection process by using SVM. I have tried a different database as well but encountered the same problem..Many thanks in advance!
%%FISHERIRIS DATA
load fisheriris
X = randn(150,20);
X(:,1:4)= meas(:,:);
y = species(1:150,:);
groups = ismember(species,'setosa');
y= groups(:,:)
X= scaleData(X); % to scale data in range [0,1]
%%CROSS VALIDATING
cc = cvpartition(y,'k',10);
%%SVM TRAINING AND TESTING FOR FEATURE %%SELECTION
opts = statset('display','iter');
OPTIONS=optimset('MaxIter',1000);
fun = @(Xtrain,Ytrain,Xtest,Ytest)...
(sum(~strcmp(Ytest,svmclassify(svmtrain(Xtrain,Ytrain),Xtest))))
[fs,history] = sequentialfs(fun,X,y,'cv',cc,'options',opts,'nfeatures',3)
%%END OF CODE

3 Kommentare

Barry Greene
Barry Greene am 19 Jan. 2012
Your function scaleData is not shared however you don't need to do this step as the matlab SVMfunction will do this by default. This may be causing sequentialfs to stop at the first local minima (1st feature encountered). Also the maxiter value given is far too low compared to default value.
I am having a similar problem, but with regression, not classification. The script started giving some meaningful results after I removed '~' from the part: 'fun = @(Xtrain,Ytrain,Xtest,Ytest)... (sum(~strcmp(Ytest,svmclassify(svmtrain(Xtrain,Ytrain),Xtest))))'. But since I don't exactly understand the meaning of '~', I'm not sure if these results are correct or just random. If you have some knowledge on the meaning of '~', please let me know.
Jan
Jan am 12 Nov. 2012
@Rok: Please posrt a new question in a new thread. Using the comment section of another question is not convenient for the ones, who wnat to answer.
Btw.: ~ is the not() operator, as the documentation reveals when you search for it.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

NIRANJAN KOTHA
NIRANJAN KOTHA am 1 Sep. 2016

0 Stimmen

strcmp compares strings not numbers. that might be the problem

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 14 Jul. 2011

Beantwortet:

am 1 Sep. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by