File size: 4,443 Bytes
df4101d
 
 
 
 
 
 
 
 
 
 
 
e6059c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2074e37
 
 
 
 
 
 
 
e6059c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
498876b
e6059c8
498876b
 
e6059c8
df4101d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
title: HeartGuard AI
emoji: πŸ“š
colorFrom: pink
colorTo: yellow
sdk: streamlit
sdk_version: 1.44.1
app_file: app.py
pinned: false
license: mit
short_description: 'Predict heart disease risk in seconds using clinical data '
---
# ❀️ HeartGuard AI - Cardiovascular Risk Prediction System

![Project Banner](assets/banner.png)

**Developed by Musabbir KM**

## πŸš€ Overview

An end-to-end machine learning system that predicts heart disease risk using clinical features, featuring:
- **XGBoost Classifier** with automated threshold optimization
- **Streamlit Web Application** for interactive predictions
- **Comprehensive Model Evaluation** (ROC AUC: 0.909)
- **Production-Ready Pipeline** with feature engineering

## 🌟 Key Features
| Feature | Description |
|---------|-------------|
| **Clinical Risk Assessment** | Classifies patients into High/Medium/Low risk categories |
| **Batch Processing** | Handles CSV uploads for multiple predictions |
| **Interactive Interface** | User-friendly Streamlit dashboard |
| **Model Explainability** | Detailed feature importance analysis |
| **Medical Recommendations** | Actionable insights based on risk level |

## πŸ“Š Dataset Information
**Source:** [UCI Heart Disease Dataset](https://archive.ics.uci.edu/dataset/45/heart+disease)  
**Samples:** 303 patients (Cleaned: 297)  
**Features:** 13 clinical + 3 engineered features  
**Attributes**:
- Demographic: Age, Sex
- Medical: 
  - cp (Chest Pain Type)
  - trestbps (Resting Blood Pressure)
  - chol (Serum Cholesterol)
  - fbs (Fasting Blood Sugar)
  - restecg (Resting ECG)
  - thalach (Maximum Heart Rate)
  - exang (Exercise Induced Angina)
  - oldpeak (ST Depression)
  - slope (ST Segment Slope)
  - ca (Major Vessels)
  - thal (Thalassemia)


## πŸ“Š Feature Description

    -age	Age in years
    sex	Gender (1 = male, 0 = female)
    cp	Chest pain type (1 = typical angina, 2 = atypical angina, 3 = non-anginal pain, 4 = asymptomatic)
    trestbps	Resting blood pressure (in mm Hg)
    chol	Serum cholesterol level (in mg/dl)
    fbs	Fasting blood sugar > 120 mg/dl (1 = true, 0 = false)
    restecg	Resting electrocardiographic results (0, 1, or 2)
    thalach	Maximum heart rate achieved
    exang	Exercise-induced angina (1 = yes, 0 = no)
    oldpeak	ST depression induced by exercise relative to rest
    slope	Slope of the peak exercise ST segment (1, 2, 3)
    ca	Number of major vessels (0–3) colored by fluoroscopy
    thal	Thalassemia (3 = normal, 6 = fixed defect, 7 = reversible defect)

## πŸ“Š Performance Metrics

| Metric        | Score  |
|---------------|--------|
| Accuracy      | 85.2%  |
| Precision     | 84.7%  |
| Recall        | 87.5%  |
| F1-Score      | 85.2%  |

(Validation set performance)


# πŸ† Model Performance

## === Optimized Performance Metrics ===

- **Optimal Threshold:** `0.327`
- **Evaluation on Test Set:** `n = 46`

### πŸ“Š Classification Report

| Class           | Precision | Recall | F1-Score | Support |
|----------------|-----------|--------|----------|---------|
| Healthy         | 0.95      | 0.76   | 0.84     | 25      |
| Heart Disease   | 0.77      | 0.95   | 0.85     | 21      |

### βœ… Overall Metrics

- **Accuracy:** `0.85`
- **Macro Average:**
  - Precision: `0.86`
  - Recall: `0.86`
  - F1-Score: `0.85`
- **Weighted Average:**
  - Precision: `0.87`
  - Recall: `0.85`
  - F1-Score: `0.85`

---

πŸ“Œ This optimized threshold enhances **Heart Disease detection** (high recall) while maintaining high precision for **Healthy** predictions.

## 🧠 Model & System Info

- **Model Name:** Heart-Guard
- **Version:** 1.1
- **Classifier:** XGBoost
- **Optimized Threshold:** 0.327
- **Deployment:** Streamlit App


## ⚠️ Important Disclaimer

**This is NOT a medical diagnostic device.** By using this model, you agree that:

- It should not replace professional medical advice
- It is not for use in emergency situations
- Treatment decisions should not be based solely on its outputs
- Always consult qualified healthcare professionals

**Dataset Source**: [UCI Machine Learning Repository](https://archive.ics.uci.edu/dataset/45/heart+disease)

## πŸ› οΈ Installation

1. Clone repository:
```bash
git clone https://github.com/musabbirkm/heart-disease-predictor.git
pip install -r requirements.txt
cd heart-disease-predictor
streamlit run app.py


Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference