Clustering & KNN

Visualise how machine learning finds patterns and makes predictions
Interactive ML Lab
●●

Clustering

Explore K-Means: an unsupervised algorithm that discovers groups in data without being told the correct labels.

1. Initialise
2. Assign
3. Update
4. Converge
Feature 2 ↑    Feature 1 →
Cluster 1 Cluster 2 Cluster 3 Cluster 4 ✕ Centroid
Initialise
K-Means begins with randomly chosen centroids. At this point the data points have not been assigned to clusters.
↗

K-Nearest Neighbours

Drag the purple star around the graph. KNN looks at nearby labelled examples and uses the majority class.

Click or drag anywhere to move the new point
Training data
5
5.0
5.0
PREDICTED CLASS
Class A
5 nearest neighbours: 4 A, 1 B
How KNN works
1. Measure the distance from the new point to every training example.
2. Select the k closest examples.
3. Count their labels. The majority label becomes the prediction.

Try it: Move the star across the boundary and change k. Notice how the prediction can change.