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 个评论
Barry Greene
2012-1-19
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
2012-11-12
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
2012-11-12
@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.
回答(1 个)
NIRANJAN KOTHA
2016-9-1
0 个投票
strcmp compares strings not numbers. that might be the problem
类别
在 帮助中心 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!