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:
- Calculate the distance between X and all other points
- Sort points ascending
- Predict the result based on what the major labels are within k range

Pros and Cons
| Pros | Cons |
|---|---|
| Simple | High Prediction cost |
| Trivial training | Not suitable for large datasets |
| Doesn’t matter the number of classes | Categorical features doesn’t work well |
| Easy to add more data | |
| Few para. (K and Distance Metric) |