Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

❤️ AI Heart Diagnostic Suite

Python Streamlit Scikit-Learn XGBoost

An end-to-end Machine Learning pipeline and interactive diagnostic dashboard for predicting heart disease using clinical data.


🗺️ Project Roadmap

Here's a full map of our learning journey:

Project Roadmap


📥 1. Data Acquisition

The first step is bringing the data into our project environment.

The UCI Heart Disease Dataset

Our data comes from the UCI Machine Learning Repository — one of the oldest and most trusted sources of public datasets for ML research.

Dataset Profile

The Acquisition Flow — data_loader.py

This script handles the downloading and initial loading of the data.

Data Acquisition Flow

3 Key Concepts

  1. No Column Names: The raw .data file from UCI has no header. We manually assign names using a Python list.
  2. Handling ? Values: Missing lab readings are marked with ?. We must handle these before processing.
  3. Binary Encoding: We convert the multi-class target (0-4) into binary (0 = healthy, 1 = disease) to simplify the prediction problem.

Output:

  • data/heart_disease_raw.csv (Original)
  • data/heart_disease_cleaned.csv (Ready for EDA)

🧹 2. Data Cleaning

"Garbage in, garbage out" — a model is only as good as the data it learns from.

Data Cleaning Problems

Key Problems Solved:

  • Problem 1: Missing Values (?NaN): We use pd.read_csv(..., na_values="?") to treat ? as missing values.
  • Problem 2: Missing Value Strategy: We use df.dropna(). Losing 6 out of 303 rows is acceptable for this dataset. Missing Value Strategies
  • Problem 3: Target Encoding: Converting severity levels to a clean yes/no binary target. Lambda Encoding
  • Problem 4: Data Types: Ensuring all columns are numeric (float64/int64) for mathematical processing.

Warning

Skipping cleaning leads to "silent failure" where models train on corrupt data and produce dangerous, incorrect medical predictions.

Skip Cleaning Consequences


📊 3. Exploratory Data Analysis (EDA)

Understanding the data before modeling.

EDA Motivation

Key Visualizations:

  1. Target Distribution: Checking if the dataset is balanced (138 healthy vs 165 disease).
  2. Correlation Heatmap: Identifying which features (like cp, exang, oldpeak) correlate most with disease. Correlation Scale
  3. Age Distribution: Visualizing how disease prevalence peaks in the 55–65 age range.
  4. Chest Pain Type vs Disease: Revealing that asymptomatic patients (cp=3) often have the highest disease counts. Chest Pain Insight

Technology Stack:

  • Matplotlib: The "engine" (canvas, saving files).
  • Seaborn: The "smart brush" (drawing complex statistical charts).

🤖 4. Model Training

This is where the machine actually learns to map inputs ($X$) to answers ($y$).

What Training Means

The Training Pipeline:

  1. X/y Split: Separating features from the target variable.
  2. Train/Test Split: Reserving 20% of data for final evaluation to prevent "cheating." Train/Test Split
  3. Feature Scaling: Using StandardScaler to bring all features (Age vs. Cholesterol) into the same range. Feature Scaling
  4. Random Forest: An ensemble of 100 decision trees that use "majority voting" to make robust predictions. Decision Tree Example

Evaluation Metrics:

We use a Confusion Matrix to track exactly where the model makes errors (False Positives vs. False Negatives). Confusion Matrix


⚖️ 5. Multi-Algorithm Comparison

Finding the absolute best model for our specific data.

"No single algorithm is best for every problem." No Free Lunch

Algorithms Evaluated:

  • Logistic Regression: Simple, interpretable baseline. Logistic Regression
  • KNN (K-Nearest Neighbors): Predicts based on the most similar past patients. KNN Intuition
  • SVM (Support Vector Machine): Finds the "maximum margin" boundary. Our Winner! SVM Margin
  • Random Forest & XGBoost: Advanced ensemble methods using bagging and boosting. Bagging vs Boosting

Why Recall Matters

In medical diagnostics, we prioritize Recall to minimize False Negatives (missing a sick patient). Recall vs Precision


🖥️ 6. Interactive AI Dashboard

A production-ready tool built with Streamlit for real-time diagnostics.

Streamlit Concept

Features:

  • Real-time Prediction: Model reruns instantly as sliders move.
  • Intelligent Caching: Uses @st.cache_resource for blazing-fast model loading. Caching Flow
  • Dynamic UI: Red/Green alerts based on diagnostic results.
  • Performance Tracking: Live metrics pulled directly from our benchmark results.

🔗 How Everything Connects

graph TD
    A[data_loader.py] -->|Cleaned CSV| B[eda.py]
    A -->|Cleaned CSV| C[train.py]
    A -->|Cleaned CSV| D[compare_models.py]
    D -->|best_model.joblib| E[app.py]
    D -->|best_scaler.joblib| E
    D -->|comparison_results.csv| E
    E -->|UI| F[Interactive Dashboard]
Loading

Created with ❤️ for AI Diagnostic Research by Rizwan Ullah

About

End-to-end AI Heart Diagnostic Suite with a benchmarked ML core and an interactive MERN-stack clinical portal.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages