Matlab Cross-Validation error in calculating performance of model

1 view (last 30 days)
I am trying to perform cross-validation on my models with multiple classification classes but I am getting errors when trying to update my classperf on each fold. I am getting this error "Index vector has invalid values."
My code is as below:
K = 5;
N = size(DataSet, 1);
idx = crossvalind('Kfold', N, K);
cp = classperf(trainLabel);
for i = 1:K
...
%Long codes for svmtrain & svmclassify
...
cp = classperf(cp, Group, trueTestLabel); %error on this line
end
cp.CorrectRate
where trainLabel is a 120 x 1 double consisting of the ground-truth score for all of the items; Group is the results obtained from svmclassify in 20 x 1 double; and trueTestLabel is the ground-truth score for the testing class in 20 x 1 double form obtained using the following function:
trueTestLabel = trainLabel(idx == i, end); I have tried converting "Group" and "trueTestLabel" into cells by using num2cell function as such:
cp = classperf(cp, num2cell(Group), num2cell(trueTestLabel ));
but instead, I got a different error saying "When the class labels of the CP object are numeric, the output of the classifier must be all non-negative integers or NaN's."

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!