IOAI ML Notes Classical Machine LearningSupervised Learning

K-Nearest Neighbours

A comprehensive guide to K-Nearest Neighbours: exploring how local similarity drives instance-based learning.

Syllabus Map


k-Nearest Neighbours

Definition

Distance Metrics

Euclidean Distance

d(p,q)=i=1m(piqi)2d(p, q) = \sqrt{\sum_{i = 1}^{m} (p_i - q_i)^2 }

Manhattan Distance

d(p,q)=i=1mpiqid(p, q) = \sum_{i = 1}^{m} \bigg| p_i - q_i \bigg|

Minkowski Distance

d(p,q)=(i=1mpiqi)1td(p, q) = (\sum_{i = 1}^{m} \bigg| p_i - q_i \bigg|)^{\frac{1}{t}}

Inference

D={(xi,yi)}i=1m, xiR, yi{0,1}\mathcal{D} = \{ (x_i, y_i) \}_{i=1}^{m}, \space x_i \in \mathbb{R}, \space y_i \in \{0 , 1\} Xc={xiRmyi=c}, c{0,1}\mathcal{X}_c = \{x_i \in \mathbb{R}^m \mid y_i=c \}, \space c \in \{0, 1\}

K-Nearest Neighbours In Practice

When to Use K-Nearest Neighbours

When Not to Use K-Nearest Neighbours

Practical Notes

Efficiency and Distance

Hyperparameters and Dimensionality

← Back to Blog