next up previous contents
Next: mb_knn.m Up: k-Nearest Neighbor Classifier Previous: mb_knntrainpicktest.m

mb_knnbestk.m

 function[bestk]=mb_knnbestk(trainin,trainclass,pickin,pickclass,tryk)
%  MB_KNNBESTK - pick the k that produces the best classification rate
%
%  [BESTK] = MB_KNNBESTK(TRIANIN,TRAINCLASS,PICKIN,PICKCLASS,TRYK)
%
%    Outputs:
%     BESTK - that value of k that results in the highest value for
%              CRATE, returned from MB_KNN
%
%    Inputs:
%     TRAININ - training data features
%     TRAINCLASS - one-of-N classification for training data
%     PICKIN - data to use for picking BESTK
%     PICKCLASS - one-of-N classification for PICKIN
%     TRYK - vector of values to try for k
%
% M. Boland - 13 Apr 1999


% $Id: mb_knnbestk.m,v 1.3 1999/07/09 00:21:23 boland Exp $

if (length(tryk)<1)
  error('TRYK must be a vector of values to test') ;
end

crates = [] ;
for i=1:length(tryk)
  [cmat crate missed info] = ...
   mb_knn(trainin,trainclass,pickin,pickclass,tryk(i)) ;
  crates = [crates crate(1)] ;
end

[maxval maxidx] = max(crates) ;

bestk = tryk(maxidx) ;


 



Copyright ©1999 Michael V. Boland
1999-09-18