Hardik Jaroli shows how to use the k-Nearest Neighbors algorithm using scikit-learn:

K Nearest Neighbors is a classification algorithm that operates on a very simple principle. It is best shown through example! Imagine we had some imaginary data on Dogs and Horses, with heights and weights.

Training Algorithm:

1. Store all the DataPrediction Algorithm:

1.Calculate the distance from x to all points in your data

2. Sort the points in your data by increasing distance from x

3. Predict the majority label of the âkâ closest points