KMeans algorithm implementation.