Skip to main content
. 2021 Feb 5;21(4):1114. doi: 10.3390/s21041114
Algorithm 1. K-means extraction of validation sets
Input: All-training set data AT. Number of clustering centers k
Output: Training set T. Verification set V.
 1: According to the two columns of data representing coordinates in All-Training sets AT, k cluster centers are randomly selected: (x1,y1),,(xk,yk). Define an empty list KC.
 2: Put the point (xj,yj) into KC, where j(1,k).
 3: for (xi,yi) to the last two columns of data in AT do
 4:   for (xj,yj) to KC do
 5:      Repeat the process until the clustering center remains unchanged
 6:         {
 7:           //For each example, calculate the class it should belong to.
 8:          c(i):=arg minj(xi,yi)(xj,yj)2
 9:         //For each class, recalculate its cluster center instead of the cluster center at the original location.
 10:         (xj,yj):=Σni=1 1{c(i)=j}(i)Σni=1 1{c(i)=j}
 11:         Put the point (xj,yj) into KC.
 12:       }
 13:    end for
 14: end for
 15://The sample points closest to the cluster center are placed in the validation set V.
 16: I=arg mini(xixj)2+(yiyj)2
 17: Put the data in row I of AT into V.
 18: Delete row I data from AT.
 19: T←AT
 20: return T, V