1
$\begingroup$

I did a Test on my data set with "cvpartition" and "crossvalind" functions (in MATLAB) with the same parameters and data set, but why the error results are different and which one is correct?

Codes are from MATLAB help just data set has been replaced.

crossvalind:

k=10;
indices = crossvalind('Kfold',lables,k);
cp = classperf(lables);
for i = 1:k
    test = (indices == i); 
    train = ~test;
    class = classify(dataset(test,:),dataset(train,:),lables(train,:));
    classperf(cp,class,test);
end

cp.ErrorRate

Error Rate is: 0.3322

and cvpartition:

CVO = cvpartition(lables,'k',10);
err = zeros(CVO.NumTestSets,1);
 for i = 1:CVO.NumTestSets
     trainIdx = CVO.training(i);
     testIdx = CVO.test(i);
     ytest = classify(dataset(testIdx,:),dataset(trainIdx,:),lables(trainIdx,:));
     err(i) = sum(~strcmp(ytest,lables(testIdx)));
end
ErrorRate = sum(err)/sum(CVO.TestSize)

Error Rate is: 0.0342

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.