title: Predict labels for new dataset (Test data) using cross validated Knn classifier model in matlab
body: <p>I have a training dataset (50000 X 16) and test dataset (5000 X 16)[the 16th column in both the datasets are decision labels or response. The decision label in test dataset in used for checking the classification accuracy of the trained classifier]. I am using my training data for training and validating my cross validated knn classifier. I have created a cross validated knn classifier model using the following code :</p>
  
  <pre><code>X = Dataset2(1:50000,:); % Use some data for fitting
  Y = Training_Label(1:50000,:); % Response of training data
  
  %Create a KNN Classifier model
  rng(10); % For reproducibility
  Mdl = fitcknn(X,Y,'Distance', 'Cosine', 'Exponent', '', 'NumNeighbors', 10,'DistanceWeight', 'Equal', 'StandardizeData', 1);
  
  %Construct a cross-validated classifier from the model.
  CVMdl = crossval(Mdl,'KFold', 10);
  
  %Examine the cross-validation loss, which is the average loss of each cross-validation model when predicting on data that is not used for training.
  kloss = kfoldLoss(CVMdl, 'LossFun', 'ClassifError')
  
  % Compute validation accuracy
  validationAccuracy = 1 - kloss;
  </code></pre>
  
  <p>now I want to classify my Test data using this cross validated knn classifier but can't really figure out how to do that. I have gone through the available examples in matlab but couldn't find any suitable function or examples for doing this.</p>
  
  <p>I know I can use the "predict" function for predicting the classlabels of my test data if my classifier is not cross validated. The code is as following :</p>
  
  <pre><code>X = Dataset2(1:50000,:); % Use some data for fitting
  Y = Training_Label(1:50000,:); % Response of training data
  
  %Create a KNN Classifier model
  rng(10); % For reproducibility
  Mdl = fitcknn(X,Y,'Distance', 'Cosine', 'Exponent', '', 'NumNeighbors', 10,'DistanceWeight', 'Equal', 'StandardizeData', 1);
  
  %Classification using Test Data
  Classifier_Output_Labels = predict(Mdl,TestDataset2(1:5000,:));
  </code></pre>
  
  <p>But I could not find any similar function (like "predict") for cross validated trained knn classifier. I found out the "kfoldPredict" function in Matlab documentation, but it says the function is used to evaluate the trained model. 
  <a href="http://www.mathworks.com/help/stats/classificationpartitionedmodel.kfoldpredict.html" rel="nofollow">http://www.mathworks.com/help/stats/classificationpartitionedmodel.kfoldpredict.html</a> But I did not find any input of the new data through this function. </p>
  
  <p>So could anyone please advise me how to use the cross validated knn classifier model to predict labels of new data? Any help is appreciated and badly needed. :( :(</p>