Implementation of the K-Means clustering algorithm