8/20
K-Nearest Neighbors (Distance) Β· Page 1 of 1

The Intuition of KNN

K-Nearest Neighbors (KNN)

"Tell me who your friends are..."

Unlike Regression which learns mathematical weights, KNN has no training phase. It simply memorizes all the data.

How it works:

  1. Plot all training data points.
  2. When a new point arrives, calculate its distance to every other point.
  3. Find the 'K' closest points (neighbors).
  4. Take a vote: If 3 out of 5 neighbors are Class A, the new point is Class A.

Euclidean Distance

dist = sqrt((x2 - x1)^2 + (y2 - y1)^2)
main.py
Loading...
OUTPUT
β–ΆClick "Run Code" to execute…