Skip to content
StackDecode
AI & ML Atlas
Machine LearningalgorithmInteractive simulation

K-Medoids Clustering

K-means whose centres must be actual data points, so outliers matter less.

The idea

Instead of averaging, each cluster is represented by its medoid, the member with the smallest total distance to the others. That makes it robust to outliers and lets it work with any distance, not just Euclidean. PAM is the classic algorithm.

Watch it run

This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.

  • cluster 1
  • cluster 2
  • cluster 3

Pick 3 real data points as the starting medoids.

1/7

Ringed circles are the cluster centres.

Step by step

  1. 1Choose k data points as initial medoids.
  2. 2Assign each point to its nearest medoid.
  3. 3For each cluster, try swapping the medoid with another member.
  4. 4Keep a swap if it lowers the total distance.
  5. 5Stop when no swap helps.

Where it is used

Clustering with non-Euclidean distances or noisy data.

Watch out for

Slower than k-means (about quadratic in the number of points).

Related