Ansh Thakkar
All projects

Stroke risk predictor

Health ML

A Flask app that takes a patient’s health indicators and returns high or low stroke risk. The more useful result came from checking the models, not from the app.

5,110
patient records
1,533
patients in the test set
89
of them had a stroke
7
found by the best model

Accuracy hid the problem

My stroke models scored about 94%. In the test set of 1,533 patients, 89 had a stroke. Choose a model to see how many it found.

Model

0 of 89 strokes found

Logistic regression found none of them. Its overall accuracy was still 94.2%.

Highlights

  • Three models trained on 5,110 patient records and tested on 1,533 patients, 89 of whom had a stroke.
  • Logistic regression, random forest and XGBoost all scored about 94% accuracy.
  • Logistic regression and random forest found none of the 89 strokes. XGBoost found 7.
  • Predicting no stroke for every patient also scores 94.2%, which is exactly what logistic regression scored.
  • A Flask form takes age, gender, hypertension, heart disease, marital status, work type, residence, average glucose level, BMI and smoking status, and returns a high or low risk label.
Results on the test set of 1,533 patients
ModelAccuracyStrokes found, of 89
Logistic regression94.2%0
Random forest94.1%0
XGBoost93.9%7

The full story

Only 5.8% of the test patients had a stroke, so a model that always says no stroke is right 94.2% of the time. Logistic regression scored exactly that, and ranked by accuracy the only model that found any strokes came last. A model like this should be judged by how many real cases it finds and how many false alarms it raises.

Next I would train with class weights or resampling so strokes count for more, choose the decision threshold from the precision and recall trade-off, and show strokes found and false alarms next to accuracy in the app. It is a student project and not a medical tool. The code is on GitHub.

Built with

Python, Flask, scikit-learn, XGBoost, pandas

Up and down to moveEnter to openEsc to close