Algorithm 1.
Object weighting K-means
| Input: | |
| - the dataset X with n objects | |
| - the object weighting scheme (WS 1 to 7 defined in Section 2.1) | |
| Output: | |
| - the best clustering according to the selected WS | |
| - the object weights and the cluster centroids | |
| 1. Parameter setting. Choose the number of clusters K and the weighting scheme (see Equations 5–11). Set wi = 1, for i = 1,…,n. | |
| 2. Setting initial centers and clusters. Assign K objects from X, selected at random, to be initial cluster centers c1, c2,…, CK. Assign each object xi ∈ X to the cluster Sk represented by the nearest ck as per (2) to form the initial clustering S. | |
| 3. Cluster update. Let be the weighted within sum of squares of the cluster Sk. For all objects xi ∈ Sk and all clusters Sk (k = 1,…,K) do: | |
| If there exists a cluster Sk′ such that after moving xi from Sk to Sk′, we have: | |
| DIFF = L(Sk, ck, w) + L(Sk′, ck′, w) − L(Sk \ xi, ck, w) − L(Sk′ ∪ xi, ck′, w) > 0 | |
| then assign xi to the cluster Sk′ that provides the maximum of DIFF. The cluster centers and object weights in both Sk and Sk′ are updated when calculating DIFF. When all objects of X are examined, a new clustering S′ = {S′1, S′2,…, S′K} is generated. | |
| 4. Decision step. If S′ = S or the maximum number of K-means iterations I is reached, then output the generated clustering S′, cluster centers C and object weights w, and end the computation; otherwise go to Step 3. | |