Skip to content

Instantly share code, notes, and snippets.

@seyyah
Created July 11, 2013 12:27
Show Gist options
  • Select an option

  • Save seyyah/5975019 to your computer and use it in GitHub Desktop.

Select an option

Save seyyah/5975019 to your computer and use it in GitHub Desktop.
load('fisheriris');
% meas: 150X4
% species: 150X1
CVO = cvpartition(species,'k',10);
% K-fold cross validation partition
% N: 150
% NumTestSets: 10
% TrainSize: 135 135 135 135 135 135 135 135 135 135
% TestSize: 15 15 15 15 15 15 15 15 15 15
err = zeros(CVO.NumTestSets, 1);
for i = 1:CVO.NumTestSets
trIdx = CVO.training(i); % logical
teIdx = CVO.test(i);
ytest = classify(meas(teIdx,:), meas(trIdx,:), species(trIdx,:));
err(i) = sum(~strcmp(ytest,species(teIdx)));
end
cvErr = sum(err)/sum(CVO.TestSize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment