필터 지우기
필터 지우기

Problem passing function to sequentialfs

조회 수: 5 (최근 30일)
Marta
Marta 2016년 9월 8일
댓글: Javier Imaz Higuera 2020년 9월 6일
Hi.
I am trying to select the variables that best predict the outcome of a patient group using sequentialfs and the AUC of a model that combines the variables. This is my code:
function inmodel=call_sequentialfs(x,y)
c = cvpartition(length(y),'LeaveOut');
inmodel = sequentialfs(@compAUC2,x,y,'cv',c);
function [AUC]=compAUC2(x,y)
clas = fitcdiscr(x,y,'DiscrimType','linear');
[~,RSvar] = resubPredict(clas);
[~,~,~,AUC] = perfcurve(y,RSvar(:,2),1);
end
end
I get the following error:
Error using crossval>evalFun (line 480)
The function 'call_sequentialfs/compAUC2' generated the following error:
Too many input arguments.
I get no errors when I call
compAUC2(x,y)
from the command line. Digging into the crosseval code, it seems to expect the function compAUC2 to have 4 arguments... Why is that? Can you help?
Many thanks,
Marta
  댓글 수: 1
Utkarsh Singh
Utkarsh Singh 2016년 11월 3일
편집: Utkarsh Singh 2016년 11월 3일
The code goes like this: (refer to sequentialfs)
load fisheriris;
X = randn(150,10);
X(:,[1 3 5 7 ])= meas;
y = species;
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)
Following error is being generated when i run the code:
Start forward sequential feature selection:
Initial columns included: none
Columns that can not be included: none
Error using crossval>evalFun (line 480)
The function '@(XT,yT,Xt,yt)(sum(~strcmp(yt,classify(Xt,XT,yT,'quadratic'))))'
generated the following error:
Too many input arguments.
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{:},...
Someone please help me, thanks in advance!

댓글을 달려면 로그인하십시오.

답변 (1개)

Michael Wang
Michael Wang 2016년 9월 14일
sequentialfs performs “c”-fold cross-validation by repeatedly calling fun with different training subsets of X and y, XTRAIN and ytrain, and test subsets of X and y,XTEST and ytest.
Therefore, it needs four inputs. In your case XTRAIN, YTRAIN, XTEST and YTEST
Here is an example:
function inmodel=call_sequentialfs(x,y)
c = cvpartition(length(y),'LeaveOut');
inmodel = sequentialfs(@compAUC2,x,y,'cv',c);
function [AUC]=compAUC2(XTrain,YTrian,XTest,YTest)
AUC = (sum(~strcmp(YTest,classify(XTest,XTrain,YTrian,'quadratic'))));
end
end
Hope this helps
  댓글 수: 1
Javier Imaz Higuera
Javier Imaz Higuera 2020년 9월 6일
How could you add the type function that classify is going to use? I want it to be an input function from my MAIN function.
function inmodel=call_sequentialfs(x,y,typeFunc)
c = cvpartition(length(y),'LeaveOut');
inmodel = sequentialfs(@compAUC2,x,y,'cv',c); % how to pass typeFunc to the function??
function [AUC]=compAUC2(XTrain,YTrian,XTest,YTest,typeFunc)
AUC = (sum(~strcmp(YTest,classify(XTest,XTrain,YTrian,typeFunc))));
end
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by