title: K-Nearest Neighbour Classifier accuracy
body: <p>I followed an example of the MATLAB KNN classifier with 10 fold cross validation, I am lost at the stage of computing the model's performance, Please kindly look at my code below and advice on how i can correctly get the accuracy of my classification in percentage (%), I dont get the cVError = 1-mean(errorMat) part. Secondly, the fitcknn and knn.predict functions were used to train and test the model, I need help on how i'll create my own functions to do the same tasks. Thank you.  </p>
  
  <pre><code>indices = crossvalind('kfold',labels,10);
  confusionMatrix = cell(1,1);
  errorMat = zeros(1,10);
  for i = 1:10
  test = (indices==i);
  train = ~test;
  knn = fitcknn(data(train,:),labels(train),'NumNeighbors',kVal);
  y = knn.predict(data(test,:));
  index = cellfun(@strcmp,y,labels(test));
  errorMat(i) = sum(index)/length(y);
  confusionMatrix{i} = confusionmat(labels(test),y);
  end
  
  % Calculate misclassification error
  cvError = 1-mean(errorMat); 
  </code></pre>