The k-nearest neighbors algorithm

In pattern recognition or grouping, the k-nearest neighbors (k-NN) algorithm is a non-parametric method implemented for classification and regression. For those two cases, the input consists of the k-closest training examples in the feature space. The following four lines of R code tries to separate plants into k-groups by using a dataset called iris:

library(ggvis) 
x<-ggvis 
y<-layer_points 
iris %>% x(~Petal.Length,~Petal.Width,fill=~Species) %>% y() 

The graph is shown here:

The following diagram shows the five nearest neighbors:

The code generated by the five nearest neighbors is given here. The code is ...

Get Hands-On Data Science with Anaconda now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.