⚡ K-Means Clustering of Patients

In chapter 5, Lucy asks the Minermont team whether they can identify groups of patients at risk before they become ill. There are no labels this time, so Martha proposes unsupervised learning: let the algorithm discover the groups that exist in the data. This notebook implements K-means by hand and with scikit-learn, on a synthetic population of 2000 patients.

The interactive notebook includes:

  • K-means by hand, step by step, on the small example of Martha's notes (section 5.4): assignment, update and the sum of squared errors.
  • Local optima: how a bad start gets stuck, and how K-means++ chooses better starting centroids.
  • A synthetic Minermont patient population with hidden profiles, and why the features must be scaled first.
  • Choosing $K$ with the elbow method, and comparing several values of $K$.
  • The clinical interpretation of each group, including a group at silent risk.
  • How the variables we include decide the groups, and how to assign a new patient to a group.

Want to modify the code and experiment on your own?
Open the notebook in Google Colab

Bibliography