Six records have three categorical attributes: 1=(a,x,p), 2=(a,x,q), 3=(a,y,p), 4=(b,y,q), 5=(b,y,p), 6=(b,x,q). Run k-modes with k=2 from initial modes c1=(a,x,p) and c2=(b,y,q), using the simple matching dissimilarity. What are the clusters, the new modes and the total cost?

Unsupervised learning, k-modes
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can apply k-modes: matching dissimilarity for assignment, then the most frequent category per attribute for the update.

Key idea

Dissimilarity is the number of attributes on which two records differ, d(x,c)=∑j1[xj≠cj]. The cost-minimising centre for a cluster is the attribute-wise mode, so k-modes is k-means with the mismatch count and modes.

Steps

  1. Distances to c1=(a,x,p): record 1 gives 0, record 2 gives 1, record 3 gives 1, record 4 gives 3, record 5 gives 2, record 6 gives 2.
  2. Distances to c2=(b,y,q): record 1 gives 3, record 2 gives 2, record 3 gives 2, record 4 gives 0, record 5 gives 1, record 6 gives 1.
  3. Assign each record to the closer mode: cluster 1 is {1,2,3} and cluster 2 is {4,5,6}. There are no ties.
  4. Update the modes attribute by attribute. Cluster 1: attribute 1 is a,a,a so a; attribute 2 is x,x,y so x; attribute 3 is p,q,p so p. The mode is (a,x,p). Cluster 2: b,b,b; y,y,x; q,p,q, so the mode is (b,y,q).
  5. The modes did not change, so the algorithm has converged. The cost is 0+1+1+0+1+1=4.
  6. Remark: this hand run is stable, but in general ties in a mode are broken arbitrarily and the result depends on the initial modes.

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: A clustering of 1-D data gives cluster 1 ={0,2} and cluster 2 ={6,8,10}. What are the silhouette values of the points x=2 and x=6, and what do they tell you?
Next 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?