# Setting the number of neighbors in NearestNeighbors algorithm

I am using Machine learning in Mathematica 11 for a specific set of data. When I use

p=Predict[data]

I get the output model by method of NearestNeighbors, which Mathematica automatically takes as the best method. In my understanding, in Nearest Neighbors technique, we need to specify the number of neighbors (k) which are considered for assigning weights for each point.

How do I see what is the value of k which Mathematica has taken automatically? How can I tune this k value?

I also could not find anything when I used

PredictorInformation[p]

You can specify the number of neighbors using the suboption "NeighborsNumber" for the method "NearestNeighbors":

SeedRandom[1]
data = Table[x -> Sin[4 x] + RandomReal[.4], {x, RandomReal[{0, 6}, 30]}];

pdefault = Predict[data, Method -> "NearestNeighbors"];
p1 = Predict[data, Method -> {"NearestNeighbors", "NeighborsNumber" -> 1}];
p10= Predict[data, Method -> {"NearestNeighbors", "NeighborsNumber" -> 10}];

{pdefault[2.], p1[2.], p10[2.]}

{1.21519, 1.21519, 0.138903}

No.

The nearest-neighbor algorithm is really the "k=1" nearest-neighbor algorithm: Assign the category of the (single) nearest labeled training point.

In the "k-nearest-neighbor" algorithm, you specify $$k$$.