Applied Case — Clustering & Segmentation

P5.applied-cases.02 · Audience: guest, it-ml, language-pro · Prerequisites: Ensembles & Unsupervised Learning

Real LLM grading for this pageLLM grading (this page):

The supervised cases had an answer column to check against. This case takes it away. Clustering asks the data to propose its own groups — and the whole craft is in what you can no longer take for granted: there is no accuracy, no ground truth, and the algorithm will happily hand you confident nonsense. Two datasets carry the case: the penguins table with its species column removed, and a seeded customer table with no labels at all.

Step 1 / 5Structure without labels

Ensembles & Unsupervised Learning taught the k-means mechanism: pick k centers, assign every point to its nearest center, move each center to the mean of its points, repeat until nothing moves. This case does not re-teach it — it makes you live with its consequences. Three of them run the whole module:

ConsequenceWhere it bites
k-means always answers — it never says "wrong k" or "wrong algorithm"Choosing k (step 3), shapes (step 4)
It measures raw Euclidean distance — units are model decisionsScaling (step 2)
Its clusters are a partition, not the truthPenguins (step 2), naming (step 5)

The practice ladder opens with the loop itself — rung 1 has you rebuild assign/update in raw numpy on three seeded blobs, and its hidden tests know the converged inertia (≈ 108.7) that a correct loop reaches.

k-means minimises within-cluster squared distance. Why does that objective alone guarantee it will 'find' clusters even in perfectly uniform random data?

📚 Go Further
TypeResource
In-appP5.ml-methods.02 — Ensembles & Unsupervised Learning — the k-means mechanism, PCA, and the unsupervised toolbox this case exercises
In-appP5.applied-cases.01 — The Honest Tabular Model — the supervised discipline this case deliberately loses (no labels, no accuracy)
In-appP5.evaluation.01 — Evaluation Metrics — the supervised metrics whose absence makes internal validation (silhouette) necessary
Externalscikit-learn user guide — Clustering: the assumptions table (k-means vs DBSCAN vs hierarchical) this case's step 4 compresses
ExternalKaufman & Rousseeuw, Finding Groups in Data — the silhouette's original home, still the clearest account of what it measures
Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

4 graded rungs · ~46 min

Four rungs, all in-browser (Pyodide, instant): rebuild the k-means loop in raw numpy, choose k with both instruments on the customer table, watch DBSCAN solve what k-means cannot, then put names on the segments — the final rung is free-form prose, graded by the LLM grader against a reference reading.

Rung 1 — Rebuild k-means by hand: assign, update, repeat

Loading exercise…

Rung 2 — Choose k with the elbow and the silhouette

Loading exercise…

Rung 3 — When k-means fails: DBSCAN on non-convex shapes

Loading exercise…

Rung 4 — Name the segments (free-form, LLM-graded)

Loading exercise…

Try it yourself

A scratch console for this page's ideas — ungraded, nothing you run here is recorded.

Scratch console

A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.

Output appears here.