Skip to main content

K-means on 1-D data, K=2 and K=3

Short answer

For K=2 with initial centroids 2 and 24: Cluster 1 = {1,2,5,6,7,9,11,13} centroid 6.75; Cluster 2 = {21,24,26,26,32,35,36,41,43,44,46,48} centroid 35.17. For K=3 with initial centroids 2,24,46: Cluster 1 = {1,2,5,6,7,9,11,13} centroid 6.75; Cluster 2 = {21,24,26,26,32,35} centroid 27.33; Cluster 3 = {36,41,43,44,46,48} centroid 43.0.

Identify the cluster of the following instances using K-Means clustering algorithm (Take K=2 and K=3). X = {2, 24, 21, 5, 6, 41, 35, 36, 9, 26, 44, 7, 46, 26, 11, 1, 32, 43, 48, 13}

Data (sorted): 1, 2, 5, 6, 7, 9, 11, 13, 21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48 (n = 20). For one attribute the distance is d = |x − c|.

Assumptions: the initial centroids are chosen from the data: for K = 2: 2 and 24; for K = 3: 2, 24 and 46. A tie goes to the lower-numbered cluster.

K = 2

Iteration 1 (C1 = 2, C2 = 24)

Valued to C1d to C2ClusterValued to C1d to C2Cluster
1123C126242C2
2022C126242C2
5319C132308C2
6418C1353311C2
7517C1363412C2
9715C1413917C2
11913C1434119C2
131111C1 (tie)444220C2
21193C2464422C2
24220C2484624C2

C1 = {1, 2, 5, 6, 7, 9, 11, 13}, new centroid = 54/8 = 6.75. C2 = {21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48}, new centroid = 422/12 = 35.17.

Iteration 2 (C1 = 6.75, C2 = 35.17): the points 1 to 13 are nearer to 6.75 (e.g. 13: 6.25 vs 22.17); 21 is 14.25 from C1 and 14.17 from C2, so it stays in C2; all others are nearer to C2. No object changes cluster, so the algorithm stops.

Answer (K = 2): Cluster 1 = {1, 2, 5, 6, 7, 9, 11, 13}, centroid 6.75; Cluster 2 = {21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48}, centroid 35.17.

K = 3

Iteration 1 (C1 = 2, C2 = 24, C3 = 46): each value goes to the nearest centroid:

  • C1 = {1, 2, 5, 6, 7, 9, 11, 13} (13 is 11 from both 2 and 24; tie to C1)
  • C2 = {21, 24, 26, 26, 32, 35} (35 is 11 from 24 and 11 from 46; tie to C2)
  • C3 = {36, 41, 43, 44, 46, 48}

New centroids: C1 = 54/8 = 6.75, C2 = 164/6 = 27.33, C3 = 258/6 = 43.0.

Iteration 2 (6.75, 27.33, 43.0)

Border valuesd to C1d to C2d to C3Cluster
136.2514.3330.0C1
2114.256.3322.0C2
3528.257.678.0C2
3629.258.677.0C3

No change in assignment, so the algorithm has converged.

Answer (K = 3): Cluster 1 = {1, 2, 5, 6, 7, 9, 11, 13}, centroid 6.75; Cluster 2 = {21, 24, 26, 26, 32, 35}, centroid 27.33; Cluster 3 = {36, 41, 43, 44, 46, 48}, centroid 43.0.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Mining chapter 5 questions →