Skip to content

Repository files navigation

Stroke Prediction — Machine Learning Analysis

Predicting stroke risk from patient health records using SQL, exploratory data analysis, clustering, and classification, with a focus on handling severe class imbalance.

Author: Oluwasegun Opawoye

Overview

Stroke is one of the leading causes of death and long-term disability worldwide, yet many strokes are preventable when at-risk patients are identified early. This project builds a data-driven system to identify the strongest risk factors, group patients into risk profiles, and predict which patients are likely to have a stroke.

Core question: Given a patient's health indicators, can we reliably flag those at high risk of stroke while missing as few real cases as possible?

The Central Challenge: Class Imbalance

The dataset is severely imbalanced — only 4.9% of patients had a stroke (249 of 5,110). A naive model can reach approximately 95% accuracy by predicting "no stroke" for everyone while catching zero real strokes.

Because a missed stroke (false negative) is far costlier than a false alarm, this project prioritizes recall over raw accuracy.

Dataset

Source: fedesoriano/stroke-prediction-dataset (Kaggle) Records: 5,110 patients · Features: 12

Feature Description
gender Male / Female / Other
age Age in years (0.08 – 82)
hypertension 0 = no, 1 = yes
heart_disease 0 = no, 1 = yes
ever_married Yes / No
work_type Type of employment
Residence_type Urban / Rural
avg_glucose_level Average glucose (55.1 – 271.7 mg/dL)
bmi Body Mass Index (10.3 – 97.6), 201 missing values
smoking_status Smoking history
stroke Target: 1 = stroke, 0 = no stroke

Methodology

Data Loading (Kaggle + SQLite)
        |
SQL Exploration & EDA
        |
Cleaning (fill missing BMI with mean = 28.89)
        |
Feature Engineering + StandardScaler
        |
Unsupervised Clustering (K-Means, risk profiles)
        |
Classification (LogReg, KNN, SVM, Random Forest)
        |
Imbalance Handling (SMOTE + threshold tuning)
        |
Evaluation & Recommendations

Feature Engineering

  • Age Group: Young (0–30), Middle-aged (30–60), Elderly (60+)
  • BMI Group: Underweight, Normal, Overweight, Obese (WHO standards)
  • Glucose–BMI Ratio: interaction between metabolic and weight factors
  • Cardio Risk Score: hypertension + heart_disease (0, 1, or 2)

Results

Clustering (K-Means, k = 2)

Cluster Size Profile Stroke Rate
0 – Healthy 4,400 (86.2%) Lower age, glucose, BMI 3.4%
1 – High-Risk 710 (13.8%) Older, higher glucose/BMI, more heart disease 14.1%

Cluster 1 patients are 4.1 times more likely to have a stroke, indicating that clustering successfully isolated a genuine high-risk subgroup.

Classification & Imbalance Handling

Method Recall Precision ROC-AUC
Baseline SVM 0.82 0.115 0.747
SMOTE 0.82 0.120 0.755
SMOTE + Threshold 0.3 0.80 0.153 0.786

Best model: SVM with SMOTE and threshold tuning (0.3), which detects approximately 80% of real strokes.

Top predictors (Random Forest): Age (0.45), Average Glucose (0.25), BMI (0.24) — together accounting for roughly 94% of predictive power.

Tech Stack

  • Data: pandas, numpy, sqlite3, kagglehub
  • Visualization: matplotlib, seaborn
  • Modeling: scikit-learn (K-Means, PCA, Logistic Regression, KNN, SVM, Random Forest)
  • Imbalance handling: imbalanced-learn (SMOTE)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages