使用libsvm的serialfs选择功能 [英] Features selection with sequentialfs with libsvm

查看:78
本文介绍了使用libsvm的serialfs选择功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用matlab工具箱进行特征选择.有一个很好的函数,称为sequencefs,可以很好地完成工作.但是,我无法将其与LibSVM函数集成以执行功能选择.它可以与KnnClassify一起正常工作,请有人帮我.这是KnnClassify的代码:

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)...

fun1 = @(XT,yT,Xt,yt)...

    (sum((yt ~= knnclassify(Xt,XT,yT,5))));

[fs,history] ​​=顺序fs(fun1,data,label,'cv',c,'options',opts,'direction','forward');

[fs,history] = sequentialfs(fun1,data,label,'cv',c,'options',opts,'direction','forward');

推荐答案

您需要包装libsvm函数,以在特定功能集上训练和测试SVM.我建议在单独的.m文件中编写内容(尽管原则上我认为它可以在匿名函数中使用).像这样:

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:

function err = svmwrapper(xTrain, yTrain, xTest, yTest)
  model = svmtrain(yTrain, xTrain, <svm parameters>);
  err = sum(svmpredict(yTest, xTest, model) ~= yTest);
end

,然后您可以通过以下方式呼叫sequentialfs:

and then you can call sequentialfs with:

[fs history] = sequentialfs(@svmwrapper, ...);

(您可能需要检查svmtrain的参数的顺序,我永远不记得它们应该是哪种方式).

(You may need to check the order of the arguments to svmtrain, I can never remember which way round they should be).

想法是svmwrapper将训练SVM并在测试集上返回其错误.

The idea is that svmwrapper will train an SVM and return its error on the test set.

匿名等效项为:

svmwrapper = @(xTrain, yTrain, xTest, yTest)sum(svmpredict(yTest, xTest, svmtrain(yTrain, xTrain, <svm parameters>) ~= yTest);

看起来不太好.

这篇关于使用libsvm的serialfs选择功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆