Alt+←/→to navigatePage8/2040
K-Nearest Neighbors (Distance) · Page 1 of 1
The Intuition of KNN
25 min Advanced
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:
- Plot all training data points.
- When a new point arrives, calculate its distance to every other point.
- Find the 'K' closest points (neighbors).
- 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…