Take the 1-D points {1,2,3,10,11,25} with k=2 and absolute-difference distance. Starting from medoids {1,11}, compute the total cost, then the cost after swapping medoid 1 with the non-medoid 2. Does PAM accept the swap, and is {2,11} 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 ∑imin⁡m∈Md(xi,m) over sets M of k data points, by repeatedly swapping one medoid for one non-medoid whenever the total cost decreases.

Steps

  1. Cost of {1,11}: 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 =0+1+2+1+0+14=18.
  2. Cost of {2,11}: 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 =17.
  3. The swap changes the cost by 17−18=−1<0, so PAM accepts it.
  4. Check the other swaps from {2,11}. Replacing 2 by 1 or 3 gives 18 each. Replacing 11 by 10 gives 1+0+1+0+1+15=18. Replacing 11 by 25 gives 19. None improves on 17, so PAM stops.
  5. 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 {10,11,25} would be 15.33 with within-cluster squared error about 140.7.

Common mistakes

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 c has a count v of points it has absorbed. For each point x assigned to it, the update is v←v+1, c←(1−η)c+ηx with η=1/v. In 1-D the centres are c1=4 with v1=3 and c2=10 with v2=1. A mini-batch {6,2,9,12} arrives. What are the new centres, and why does this update make sense?
Next in Unsupervised learning: Six points have true classes A,A,A,B,B,B (points 1–6) and a clustering puts points {1,2} in cluster 1 and {3,4,5,6} in cluster 2. Compute the Rand index and the purity. Why is the Rand index alone not enough?