knncWrtK
Try various values of K in KNN classifier
Contents
Syntax
- recogRate = knncWrtK(testSet, trainSet, kMax, plotOpt)
Description
recogRate = knncWrtK(testSet, trainSet, kMax, plotOpt) return the
recognition rates of KNNC w.r.t. various values of k ranging from
1 to kMax.
Example
[trainSet, testSet]=prData('iris'); designNum=size(trainSet.input, 2); testNum =size(testSet.input, 2); fprintf('Use of KNNC for Iris data:\n'); fprintf('\tSize of design set (odd-indexed data)= %d\n', designNum); fprintf('\tSize of test set (even-indexed data) = %d\n', testNum); kMax=15; plotOpt=1; knncWrtK(testSet, trainSet, kMax, plotOpt);
Use of KNNC for Iris data: Size of design set (odd-indexed data)= 75 Size of test set (even-indexed data) = 75 1-NNR ===> 1-3/75 = 96.00%. 2-NNR ===> 1-4/75 = 94.67%. 3-NNR ===> 1-3/75 = 96.00%. 4-NNR ===> 1-3/75 = 96.00%. 5-NNR ===> 1-2/75 = 97.33%. 6-NNR ===> 1-2/75 = 97.33%. 7-NNR ===> 1-2/75 = 97.33%. 8-NNR ===> 1-1/75 = 98.67%. 9-NNR ===> 1-4/75 = 94.67%. 10-NNR ===> 1-2/75 = 97.33%. 11-NNR ===> 1-2/75 = 97.33%. 12-NNR ===> 1-3/75 = 96.00%. 13-NNR ===> 1-3/75 = 96.00%. 14-NNR ===> 1-2/75 = 97.33%. 15-NNR ===> 1-2/75 = 97.33%.
![](knncWrtK_help_01.png)