Predicting heart disease using machine learning
This notebook contains the information I learned from the course:
Course Link
** Project Structure**
Heart-Disease-Classification/
│
├── App/
│ ├── app.py # Main application (UI / API / interface)
│ └── connecter.py # Handles database or model connections
│
├── Dataset/
│ └── heart-disease.csv # Main dataset file
│
├── Model/
│ └── logistic_regression_model.pkl # Saved trained model
│
├── Notebook/
│ └── Heart-Disease-Classification.ipynb # Jupyter notebook for analysis
│
├── README.md # Project overview and usage instructions
└── requirements.txt # Dependencies list
|-- 1. Problem definition
|-- 2. Data
|-- 3. Evaluation
|-- 4. Features
|-- 5. Modelling
|-- 6. Experimentation
"Given clinical parameters about a patient, can we predict whether or not they have heart disease?"
The original data came from the Cleveland dataset from the UCI Machine Learning Repository.
UCI Repository Link
There is also a version of it available on Kaggle:
Kaggle Dataset Link
Since this is related to the health sector, we need high accuracy.
If we achieve 95% accuracy, we will consider the effort worth it (maybe or maybe not).
-
age - age in years
-
sex - (1 = male; 0 = female)
-
cp - chest pain type
- 0: Typical angina → chest pain related to decreased blood supply to the heart
- 1: Atypical angina → chest pain not related to the heart
- 2: Non-anginal pain → typically esophageal spasms (non-heart related)
- 3: Asymptomatic → chest pain not showing signs of disease
-
trestbps - resting blood pressure (in mm Hg on admission to the hospital)
- Anything above 130–140 is typically cause for concern
-
chol - serum cholesterol in mg/dl
- serum = LDL + HDL + 0.2 * triglycerides
- Above 200 is cause for concern
-
fbs - fasting blood sugar > 120 mg/dl (1 = true; 0 = false)
- '>126' mg/dL signals diabetes
-
restecg - resting electrocardiographic results
- 0: Nothing to note
- 1: ST-T Wave abnormality
- Can range from mild symptoms to severe problems
- Signals non-normal heartbeat
- 2: Possible or definite left ventricular hypertrophy
- Enlarged heart's main pumping chamber
-
thalach - maximum heart rate achieved
-
exang - exercise induced angina (1 = yes; 0 = no)
-
oldpeak - ST depression induced by exercise relative to rest
- Looks at stress of heart during exercise
- Unhealthy heart will stress more
-
slope - the slope of the peak exercise ST segment
- 0: Upsloping → better heart rate with exercise (uncommon)
- 1: Flatsloping → minimal change (typical healthy heart)
- 2: Downsloping → signs of unhealthy heart
-
ca - number of major vessels (0–3) colored by fluoroscopy
- Colored vessel means the doctor can see the blood passing through
- The more blood movement, the better (no clots)
-
thal - thalium stress result
- 1, 3: Normal
- 6: Fixed defect → used to be defect but okay now
- 7: Reversible defect → no proper blood movement when exercising
-
target - whether the patient has disease or not
- 1 = Yes
- 0 = No
- (Predicted attribute)
- Run the following command in your terminal
git clone https://github.com/Skanda02/Heart-Disease-Classification.git- On macOS / Linux:
python3 -m venv .venv- On Windows:
python -m venv .venvActivate the environment:
- macOS / Linux:
source .venv/bin/activate- Windows:
.venv\Scripts\activateInstall the required packages:
pip install -r requirements.txtStart the application by running:
- macOS / Linux
python3 App/app.py- Windows
python App/app.py