An interactive machine learning web application that predicts the probability of heart disease based on patient health parameters and provides explainable insights using SHAP (SHapley Additive Explanations).
This project combines data preprocessing, machine learning, and explainable AI with a clean Streamlit-based user interface to make predictions interpretable and user-friendly.
-
Predicts heart disease probability using a trained ML model
-
User-friendly dashboard built with Streamlit
-
Accepts patient health parameters as input
-
Displays:
- Prediction result (disease / no disease)
- Probability score
- Top contributing features
-
Uses SHAP to explain model predictions
-
Visualizes feature impact using bar charts
-
Allows exporting prediction report as a downloadable file
-
Includes medical disclaimer for responsible use
- Algorithm: Random Forest Classifier
- Trained on a heart disease dataset
- Preprocessing steps:
- One-hot encoding for categorical features
- Feature scaling for numeric features
- Model accuracy: ~80%
Train the model by running:
python train_model.py
The dataset contains the following features:
age, sex, cp, trestbps, chol, fbs, restecg, thalach,
exang, oldpeak, slope, ca, thal, target
target= 1 → Heart diseasetarget= 0 → No heart disease
The application allows users to:
-
Enter patient details
-
Click Predict
-
View:
- Risk probability
- Prediction result
- Feature contributions
- SHAP explanation chart
-
Download a detailed prediction report
- Python
- Streamlit (Web UI)
- Scikit-learn (ML model)
- Pandas, NumPy (Data processing)
- Matplotlib (Visualization)
- SHAP (Explainable AI)
git clone https://github.com/Arijit2175/Heart-Disease-Prediction.git
cd Heart-Disease-Prediction
pip install -r requirements.txt
streamlit run app.py
-
Launch the app
-
Enter patient information
-
Click Predict
-
View prediction and explanation
-
Download the report if needed
SHAP is used to:
- Show how each feature contributed to the prediction
- Indicate whether a feature increased or reduced risk
- Improve transparency and trust in the model
Example explanation:
Chol contributed +0.27 to increased heart disease probability
Max heart rate contributed -0.14 to reduced heart disease probability
This application is for educational purposes only and does not provide medical diagnosis. Predictions are generated by a machine learning model trained on historical data and may not be 100% accurate. Always consult a qualified healthcare professional for medical advice.
Heart-Disease-Prediction/
├── app.py
├── train_model.py
├── dataset/
└── dataset.csv
├── model.pkl
├── requirements.txt
└── README.md
-
N. Pratheek, S. Rajesh, and R. Suresh,
Cardiovascular Disease Prediction with Machine Learning Algorithms and Interpretation using Explainable AI methods: LIME & SHAP,
IEEE International Conference on Intelligent Computing and Communication Technologies (ICICCT), 2024. -
B. Majhi and A. Kashyap,
Explainable AI-Driven Machine Learning for Heart Disease Detection Using ECG Signals,
Applied Soft Computing, Elsevier, 2024. -
Shah, P., Patel, M., and Mehta, K.,
Predicting cardiovascular risk with hybrid ensemble learning and explainable artificial intelligence,
Scientific Reports, Nature, 2025. -
Mushtaq, M., Akram, M., and Khan, S.,
Causal and Explainable Machine Learning Framework for Heart Disease Prediction using XGBoost and SHAP,
Journal of Computing and Biomedical Informatics, 2025. -
Hussain, S., Alshammari, A., and Raza, A.,
Interpretable Coronary Heart Disease Prediction using Random Forest, XGBoost, and SHAP-Based Explainability,
IEEE Access, 2025. -
Lundberg, S. M., and Lee, S. I.,
A Unified Approach to Interpreting Model Predictions,
Advances in Neural Information Processing Systems (NeurIPS), 2017.
👨💻 Developed by - @Arijit2175



