// use built-in function samplesize = size( matrix , 1); c = cvpartition(samplesize, 'kfold' , k); % return the indexes on each fold ///// output in matlab console K-fold cross validation partition N: 10 NumTestSets: 4 TrainSize: 8 7 7 8 TestSize: 2 3 3 2 ////////////////////// for i=1 : k trainIdxs = find(training(c,i) ); %training(c,i); // 1 means in train , 0 means in test testInxs = find(test(c,i) ); % test(c,i); // 1 means in test , 0 means in train trainMatrix = matrix ( matrix(trainIdxs ), : ); testMatrix = matrix ( matrix(testIdxs ), : ); end //// now calculate performance %% calculate performance of a partition selectedKfoldSen=[];selectedKfoldSpe=[];selectedKfoldAcc=[]; indexSen=1;indexSpe=1;indexAcc=1; if ( kfold == (P+N) )% leave one out sensitivity = sum(cvtp) /( sum(cvtp) + sum(cvfn) ) specificity = sum(cvtn) /( sum(cvfp) + sum(cvtn) ) acc
Comments
Post a Comment