Training the k-means algorithm