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!