K-Nearest Neighbors in Python

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 Data

Prediction Algorithm:1.Calculate the distance from x to all points in your data2. Sort the points in your data by increasing distance from x3. Predict the majority label of the “k” closest points