我正在尝试通过使用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}
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次交叉验证(一列火车和一份测试),我的问题是:
cvpartition
? sequentialfs
以使用我定义的功能?fun
分类器的定制svm
函数?非常感谢您的帮助