crossval> getFuncVal中的错误:Matlab功能选择

时间:2018-12-30 10:54:26

标签: matlab classification cross-validation matlab-guide feature-selection

我正在尝试通过使用Matlab sequentialfs进行特征选择,但是,我遇到的fun问题如下:

function err = fun(XT,yT,Xt,yt)
%XT: xtrain   yT:label of training set(ytrain)  Xt:xtest  yt:ytest
rng(1); 
model = svmtrain(XT,yT,'Kernel_Function', 'rbf', 'boxconstraint', 1);
err = sum(svmclassify(model, Xt) ~= yt);
end

我已经将数据保存到单元格数组中,其中一个用于功能(Xtrain),另一个用于标签(Ytrain`),其中

XT: Xtrain{1,1}, yT:Ytrain{1,1}, Xt:Xtrain{1,2}, yt:Ytrain{1,2}

例如mathwork page

c = cvpartition(y,'k',10);
opts = statset('display','iter');
fun = @(XT,yT,Xt,yt)...
      (sum(~strcmp(yt,classify(Xt,XT,yT,'quadratic'))));

[fs,history] = sequentialfs(fun,X,y,'cv',c,'options',opts)

即使我尝试运行Matlab预定义设置,也遇到错误:

Columns that can not be included:  none
Step 1, added column 1, criterion value 3.04984e-05
Error using crossval>evalFun (line 480)
The function '@(XT,yT,Xt,yt)(sum(~strcmp(yt,classify(Xt,XT,yT,'quadratic'))))' generated the following error:
The covariance matrix of each group in TRAINING must be positive definite.

Error in crossval>getFuncVal (line 497)
funResult = evalFun(funorStr,arg(:));

Error in crossval (line 343)
    funResult = getFuncVal(1, nData, cvp, data, funorStr, []);

Error in sequentialfs>callfun (line 485)
    funResult = crossval(fun,x,other_data{:},...

Error in sequentialfs (line 353)
                crit(k) = callfun(fun,x,other_data,cv,mcreps,ParOptions);

Error in feature_selection (line 11)
[fs,history] = sequentialfs(fun,X,y,'cv',c,'options',opts);

我想进行2次交叉验证(一列火车和一份测试),我的问题是:

  1. 如何设置cvpartition
  2. 如何设置sequentialfs以使用我定义的功能?
  3. 我应该如何调用已设置为使用fun分类器的定制svm函数?

非常感谢您的帮助

0 个答案:

没有答案