Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cardio Predict

Status Python Scikit-Learn FastAPI React Vite

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.

Live Demo

Application: https://cardio-predict-gamma.vercel.app

Table of Contents

Overview

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.


Project Architecture

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
Loading

Features

  • 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

Dataset

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).

Input Features

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

Exploratory data analysis (EDA) was performed to understand feature distributions, examine relationships between variables, identify missing values, and uncover patterns associated with heart disease.

Key Findings

  • Dataset contains 303 patient records.
  • Missing values were found in ca and thal.
  • 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.

Visualizations

Correlation Heatmap:

Age Distribution:


Data Preprocessing

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

Model Development

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.


Model Performance

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.


Confusion Matrix

The confusion matrix illustrates the classification performance of the deployed Logistic Regression model.


ROC Curve

The Receiver Operating Characteristic (ROC) curve demonstrates the model's ability to distinguish between patients with and without heart disease across different classification thresholds.


Tech Stack

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

Project Structure

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

API

POST /predict

Request

{
  "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
}

Response

{
  "prediction": 1,
  "result": "Heart Disease",
  "probability": {
    "heart_disease": 0.88,
    "no_heart_disease": 0.12
  }
}

Installation

Clone the repository.

git clone https://github.com/alibro005/CardioPredict.git

Move into the project directory.

cd CardioPredict

Install the required Python dependencies.

pip install -r requirements.txt

Running the Backend

cd backend

uvicorn main:app --reload

The API will be available at:

http://127.0.0.1:8000

Running the Frontend

cd frontend

npm install

npm run dev

The frontend will be available at:

http://localhost:5173

Future Improvements

  • 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

Author

Muhammad Ali Siddiqui

GitHub: https://github.com/alibro005


License

This project is licensed under the MIT License.

About

An end-to-end machine learning application for heart disease prediction using Classification.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages