Implementation of k-means clustering.