In this article, we will cover how K-nearest neighbor (KNN) algorithm works and how to run k-nearest neighbor in R. It is one of the most widely used algorithm for classification problems. Knn is a non-parametric supervised learning technique in which we try to classify the data point to a given category with the help of training set.
First divide the entire data set into training set and test set. Apply the KNN algorithm into training set and cross validate it with test set. Lets assume you have a train set xtrain and test set xtest now create the model with k value 1 and pred.