tezvyn:

How does K-Means clustering work and how do you choose K?

AI-drafted, machine-checkedSource: Wikipedia: K-means clusteringbeginner

Tests centroid-based partitioning and hyperparameter tuning. Explain iterative assignment to nearest means and variance reduction, then cite elbow method, silhouette score, or domain knowledge for K. Red flag: choosing K without quantitative justification.

WHAT THIS TESTS: This question checks two things. First, do you understand the mechanics of an unsupervised centroid-based algorithm well enough to explain it without jargon? Second, do you know that K is a hyperparameter that requires a deliberate strategy, not a guess?

A GOOD ANSWER COVERS: Start with the objective: partition N observations into K clusters so that each observation belongs to the cluster with the nearest mean, which minimizes within-cluster variance. Describe the iterative Lloyd's algorithm in three steps. First, initialize K centroids, often by selecting K random points. Second, assign every observation to the nearest centroid, creating Voronoi cells. Third, recompute each centroid as the mean of all points assigned to it. Repeat the assignment and update steps until centroids stabilize or changes fall below a threshold. For choosing K, name at least two methods. The elbow method plots the sum of squared distances from points to their cluster centroids, called inertia, for a range of K values and looks for an inflection point where adding another cluster yields diminishing returns. The silhouette score evaluates how similar a point is to its own cluster compared to other clusters, with higher values indicating better-defined clusters. Also mention that domain knowledge or downstream business constraints can override pure metrics.

COMMON WRONG ANSWERS: A major red flag is saying you just guess K or run the algorithm many times and pick what looks right. Another is claiming K-Means minimizes Euclidean distance directly; it actually minimizes squared Euclidean distance, which is why outliers pull centroids aggressively. Some candidates forget to mention the iterative nature and describe K-Means as a single-step lookup. Finally, citing only the elbow method without acknowledging its ambiguity, since the elbow is often not sharp, shows shallow experience.

LIKELY FOLLOW-UPS: An interviewer might ask how you handle clusters with non-spherical shapes, which K-Means struggles with because it assumes isotropic variance. They might ask about initialization sensitivity and how K-Means++ improves centroid seeding. Another common follow-up is how you scale features, since K-Means is distance-based and will dominate large-scale variables unless normalized.

ONE CONCRETE EXAMPLE: Suppose you are segmenting retail customers by annual spend and visit frequency. You would standardize both features because their units differ. Running K-Means for K from two to ten, you plot inertia and see a clear elbow at K equals four. You validate this with a silhouette score of zero point four five at K equals four versus zero point three two at K equals five. The resulting clusters might represent loyal high spenders, frequent low spenders, occasional high spenders, and inactive customers, giving marketing a concrete segmentation strategy.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.