An end-to-end machine learning application that predicts the likelihood of heart disease using clinical patient data. The project demonstrates the complete machine learning lifecycle, from exploratory data analysis and model training to deployment through a FastAPI backend and an interactive React frontend.
Application: https://cardio-predict-gamma.vercel.app
- Overview
- Project Architecture
- Features
- Dataset
- Exploratory Data Analysis
- Data Preprocessing
- Model Development
- Model Performance
- Tech Stack
- Project Structure
- API
- Installation
- Running the Backend
- Running the Frontend
- Future Improvements
- Author
- License
Cardio Predict predicts whether a patient is likely to have heart disease using thirteen clinical features from the Cleveland Heart Disease dataset.
The project was developed to demonstrate how a machine learning model can be transformed from a research notebook into a production-ready application. It includes data exploration, preprocessing, model development, API deployment, and a modern frontend that communicates with the backend in real time.
flowchart LR
A[React + Vite Frontend]
B[FastAPI Backend]
C[Scikit-learn Pipeline]
D[Prediction Response]
A -->|POST /predict| B
B --> C
C --> D
D --> B
B -->|JSON Response| A
- End-to-end machine learning workflow
- Exploratory Data Analysis (EDA)
- Data preprocessing pipeline
- Classification model built with Scikit-learn
- FastAPI REST API
- Interactive React frontend
- Real-time predictions
- Probability scores for each prediction
- Responsive user interface
- Cloud deployment
This project is based on the Cleveland Heart Disease dataset from the UCI Machine Learning Repository. The dataset contains 303 patient records and 13 clinical features commonly used for heart disease diagnosis.
The target variable indicates whether a patient has heart disease (1) or not (0).
| Feature | Description |
|---|---|
| age | Age of patient |
| sex | Gender |
| cp | Chest pain type |
| trestbps | Resting blood pressure |
| chol | Serum cholesterol |
| fbs | Fasting blood sugar |
| restecg | Resting ECG results |
| thalach | Maximum heart rate achieved |
| exang | Exercise-induced angina |
| oldpeak | ST depression |
| slope | Slope of ST segment |
| ca | Number of major vessels |
| thal | Thalassemia |
Exploratory data analysis (EDA) was performed to understand feature distributions, examine relationships between variables, identify missing values, and uncover patterns associated with heart disease.
- Dataset contains 303 patient records.
- Missing values were found in
caandthal. - Heart disease classes are moderately balanced.
- Chest pain type, number of major vessels (
ca), and ST depression (oldpeak) showed strong relationships with the target. - Age and cholesterol showed wider distributions with several outliers.
A preprocessing pipeline was built using Scikit-learn's Pipeline and ColumnTransformer to ensure consistent transformations during both training and inference.
The preprocessing workflow included:
- Missing value imputation
- Standardization of numerical features using StandardScaler
- Column-wise feature transformation with ColumnTransformer
- End-to-end pipeline serialization using Joblib
Multiple machine learning algorithms were trained and evaluated to determine the most suitable model for deployment.
Models evaluated:
- Logistic Regression
- Random Forest Classifier
- Decision Tree Classifier
- Support Vector Machine (SVM)
Each model was trained using the same preprocessing pipeline and evaluated on the test dataset using multiple classification metrics.
Logistic Regression achieved the best overall performance and was selected for deployment.
The trained models were evaluated using Accuracy, Precision, Recall, and F1-score.
| Model | Accuracy | Recall | F1-score |
|---|---|---|---|
| Logistic Regression | 0.9 | 0.875 | 0.875 |
| Random Forest | 0.833 | 0.792 | 0.844 |
| Decision Tree | 0.767 | 0.792 | 0.731 |
| Support Vector Machine | 0.9 | 0.875 | 0.875 |
Logistic Regression provided the best balance between predictive performance and model simplicity, making it the final model for deployment.
The confusion matrix illustrates the classification performance of the deployed Logistic Regression model.
The Receiver Operating Characteristic (ROC) curve demonstrates the model's ability to distinguish between patients with and without heart disease across different classification thresholds.
| Category | Technologies |
|---|---|
| Language | Python, JavaScript |
| Data & ML | Pandas, NumPy, Scikit-learn |
| Visualization | Matplotlib, Seaborn |
| Backend | FastAPI, Uvicorn |
| Frontend | React, Vite, Axios |
| Deployment | Vercel, FastAPI Cloud |
| Tools | Git, GitHub, Jupyter Notebook |
CardioPredict/
│
├── artifacts/ # Saved machine learning pipeline
├── backend/ # FastAPI backend
├── frontend/ # React application
├── notebook/ # EDA and model experimentation
├── src/ # Training pipeline and utilities
├── requirements.txt
└── README.md
{
"age": 45,
"sex": 1,
"cp": 0,
"trestbps": 120,
"chol": 200,
"fbs": 0,
"restecg": 0,
"thalach": 150,
"exang": 0,
"oldpeak": 1.0,
"slope": 1,
"ca": 0,
"thal": 2
}{
"prediction": 1,
"result": "Heart Disease",
"probability": {
"heart_disease": 0.88,
"no_heart_disease": 0.12
}
}Clone the repository.
git clone https://github.com/alibro005/CardioPredict.gitMove into the project directory.
cd CardioPredictInstall the required Python dependencies.
pip install -r requirements.txtcd backend
uvicorn main:app --reloadThe API will be available at:
http://127.0.0.1:8000
cd frontend
npm install
npm run devThe frontend will be available at:
http://localhost:5173
- Perform hyperparameter tuning using GridSearchCV
- Add SHAP-based model explainability
- Implement automated unit and API tests
- Containerize the application using Docker
- Configure CI/CD with GitHub Actions
- Monitor model performance after deployment
Muhammad Ali Siddiqui
GitHub: https://github.com/alibro005
This project is licensed under the MIT License.



