Six records have three categorical attributes: , , , , , . Run k-modes with from initial modes and , 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, . 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
- Distances to : record 1 gives 0, record 2 gives 1, record 3 gives 1, record 4 gives 3, record 5 gives 2, record 6 gives 2.
- Distances to : record 1 gives 3, record 2 gives 2, record 3 gives 2, record 4 gives 0, record 5 gives 1, record 6 gives 1.
- Assign each record to the closer mode: cluster 1 is and cluster 2 is . There are no ties.
- Update the modes attribute by attribute. Cluster 1: attribute 1 is so ; attribute 2 is so ; attribute 3 is so . The mode is . Cluster 2: ; ; , so the mode is .
- The modes did not change, so the algorithm has converged. The cost is .
- 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
- Averaging categories or one-hot vectors. The centre is the mode of each attribute.
- Using Euclidean distance on arbitrary integer codes. The codes have no order, so matching dissimilarity is the right choice.
- Summing squared mismatch counts per record. The k-modes cost is the plain total number of mismatches.
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 and cluster 2 . What are the silhouette values of the points and , and what do they tell you?
Next 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?