Use sequentialfs with SVM in Matlab

时间:2016-04-15 11:11:24

标签: matlab svm feature-selection

Can somebody help me with "sequentialfs "?

I'm failing to use it with the following SVM functions. 'X' contains the features for each observation and 'y' contains the classes of each observation.

SVMModel = fitcsvm(X,Y);
predict(SVMModel, X);

When executing sequentialfs, the following error occurs:

The function 'featureSelection' generated the following error: Too many input arguments.

Here, my code:

fs = sequentialfs(@featureSelection,X,y)

function err=featureSelection(X,y)
    SVMModel = fitcsvm(X,y,'KernelFunction','gaussian', 'KernelScale','auto');
    err = 0;
    for i=1:size(X,1)
         err = err + (y(i) ~= predict(SVMModel,X(i,:)));
    end 
end

Thanks!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。根据MATLAB的文档:

  

sequentialfs 通过重复调用执行10次交叉验证   有趣的是X和y,XTRAIN和ytrain的不同训练子集   测试X和y,XTEST和ytest的子集,如下:

     

标准=有趣(XTRAIN,ytrain,XTEST,ytest)

这意味着您的标准函数应遵循以下形式:

gestureRecognizerShouldBegin(:)

只要 sequentialfs 默认将X数据分隔为XTRAIN和XTEST子集。

以下是一个例子:

function err=featureSelection(XTRAIN,ytrain,XTEST,yTest)