Session 10: Unsupervised Learning — Clustering
Monday, 30 November 2026, 09:00–11:15 · Room MAD 099
What this session is about
A telecom company wants to know what kinds of customers it has — to design offers and campaigns, and to decide whom to call first. Nobody has told us what the groups are. For the first time in this course, there is no outcome to predict: no RMSE, no holdout verdict. That is unsupervised learning.
- Part A — What k-means does. The algorithm in four steps, drawn on a picture of the customers. Why the variable with the largest numbers wins unless you standardise, and why one random start is not enough.
- Part B — How many segments, and do they mean anything? The within-cluster sum of squares, the elbow and the silhouette for choosing the number of clusters. Which variables to cluster on, and which to profile with. Profiling and naming the segments. And the central warning: k-means always returns clusters — even on random numbers. Whether segments are real has to be shown from outside: with a variable the algorithm never saw.
Report 3 is issued at the start of the session — the assignment link is at the bottom of this page.
Nothing new. cluster comes with R, broom with the tidyverse.
Learning goals
After this session you can:
- Say what distinguishes unsupervised from supervised learning, and what that means for judging the result
- Explain the four steps of k-means, and run it with
kmeans() - Explain why variables must be standardised before clustering, and why redundant variables distort it
- Use
nstartto protect against bad random starts - Explain the within-cluster sum of squares, and choose the number of clusters with the elbow and the silhouette — and say why neither proves that the clusters are real
- Distinguish clustering variables from profiling variables, and say why the outcome stays out of the clustering
- Profile and name segments, and validate them with a variable not used for clustering
- Name other clustering approaches and what they are good at
Slides
Materials
| File | Description |
|---|---|
| Exercise sheet | The in-session exercise |
| telco-customers.csv | Customers of a telecom company |
| Slides | Online after the session |
| Live coding document | Online after the session |
| Exemplary solution | Online after the session |
Data
Customers of a telecom company: one row per customer, with tenure in months, monthly and total charges in US dollars, the services they use, their contract and payment method, and whether they left (churn). It is IBM’s telecom sample dataset — realistic but fictional, made for teaching — distributed with the R package modeldata as wa_churn. The MIT licence covers the package; the data themselves are IBM’s sample data, published by IBM for teaching and demonstration. The file is an unmodified export; every change is made in the code.
The question we answer
When you ask a computer to find groups, how do you know it found something?
Not from the computer. k-means splits random numbers into tidy groups too, and the elbow and silhouette look almost as convincing as for real customers. The evidence comes from outside: segments that differ in something the algorithm never saw — here, how many customers leave, from 5% to 49% — that come back on other samples, and that the business can name and act on. Segments are a useful choice, not a discovery.
Take-home until session 11
Read James et al. (2021), ch. 12.4.1 “K-Means Clustering” and 12.4.3 “Practical Issues in Clustering”, free at statlearning.com. Optional: 12.4.2 “Hierarchical Clustering”.
Session 11: an outcome again — predicting whether a firm will exit. Classification, and why “94% accurate” can mean useless.
Going further
- James et al. (2021), ch. 12.2 — principal components analysis, the other classic unsupervised method
- The
broompackage —tidy(),glance()andaugment()work forkmeans()too
Report 3
| Task sheet | in your Classroom 50 repository, with a hints document — accept the link below |
| Issued | start of this session, 30 November |
| Due | Sunday 6 December, 23:59 |
| Form | individual, pass/fail — required for exam admission |
| Submit | through Classroom 50: push to your repository — how |
| Debrief | session 12 |
The Reports page carries the rules that apply to all three reports. Moodle remains the fallback if GitHub misbehaves.
Accept Report 3
Accept the assignment here — manual, step 1:
The link works from the start of this session on. Before that, Classroom 50 says This assignment is locked. The repository it creates for you holds the task sheet and the hints (TASK.md / TASK.pdf, HINTS.md / HINTS.pdf), the data and a starter document.