1

Do someone know how to perform Leave one out cross validation in MATLAB?? I need LOOCV algorithm for data classification. So for example . I have the number of training set 10 , and I want to take out one from training set for testing. So, it's like 1 = testing and 9 for training, and do it again until the last data training.

How about if we have data training like this cancer and no cancer:

[C,F] = training('D:\cancer\',...
    'D:\nocancer\');
user2157806
  • 319
  • 2
  • 8
  • 17
  • look at my answer [here](http://stackoverflow.com/questions/15451301/how-to-create-leave-one-out-cross-validation-in-matlab) – Autonomous Mar 17 '13 at 06:04

1 Answers1

1

Here is what I do :

// Initialize result matrix
Results = zeros(size(Datas,1),2);
// Validate classifier settings with leave-one-out procedure
for k=1:size(Datas,1)
    // Extract sample
    ind = Datas(k,:);
    // Copy the database
    Datas_mod = Datas;
    // Copy the classes vector
    Classes_mod = Classes;
    // Keep the sample real class
    Results(k,2) = Classes(k);
    // Remove sample from database
    Datas_mod(k,:) = [];
    // Remove sample from class vector
    Classes_mod(k)   = [];
    // Execute the classification algorithm
    [Individu,MxD(k)] = knn(ind(1,1:size(ind,2)),Datas_mod,Classes_mod,5,700);
    // Keep the class found by the classifier for the current sample
    Results(k,1) = Individu(1,size(Individu,2));
end

// Confusion matrix
CM = nan_confusionmat(Results(:,1),Results(:,2)) // Scilab function, find your own

Just replace knn by whichever classifier you're using. Hope this help.

CTZStef
  • 1,675
  • 2
  • 18
  • 47