A machine learning algorithm that provides clustering especially used for unsupervised learning by partitioning data into clusters based on their nearest mean (average or centroid). K is a user-defined variable that determines the number of desired clusters for the data set.