I'm working on classifying motions from EMG signals with SVM. I have 5 subjects, and I'm trying to get the accuracy for each subject. My data for each subject is a 34290 x 16 array. I stored all the subject data in a 3D array, "data", where data(:, :, 1) is a 34290 x 16 array for the first subject, data(:, :, 2) is the data for the second subject, and so on.
I'm running SVM on each subject with this loop:
for i = 1: 5
thisSub = data(:, :, i);
colMin = min(thisSub); colMax = max(thisSub);
scaledData = (thisSub - colMin) ./ (colMax - colMin);
shuffle = randperm(size(scaledData,1));
scaledData = scaledData(shuffle,:); labels = labels(shuffle,:);
t = templateSVM('KernelFunction','gaussian');
Mdl = fitcecoc(scaledData,labels,'Learners',t, 'coding', 'onevsall', 'CrossVal', 'on', 'kfold' , 5);
accuracy(i, :) = (1 - kfoldLoss(Mdl)) * 100
If I run each subject one-by-one, it runs relatively quickly and performs pretty well for all subjects. However, if I try to run it in this loop, the accuracy for the first subject matches what I get when I do it individually, bu the rest of the subjects are very low. It also takes much longer for each subject than when I do it one-by-one. When I run it one-by-one, I still use this loop, I just set the index to 1, 2, 3, 4, 5, so I'm not resetting anything this way that wouldn't get reset when it all gets run at once in the loop.
Why could this be happening?