One of the Method options to Classify is NearestNeighbors. To set up a NearestNeighbors-based classification (nnclas) using the training set tset, we would use nnclas = Classify[tset, Method->"NearestNeighbors"];

I have two questions:-

  1. What is the default number of neighbors?
  2. Is there any control on the number of neighbors that are used?

Spelunk, while interesting, is not particularly illuminating.

I'm using 11.01.


Take the first example from the documentation

trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"};

and use a nearest neighbor classifier to find out the options

Classify[trainingset, Method -> "NearestNeighbors"] // Options


In the Models section you can find the parameters used by the nearest neighbor algorithm; in the case of "NeighborNumber" this seems to work when supplying this as nested Method-call

Classify[trainingset, Method ->{"NearestNeighbors", "NeighborsNumber" -> 2}] //Options


  • $\begingroup$ Too easy! Brilliant response, and up-voted accordingly. $\endgroup$ – dwa Oct 7 '16 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.