Grouping data into 'k' distinct, non-overlapping clusters.
K-Means is one of the most popular and straightforward clustering algorithms in unsupervised machine learning. Its objective is to partition a dataset of 'n' observations into 'k' predefined, non-overlapping clusters, where each data point belongs to the cluster with the nearest mean (cluster centroid). The algorithm works iteratively to assign each data point to one of the 'k' groups based on the features that are provided. The process begins by randomly initializing 'k' centroids, which are the central points of the clusters. Then, it performs two steps repeatedly: the Assignment step and the Update step. In the Assignment step, each data point is assigned to its nearest centroid, based on a distance measure like Euclidean distance. In the Update step, the centroids are recalculated by taking the mean of all data points assigned to that centroid's cluster. This loop continues until the centroids no longer move significantly, and the cluster assignments stabilize. The choice of 'k', the number of clusters, must be specified beforehand and is a critical parameter. A common method to find the optimal 'k' is the 'elbow method', which involves plotting the cost function against 'k' and looking for an 'elbow' point where the rate of decrease sharply shifts. K-Means is computationally efficient and easy to implement, making it an excellent choice for clustering large datasets, especially for initial data exploration and tasks like customer segmentation.