⚡ KNN for Emergency Triage

In chapter 4 the Minermont team wants a system that suggests the urgency level of each emergency patient, from 1 (red) to 5 (blue), always as a support for the triage nurse. This notebook implements the first algorithm the team studies at AIA, K-nearest neighbors (KNN), by hand and with scikit-learn, on synthetic triage data.

The interactive notebook includes:

  • KNN by hand on a small example: distances, the $K$ nearest neighbors and the majority vote.
  • The Euclidean, Manhattan and Chebyshev distances, their unit balls, and how the metric changes the neighbors.
  • Synthetic emergency patients with vital signs, symptoms and five urgency levels.
  • Why feature scaling matters: no scaling versus min-max, standardization and robust scaling.
  • Choosing $K$ and the metric with stratified cross-validation, and the curse of dimensionality.
  • Final evaluation with the $5 \times 5$ confusion matrix and per-class metrics.

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

Bibliography