A machine learning project to predict the presence of heart disease using clinical and demographic data, deployed using a FastAPI backend and containerized with Docker.
This project develops and deploys a machine learning model to predict the likelihood of heart disease based on patient clinical features such as age, cholesterol level, chest pain type, and others.
Multiple classification algorithms were trained and evaluated, including Logistic Regression, Support Vector Classifier (SVC), K-Nearest Neighbors (KNN), Decision Tree, Random Forest, AdaBoost, and XGBoost. After comparative model selection, SVC was chosen for its superior performance on the validation set.
The selected model is served via a RESTful API built with FastAPI. The entire application is containerized with Docker, enabling consistent and portable deployment across environments that support containers.
HeartPredictionAPI/
├── main.py # FastAPI app
├── svm_pipeline.pkl # Trained ML pipeline
├── model_training.ipynb # Model development notebook (optional)
├── requirements.txt # Python dependencies
├── Dockerfile # Docker container instructions
├── README.md # Project documentation
├── .gitignore
└── images/ # Screenshots for API demo
The dataset is taken from Kaggle, which includes clinical features such as:
- Age, sex, chest pain type (
cp), resting blood pressure (trestbps), cholesterol (chol) - Fasting blood sugar (
fbs), ECG (restecg), max heart rate (thalach) - Exercise-induced angina (
exang), ST depression (oldpeak), number of vessels (ca), and thalassemia type (thal)
- Algorithm: Support Vector Machine (RBF Kernel)
- Pipeline: StandardScaler + SVM using
Pipelinefrom scikit-learn - Exported As:
svm_pipeline.pklusingpickle - Tuned With:
GridSearchCV - Evaluated Using: Accuracy, Precision, Recall, F1-Score, and SHAP for model explainability
conda create -n heartapi python=3.12 -y
conda activate heartapigit clone https://github.com/Amaan-developpeur/HeartPredictionAPI.git
cd HeartPredictionAPIpip install -r requirements.txtuvicorn main:app --reloadVisit the interactive Swagger UI at:
📎 http://127.0.0.1:8000/docs
{
"age": 55,
"sex": 1,
"cp": 2,
"trestbps": 130,
"chol": 250,
"fbs": 0,
"restecg": 1,
"thalach": 160,
"exang": 0,
"oldpeak": 1.5,
"slope": 2,
"ca": 0,
"thal": 3
}You can run the entire app in a containerized environment using Docker.
docker build -t heart-api .docker run -p 8000:8000 heart-apiThen open your browser to:
📎 http://localhost:8000/docs
Users can submit patient data here:
The model returns a clear message about heart disease risk:
Server running successfully with Uvicorn:
See requirements.txt for exact versions. Core dependencies include:
fastapiuvicornpandasscikit-learnnumpypython-multipart
Mohammed Amaan
📎 GitHub: Amaan-developpeur


