Take the 1-D points with and absolute-difference distance. Starting from medoids , compute the total cost, then the cost after swapping medoid 1 with the non-medoid 2. Does PAM accept the swap, and is optimal?
Unsupervised learning, k-medoids
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can evaluate the PAM swap cost: assign each point to its nearest medoid, sum the distances, and accept a swap only if the cost falls.
Key idea
PAM minimises over sets of data points, by repeatedly swapping one medoid for one non-medoid whenever the total cost decreases.
Steps
- Cost of : point 1 costs 0, point 2 costs 1, point 3 costs 2, point 10 costs 1 (to 11), point 11 costs 0, point 25 costs 14. Total .
- Cost of : point 1 costs 1, point 2 costs 0, point 3 costs 1, point 10 costs 1, point 11 costs 0, point 25 costs 14. Total .
- The swap changes the cost by , so PAM accepts it.
- Check the other swaps from . Replacing 2 by 1 or 3 gives 18 each. Replacing 11 by 10 gives . Replacing 11 by 25 gives 19. None improves on 17, so PAM stops.
- Checking all 15 pairs confirms 17 is the global minimum here. Note the medoid 11 is not pulled towards 25, whereas the k-means centre of would be with within-cluster squared error about .
Common mistakes
- Letting the medoid be a point that is not in the data. Medoids must be actual data points.
- Recomputing only the swapped cluster and forgetting that other points may now be closer to the new medoid.
- Using squared distances in the cost. PAM uses the plain sum of dissimilarities.
How long your answer should be
Half a page; 3–4 minutes.
Last checked on 4 December 2026.
Read this
Previous in Unsupervised learning: In mini-batch k-means (Sculley's version) each centre has a count of points it has absorbed. For each point assigned to it, the update is , with . In 1-D the centres are with and with . A mini-batch arrives. What are the new centres, and why does this update make sense?
Next in Unsupervised learning: Six points have true classes (points 1–6) and a clustering puts points in cluster 1 and in cluster 2. Compute the Rand index and the purity. Why is the Rand index alone not enough?