help with error in my code

조회 수: 5 (최근 30일)
Ditf
Ditf 2020년 12월 31일
댓글: Rena Berman 2021년 5월 6일
Hi can someone help me understand the mistake in my code, i followed the correct syntax from https://uk.mathworks.com/help/bioinfo/ref/classperf.html
i keep getting the error
operator "==" not supported for operands of type "cvpartition"
error in line 24
test = (indices == 1)
k = 4;
n = 699; %sample lenght
rng ('default')
indices = cvpartition(n,'kfold', k);
for i = 1:k
test= (indices == i); train = ~test;
class = classify(InputVariable(test,:),InputVariable(train,:),OutputVariable(train,:));
classperf(cp,class,test);
end
cp.ErrorRate
plotconfusion(testTarget, testY)
  댓글 수: 4
Stephen23
Stephen23 2021년 1월 2일
편집: Stephen23 2021년 1월 2일
Original question by Dilpreet kaur retrieved from Google Cache:
help with error in my code
Hi can someone help me understand the mistake in my code, i followed the correct syntax from https://uk.mathworks.com/help/bioinfo/ref/classperf.html
i keep getting the error
operator "==" not supported for operands of type "cvpartition"
error in line 24
test = (indices == 1)
k = 4;
n = 699; %sample lenght
rng ('default')
indices = cvpartition(n,'kfold', k);
for i = 1:k
test= (indices == i); train = ~test;
class = classify(InputVariable(test,:),InputVariable(train,:),OutputVariable(train,:));
classperf(cp,class,test);
end
cp.ErrorRate
plotconfusion(testTarget, testY)
Rena Berman
Rena Berman 2021년 5월 6일
(Answers Dev) Restored edit

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

채택된 답변

Image Analyst
Image Analyst 2020년 12월 31일
I get this:
k = 4;
n = 699; %sample lenght
rng ('default')
indices = cvpartition(n,'kfold', k)
indices =
K-fold cross validation partition
NumObservations: 699
NumTestSets: 4
TrainSize: 525 524 524 524
TestSize: 174 175 175 175
You're not using indices correctly. It's an object, not a list of indices. If you want a listof indices, use randperm().

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 1일
편집: Walter Roberson 2021년 1월 2일
cvpartition does not return indices.
rng ('default')
nfold = 4;
cvfolds = cvpartition(699,'kfold', nfold);
cp = classperf(OutputVariable); % initializes the CP object
for i = 1:nfold
test = cvfolds.test(i);
train = cvfolds.training(i);
class = classify(InputVariable(test,:), InputVariable(train,:), OutputVariable(train,:));
classperf(cp, class, test);
end
cp.ErrorRate

카테고리

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