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 comentarios

Barry Greene
Barry Greene el 19 de En. de 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.
Rok Martincic
Rok Martincic el 12 de Nov. de 2012
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 el 12 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (1)

NIRANJAN KOTHA
NIRANJAN KOTHA el 1 de Sept. de 2016

0 votos

strcmp compares strings not numbers. that might be the problem

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Jul. de 2011

Respondida:

el 1 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by