A machine learning system that predicts heart disease risk using clinical patient data.
Built with Python, Scikit-learn, Streamlit, FastAPI, and SHAP.
⚠️ This project is for educational purposes only and is NOT a medical diagnostic tool.
- Multiple ML models (Random Forest, XGBoost, LightGBM, etc.)
- Automatic model selection
- Interactive Streamlit web app
- REST API using FastAPI
- Model explainability using SHAP
- Data visualization dashboard
- Risk probability scoring system
Uses the UCI Heart Disease Dataset (processed Cleveland dataset):
Features include:
- Age
- Sex
- Chest pain type
- Blood pressure
- Cholesterol
- ECG results
- Max heart rate
- Exercise angina
- Oldpeak
- Thalassemia
Target:
0= Low risk1= High risk
The training script downloads and cleans the dataset from the UCI repository if data/heart.csv is not already present.
- Data preprocessing
- Missing value handling
- Encoding categorical variables
- Feature scaling
- Model training (10+ models)
- Best model selection
- Evaluation (Accuracy, ROC-AUC)
- Model saving
heart-disease-ai/
│
├── app.py # Streamlit UI
├── api.py # FastAPI backend
├── train.py # Model training
├── predict.py # CLI prediction
├── explain.py # SHAP explainability
├── dashboard.py # Analytics dashboard
├── utils.py
├── config.py
│
├── models/
│ └── model.pkl
│
├── data/
│ └── heart.csv
│
└── requirements.txtpip install -r requirements.txtpython train.pystreamlit run app.pystreamlit run dashboard.pyuvicorn api:app --reloadpython predict.pyPOST /predict
{
"age": 58,
"sex": 1,
"cp": 2,
"trestbps": 140,
"chol": 220,
"fbs": 0,
"restecg": 1,
"thalach": 150,
"exang": 0,
"oldpeak": 1.0,
"slope": 2,
"ca": 0,
"thal": 2
}{
"prediction": "High Risk",
"probability": 0.91,
"confidence": 0.91,
"recommendation": "Consult a healthcare professional promptly.",
"disclaimer": "Not a medical diagnosis."
}- Accuracy: ~85%–95%
- ROC-AUC: ~0.88–0.96
(Depends on dataset split and model choice)
- Python
- Pandas / NumPy
- Scikit-learn
- XGBoost / LightGBM / CatBoost
- Streamlit
- FastAPI
- SHAP
- Matplotlib / Seaborn
This system is NOT a medical device. It is intended only for educational and research purposes.
Always consult a certified medical professional.
Built as a machine learning project for educational purposes.
- Deep learning model (TensorFlow / PyTorch)
- Real hospital dataset integration
- Mobile app version
- Docker deployment
- Cloud hosting (AWS / GCP)
pandas
numpy
scikit-learn
matplotlib
seaborn
streamlit
fastapi
uvicorn
joblib
plotly
shap
xgboost
lightgbm
catboost
-Heart-Disease-Prediction-