Notes

K-Medoids

When you want to group similar things together, it helps to choose a “representative” for each group. K-Medoids does that in a very grounded way: instead of inventing an average point, it picks a real data point from the dataset to stand for each cluster.

How it works

K-Medoids is a clustering algorithm for splitting data into k groups. Each cluster is represented by a medoid, which is the actual point whose total distance to other points in that cluster is smallest. The algorithm usually works like this:

  • Choose k initial medoids.
  • Assign every data point to its nearest medoid.
  • Try swapping a medoid with a non-medoid point.
  • Keep the swap if it reduces the total within-cluster distance.
  • Repeat until no swap improves the clustering.

This is similar in spirit to K-Means, but the difference matters: K-Means uses the arithmetic mean, which can be badly pulled by outliers. K-Medoids is more robust to noise and extreme values because cluster centers must be real observations.

Why it matters

That robustness makes K-Medoids useful when your data contains unusual cases or when an “average” point is not meaningful. Examples include:

  • Customer segmentation: choose representative customers that actually exist, not synthetic averages.
  • Transaction analysis: cluster spending patterns without letting a few extreme purchases distort the groups.
  • Document or sequence clustering: work with custom distance measures where means are undefined.

K-Medoids also supports distance metrics beyond Euclidean distance, which is a major advantage for mixed, categorical, or precomputed dissimilarity data.

Algorithms and practice

A well-known version is PAM (Partitioning Around Medoids). In Python, you’ll encounter implementations such as sklearn_extra.cluster.KMedoids. The tradeoff is speed: K-Medoids is usually more computationally expensive than K-Means, but in return you get clusters that are easier to interpret and less fragile in messy real-world data.

K-Medoids is a partitional clustering algorithm that represents each cluster by a real data point, called a medoid, chosen to minimize total dissimilarity within the cluster. Unlike K-Means, it works directly with arbitrary distance measures and is more robust to outliers because cluster centers are actual observations. This matters because it produces more stable, interpretable clusters when data contain noise, non-Euclidean distances, or mixed feature types.

Imagine sorting a pile of photos into a few groups, then choosing one real photo from each group that best represents the others. That is the idea behind K-Medoids.

It is a way for AI to group similar things together when nobody has labeled them first. Instead of inventing an “average” center for each group, K-Medoids picks an actual data point as the group’s representative. That makes it easier to understand and often more reliable when the data has weird extremes or mistakes. For example, in customer data, one unusual shopper is less likely to throw off the whole group. It helps find natural groupings while staying grounded in real examples.