A small Python machine-learning project that explores how health and lifestyle factors can be used to estimate stroke risk. The model is trained with a Random Forest classifier using the Kaggle Stroke Prediction Dataset.
Warning
This project is for educational purposes only. Its predictions are not medical advice, a diagnosis, or a substitute for a qualified healthcare professional. Do not use it to make healthcare decisions.
The program:
- Loads the stroke prediction dataset.
- Converts categorical values into numeric features.
- Fills missing BMI values with the dataset median.
- Trains a Random Forest classifier.
- Evaluates the model on a held-out portion of the dataset.
- Prompts for an individual's information and prints a predicted result.
The model uses the following features:
- Gender
- Age
- Hypertension
- Heart disease
- Marital status
- Work type
- Residence type
- Average glucose level
- BMI
- Smoking status
Using the current training configuration and dataset split, the model achieved:
Model Accuracy: 94.72%
Accuracy can vary depending on the dataset, preprocessing steps, and training configuration. Because the dataset is imbalanced, accuracy alone should not be used to judge the model's overall performance.
- Python 3.9 or newer
- pandas
- scikit-learn
Install the dependencies with:
python -m pip install pandas scikit-learnThis project uses the Stroke Prediction Dataset from Kaggle.
Because the dataset has its own licensing terms, it is not included in this repository. Download it from Kaggle and place the CSV at the following path:
data/healthcare-dataset-stroke-data.csv
Your project should look like this:
stroke-predictor/
├── data/
│ └── healthcare-dataset-stroke-data.csv
├── main.py
└── README.md
From the repository root, run:
python main.pyThe script will first train and evaluate the model, then ask you to enter the features required for a prediction. Use the numeric options shown in each prompt—for example, 0 or 1 for yes/no fields.
This is a learning project and should not be treated as a production-ready clinical model. In particular:
- The dataset is imbalanced, so accuracy alone does not fully describe model performance.
- Results may vary depending on the dataset and training configuration.
- The model has not been clinically validated.
- A prediction of “No” does not mean that someone cannot have a stroke.
A lot of this code was written with the help of Gemini. This project was created as a means to teach myself machine learning using python, so I used Gemini to help me learn by doing.
The source code is available under the MIT License. The dataset is provided separately by Kaggle and remains subject to its own license and terms of use.