Index must be a positive integer less than or equal to the number of test sets.

조회 수: 1 (최근 30일)
Joana
Joana 2019년 12월 11일
편집: Adam 2019년 12월 11일
Hi
i'm trying to create 10-fold cross validation for my CNN. To create the 10 batches I'm using a for loop, but it's giving this error again and again.
'Index must be a positive integer less than or equal to the number of test sets.'
Possibly how I can change the loop to initialize batches.?
selectBatch=cell(1,10);
for k=1:10
%%Prep Data
% 10 kfold crossvalidation indicies
c = cvpartition(204,'kfold',10);
testInd = test(c,selectBatch(k));
trainInd = ~testInd;
epochsTarget = zeros(204,1);
epochsTarget(103:end)=1;
epochsTarget= categorical(epochsTarget);
...............
end
  댓글 수: 3
Joana
Joana 2019년 12월 11일
편집: Image Analyst 2019년 12월 11일
Sorry if my question did not make sense.
This is the full error:
Error using internal.stats.cvpartitionImpl>checkindex (line 441)
Index must be a positive integer less than or equal to the number of test sets.
Error in internal.stats.cvpartitionImpl/test (line 229)
checkindex(i,cv.NumTestSets);
Error in cvpartition/test (line 229)
testIndices = test(cv.Impl,varargin{:});
And it is possible due to this line of the code:
testInd = test(c,selectBatch(k));
Because when I run the code withourt for loop, and with a fixed parameter of 'selectBatch' the code runs okay, but it doesn't work with the for loop.
Image Analyst
Image Analyst 2019년 12월 11일
The error message says your line of code throwing the error is
testIndices = test(cv.Impl,varargin{:});
not
testInd = test(c,selectBatch(k));
When you set a breakpoint on line 229 of your program, what are the values of cv.Impl and varargin{:}? Why are you sending in varargin anyway???

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

답변 (1개)

Adam
Adam 2019년 12월 11일
편집: Adam 2019년 12월 11일
selectBatch(k)
is a cell array, which clearly is not an integer.
selectBatch{k}
may be what you want instead.
That said, your cell array also appears to be empty anyway.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by