Implementation of K-means clustering.