The interview question

We have customer activity data without labels. How would you find useful groups?

Work through an assignment step, then question the distance function and the purpose of the groups.

01. Define similarity before choosing K

Suppose the proposed features are monthly sessions and lifetime spending. Spending may have a much larger numerical range, so raw Euclidean distance can mostly reflect money. Decide whether that matches the intended use. Standardizing features changes the question to similarity in standardized coordinates; it does not discover the correct business definition automatically.

A segment for onboarding might emphasize recent behavior, while a segment for support operations might emphasize product usage. Exclude identifiers and any information that would be unavailable when assigning a new customer. Record the feature window so segment changes are interpretable.

02. Calculate one iteration

Take four one-dimensional observations: 1, 2, 8, and 9. Initialize centers at 1 and 8. Assign the first two observations to center 1 and the last two to center 8. Updating each center to its assigned mean gives 1.5 and 8.5. The total squared distance becomes four times 0.25, or 1.

This example is deliberately well separated. With overlapping groups, different initial centers can lead to different local solutions. Repeat initialization and compare results rather than treating one run as a unique discovery.

03. Choose a model with the right assumptions

K-means minimizes within-cluster squared distance and requires a cluster count. Compact groups suit this objective better than curved or strongly unequal-density groups. Consider density-based methods when noise points and irregular geometry are central to the problem.

More clusters can reduce training inertia without producing better segments. Compare stability across samples, representative examples, cluster sizes, and the downstream action each group enables. A silhouette score is one diagnostic, not proof that the groups represent meaningful categories.

04. Handle the production lifecycle

Store the scaler and centers together. Monitor assignment distances and the fraction of very small clusters. If a new campaign introduces a different population, forcing every observation into an old cluster can conceal that change. An explicit distance threshold can route unusual cases for inspection.

Cluster IDs have no intrinsic order. After retraining, cluster 2 may describe a different population. Match groups using their profiles before presenting a longitudinal dashboard. Follow-up: if clusters look stable but a targeted campaign fails, revisit whether the selected similarity is relevant to the action rather than increasing K.

Practice the follow-up

Self-review

Calculate the new centers if observation 9 changes to 19. Which point now dominates the squared-distance objective?

Connect this to embeddings and similarity.

Sources & further reading

scikit-learn: clustering. The interview scenario, calculations, and proposed design choices are illustrative.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.