A PyTorch model for determining stroke risk, based on established risk factors documented in leading medical textbooks, research papers, and guidelines from health organizations. The model achieves an impressive 99.96% accuracy on test data.
This project uses PyTorch to build a neural network classifier for stroke risk prediction. The model analyzes several medical predictor variables to determine if a patient is at risk of a stroke.
The dataset uses 16 health indicators:
- Chest Pain (binary)
- Shortness of Breath (binary)
- Irregular Heartbat (binary)
- Fatigue & Weakness (binary)
- Dizziness (binary)
- Swelling (Edema) (binary)
- Pain in Neck/Jaw/Shoulder/Back (binary)
- Excessive Sweating (binary)
- Persistent Cough (binary)
- Nausea/Vomiting (binary)
- High Blood Pressure (binary)
- Chest Discomfort (Activity) (binary)
- Cold Hands/Feet (binary)
- Snoring/Sleep Apnea (binary)
- Anxiety/Feeling of Doom (binary)
- Age (integer)
To calculate:
- Stroke Risk (high or low risk) (binary)
- Python 3.8+
- PyTorch
- pandas
- scikit-learn
- matplotlib
- Clone the repository
- Create a virtual environment
py -m venv .venv
and activate it.venv/Scripts/activate
- Install dependencies:
pip install -r requirements.txt
- Run the model:
python main.py
- Input layer: 16 features
- Hidden layer 1: 64 neurons with ReLU activation
- Hidden layer 2: 28 neurons with ReLU activation
- Output layer: 2 neurons (Binary classification)
- Optimization: Adam optimizer with learning rate 0.005
- Loss function: Cross Entropy Loss
The model is trained for 1000 epochs and the training progress can be visualized through a loss plot that is automatically generated and saved as 'loss_plot.png'. The model had an accuracy of approximately 99.96%, though results may vary.