The Stroke Predictor is a machine learning-based web application that predicts stroke risk based on health data inputs like age, gender, BMI, and smoking status. It includes two core scripts:
train.py: Trains a TensorFlow neural network, preprocesses data, and saves model artifacts (model, scaler, encoders, SHAP explainer).app.py: A Flask web app with a user-friendly interface for input collection, stroke risk prediction, and interpretable results with lifestyle recommendations.
The model uses a neural network with dropout regularization, SHAP for interpretability, and Flask with CSRF protection for secure web deployment.
- Data Preprocessing: Handles missing values, encodes categorical features, and scales numerical features.
- Model Training: Trains a neural network for binary classification (stroke/no stroke).
- Web Interface: Validates user inputs and displays predictions, risk scores, and top risk factors.
- Interpretability: Uses SHAP to identify key risk factors (e.g., high glucose, smoking).
- Recommendations: Offers personalized lifestyle advice based on user inputs.
- Python 3.8+
- Required packages (listed in
requirements.txt):- pandas
- numpy
- scikit-learn
- tensorflow
- flask
- flask-wtf
- joblib
- shap
- A web browser for accessing the Flask app.
stroke_predictor/ ├── dataset/ │ └── stroke_data1.csv # Input dataset for training ├── model/ │ ├── stroke_predictor_model.h5 # Trained neural network model │ ├── label_encoders.pkl # Label encoders for categorical features │ ├── scaler.pkl # StandardScaler for numerical features │ ├── shap_explainer.pkl # SHAP explainer for interpretability │ └── feature_names.pkl # Feature names for SHAP explanations ├── templates/ │ └── index.html # HTML template for Flask app ├── app.py # Flask web application ├── train.py # Model training and preprocessing script ├── requirements.txt # Python dependencies └── README.md # Project documentation
Clone the Repository: git clone cd stroke_predictor python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
- Open VSCode and navigate to your
stroke_predictor/directory. - Create or open
README.mdin the project root. - Copy the entire content above and paste it into
README.md. - Save the file.
- Stage and commit to Git: git add README.md git commit -m "Add README for Stroke Predictor project" git push origin main