K-Means
ELI5 - The Vibe Check
K-Means is a clustering algorithm that groups your data into a set number of buckets without ever being told what the buckets should mean. You say find me 5 groups, and it plants 5 random center points, assigns every data point to its nearest center, moves each center to the middle of the points assigned to it, and repeats until the centers stop moving. You get 5 clusters; figuring out what each one actually represents is on you.
Real Talk
K-Means is an unsupervised clustering algorithm that partitions data into k groups by iteratively assigning each point to its nearest centroid and recomputing centroids as the mean of their assigned points, until the assignments stabilize. It requires choosing k in advance, commonly guided by the elbow method or silhouette score, and works best when clusters are roughly spherical and similarly sized.
Show Me The Code
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=5, random_state=42)
labels = kmeans.fit_predict(X)
When You'll Hear This
"We ran K-Means on purchase behavior and found 4 pretty distinct customer segments." / "K-Means assumed round, evenly-sized clusters, but our data's shaped nothing like that, results were garbage."
Related Terms
Classification
Classification is teaching an AI to sort things into categories. Is this email spam or not? Is this image a cat, dog, or bird?
Feature Engineering
Feature engineering is the unglamorous, hugely important work of turning raw, messy real-world data into the specific columns a model can actually learn fr...
Machine Learning (ML)
Machine Learning is teaching a computer by showing it thousands of examples instead of writing out every rule.
Principal Component Analysis
PCA is a way to take data with a hundred confusing, overlapping columns and boil it down to just a handful of new super-columns that capture most of what a...