I want to use matlab toolbox to do feature selection. there is one good function there called sequentialfs that does a good job. However, I could not integrate it with LibSVM function to perform features selection. It works fine with KnnClassify, can somebody help me please. here is the code for KnnClassify:
fun1 = @(XT,yT,Xt,yt)…
(sum((yt ~= knnclassify(Xt,XT,yT,5))));
[fs,history] = sequentialfs(fun1,data,label,’cv’,c,’options’,opts,’direction’,’forward’);
You’ll need to wrap the libsvm functions to train and test an SVM on a particular featureset. I’d suggest writing things in a separate .m file (though in priciple I think it could go in an anonymous function). Something like:
and then you can call
sequentialfswith:(You may need to check the order of the arguments to
svmtrain, I can never remember which way round they should be).The idea is that svmwrapper will train an SVM and return its error on the test set.
The anonymous equivalent would be:
which doesn’t look very nice.