Skip to content
Julen Somet García
FRENES
← All missions

Data DAT-06 · Jan 2025

Stroke risk prediction

Classification model that identifies patients at risk of stroke on a highly imbalanced medical dataset, followed by a critical review of our first version.

Role
Data mining project at ISIMA, in a pair with Jocelin Calas
Stack
  • Python
  • pandas
  • scikit-learn
  • imbalanced-learn
  • XGBoost
  • Jupyter
79%of strokes detected on the test set (versus 19% for our first version)
0.84ROC AUC (versus 0.79)
1 in 7flagged patients actually have a stroke
Result of the project Stroke risk prediction

AThe question

From a few simple medical details (age, hypertension, glucose, BMI, smoking…), can we predict whether a patient is at risk of a stroke? The goal is to miss as few cases as possible.

BThe data

5,110 patients and 10 variables, of whom only 249 had a stroke (under 5%). Some BMI values are missing.

CThe method

Data exploration, then imputation, encoding and scaling combined in a scikit-learn pipeline. The imbalance is handled by class weighting or by SMOTE applied only to the training folds. We compared logistic regression, Random Forest and XGBoost by cross-validation on ROC AUC. The decision threshold is chosen on the training set to detect at least 80% of strokes.

DIn charts

Fewer than 5% of patients had a stroke, and this rate goes from almost zero before age 40 to over 20% after 80.
Fewer than 5% of patients had a stroke, and this rate goes from almost zero before age 40 to over 20% after 80.
Importance of each variable for the corrected model: without age, the AUC drops by 0.29; the other variables add almost nothing.
Importance of each variable for the corrected model: without age, the AUC drops by 0.29; the other variables add almost nothing.

EWhat I take from it

Our first version showed 95% accuracy while missing four strokes out of five, and contained a target leak in the BMI imputation. After fixing it and choosing a suitable metric, the model becomes usable as a first screening. However, it produces many false alarms and relies almost entirely on age: the limit comes from the available variables, not from the algorithm.