Implement k-means clustering algorithm