How Machine Learning Predicts Stroke Risk: Lessons from a UK Case Study
A look at how gradient-boosted models like XGBoost combine age, glucose, blood pressure and lifestyle data to flag stroke risk, and what the numbers really mean for NHS-style screening.
Why stroke is a natural target for predictive modelling
Stroke remains one of the leading causes of death and long-term disability in the UK, and the NHS spends billions of pounds a year on acute stroke care and rehabilitation. Unlike many diseases, a meaningful share of stroke risk is driven by a small set of measurable factors: age, blood pressure, blood glucose, cardiac history, weight and smoking behaviour. That combination of a serious outcome and well-understood, routinely collected risk factors makes stroke an appealing candidate for statistical and machine-learning risk models. The goal of such models is not to diagnose a stroke as it happens, but to flag, ahead of time, which patients in a GP practice or health-check programme carry an elevated probability of having one, so that preventive measures such as blood-pressure control or anticoagulation can be prioritised.
A recent open-source project, built around a public stroke dataset of a little over five thousand patient records, illustrates both the promise and the practical limits of this approach. It trained a series of models culminating in a tuned XGBoost classifier, and evaluated them the way a clinical audit would: not on raw accuracy, but on how well the model actually catches the patients who go on to have a stroke.
The features that actually move the needle
The underlying dataset recorded eleven fields per patient: age, gender, whether the patient had ever been married, work type, residence type (urban or rural), hypertension status, heart disease history, average blood glucose level, body mass index, smoking status, and the outcome itself. From feature-engineering work on top of these raw fields, the project derived clinically meaningful groupings such as age bands, WHO-style BMI categories, glucose categories aligned with diabetic thresholds, a combined 'high risk' flag for patients with both hypertension and heart disease, and a metabolic-syndrome-style flag for patients who were both obese and hyperglycaemic.
When the trained model's predictions were decomposed using SHAP (SHapley Additive exPlanations, a technique described in a companion article), age emerged as by far the dominant driver of predicted risk, contributing roughly two to three times more than any other single feature, with risk rising sharply after 60. Average glucose level was the second most influential factor, with values above roughly 140 mg/dL substantially increasing predicted risk. Hypertension and heart disease followed as strong binary contributors, and elevated BMI added a further, non-linear boost once patients crossed into the obese range. Lower down the list, smoking history, marital status and occupation type contributed smaller but non-trivial amounts, likely acting as proxies for broader lifestyle and socioeconomic patterns rather than direct causal mechanisms.
From logistic regression to gradient boosting
The project compared five tabular models of increasing sophistication. A trivial 'majority class' baseline, which always predicts 'no stroke', scored a headline accuracy of 95% simply because strokes were rare in the data — but it was clinically worthless, catching zero actual stroke cases. A plain logistic regression model, a natural starting point for binary medical outcomes, reached a modest F1-score around 0.65. Reweighting that same logistic regression to counteract class imbalance (giving more weight to the rare positive cases during training) pushed performance to roughly 0.70.
The bigger jump came from XGBoost, a gradient-boosted decision tree algorithm well suited to structured, tabular health data because it can capture non-linear interactions — for example, the fact that hypertension and high glucose together are more dangerous than either alone — without requiring the analyst to hand-craft every interaction term. A default XGBoost configuration reached a validation F1-score around 0.75; after tuning tree depth, learning rate, the number of boosting rounds and, critically, a class-imbalance weighting parameter, the tuned model reached a validation F1 of 0.81 and a held-out test F1 of 0.80, with a recall of 84% and precision of 78% on the test set.
Reading the confusion matrix like a clinician
Aggregate scores can hide what actually happens patient by patient, so it is worth walking through the model's test-set confusion matrix directly. Out of 1,022 held-out patients, the model correctly identified 917 as low risk and correctly flagged 14 as high risk. It also raised 54 false alarms — patients flagged as high risk who did not go on to have a stroke in the data — and missed 37 patients who did have a stroke but were scored as low risk.
In a screening context, these two error types have very different costs. A false positive typically means an extra conversation with a GP, perhaps a follow-up blood pressure check or blood test — inconvenient and mildly anxiety-inducing, but low harm. A false negative means a patient at real risk is reassured incorrectly and preventive action is not taken. For that reason, most stroke-risk screening tools are deliberately tuned to favour recall (catching true positives) over precision (avoiding false alarms), even at the cost of more false positives overall. The 84% recall achieved here reflects that tuning choice, made explicitly during hyperparameter search by weighting the rare positive class.
What the model cannot tell you
It is worth being blunt about the limitations, because they are exactly the kind of thing that separates a promising research prototype from something safe to use in the NHS. The underlying dataset contains only 249 positive stroke cases out of 5,110 records, which is a thin foundation for learning the subtler patterns that distinguish borderline cases. Its geographic origin is not confirmed as UK-specific, so the base rates and risk relationships it has learned may not transfer cleanly to the UK population without recalibration. It is a static snapshot rather than a longitudinal record, so it cannot capture how a patient's risk changes over months or years of medication, weight change or new diagnoses. And, like essentially every observational risk model, it identifies statistical association, not proven causal mechanism — a strong SHAP contribution for a feature tells you the model leans on that variable, not that intervening on it will change outcomes for a given patient.
These caveats are not a reason to dismiss the approach; they are the reason model cards, clinical validation studies and prospective trials exist before any tool like this is allowed near real patient care. A well-documented research model with an honest F1-score of 0.80 and a clear list of blind spots is far more useful — and far safer — than an undocumented one claiming near-perfect accuracy.
Frequently Asked Questions
Why not just use accuracy to judge a stroke-prediction model?
Because stroke is rare in the general population (roughly 5% of records in the dataset used here), a model that always predicts 'no stroke' scores 95% accuracy while catching zero real cases. F1-score, which balances precision and recall, exposes this failure mode where accuracy hides it.
What are the strongest predictors of stroke risk in this kind of model?
Age is consistently the dominant factor, followed by average blood glucose level, hypertension, heart disease history and BMI. These align with established clinical risk factors used in tools like the NHS's QRISK cardiovascular risk calculator.
Is a model like this ready to use in a GP surgery?
No. It was trained on a public research dataset of just over 5,000 records with only 249 stroke cases, has not been validated on UK-specific demographic data, and its authors explicitly restrict it to educational and research use, not clinical decision-making.
Why does XGBoost outperform logistic regression here?
XGBoost is a gradient-boosted tree ensemble that can automatically capture non-linear relationships and interactions between variables, such as the combined effect of hypertension and high glucose, without the modeller having to specify those interactions by hand, as a linear model like logistic regression would require.