Link: Supervised learning

What is KNN?

It‘s a classification algorithm that predicts the result based on near by data points in the range.

Example: horse vs dog’s body measurement

Algorithm logic

Training stage: just store the data

Prediction stage:

  1. Calculate the distance between X and all other points
  2. Sort points ascending
  3. Predict the result based on what the major labels are within k range

Pros and Cons

ProsCons
SimpleHigh Prediction cost
Trivial trainingNot suitable for large datasets
Doesn’t matter the number of classesCategorical features doesn’t work well
Easy to add more data
Few para. (K and Distance Metric)