Instance Based Learning

Package KKNN
To train your data set using K-nearest neighbors using package {KKNN}, you use the function train.kknn as described in the CRAN page:

fit.train <- train.kknn(class ~ ., ionosphere.learn, kmax = 15,

kernel = c("triangular", "rectangular", "epanechnikov", "optimal"), distance = 1)

An interesting feature about the function train.kknn is that when you set  kmax = M, the function will run KNN on values of K from 1 to M, and will output the most optimal one. Also if you include more than one type of kernel in the kernel argument, it will try each one of them and output the best one.

This functionality is interesting since it spares you the effort of writing a function to loop through different K values looking for the best one.