In this problem, with k = 5, it occurs overtraining and the conditional probability is too wiggly. We can see this by seeing the difference between the accuracy over the training and the test set.

To show the other direction, when the data is oversmoothing, we propositally use k = 401.

Now we tune for the best k, which will be a value between the overtraining and oversmoothing cases:

The model automatically uses bootstrap samples for tuning the parameter k.
We can visualize the accuracy and standard deviation of this tuning process.

The user can also manually create bootstrap samples:

Following we see the conditional probability of the best k tunned and how it approximates the real conditional probability.

Kernel methods such as knn suffer from the curse of dimensionality, when they face multiple predictors. With around 100 predictors, the neighborhood is no longer very local, once it covers almost the entire dataset.