This repository contains a project aimed at predicting the risk of heart disease using machine learning models. The workflow involves comparing multiple datasets and evaluating the performance of various models to identify the most suitable dataset and model for the task.
This project uses three datasets to train and evaluate machine learning models for heart disease prediction. The datasets are:
- Each dataset was loaded and inspected for missing values.
- Missing values were dropped.
- Categorical columns were encoded using one-hot encoding.
- For each dataset, the target column was identified:
heart.csv:targetheart-2.csv:outputheart-3.csv:HeartDisease
- Features (
X) and target (y) were separated.
- The data was split into training and testing sets using an 80-20 split.
- The following machine learning models were trained and evaluated:
- Logistic Regression
- Random Forest
- Support Vector Machine (SVM)
- XGBoost
- K-Nearest Neighbors (KNN)
- Naive Bayes
- Performance metrics used for evaluation:
- Accuracy
- ROC AUC Score
- Each dataset was evaluated using the above models.
- The performance metrics were compared across datasets.
- For models that support feature importance (e.g., Random Forest, XGBoost), the top features contributing to predictions were identified and visualized.
- Dataset 1:
- Dataset 2:
- Dataset 3:
- Dataset-1 is chosen for making predictions due to its large volume and better model performance
- Random Forest model has been implemented on Dataset-1 due to its consistent performance
- Most important features were identified cooresponding to this model
To enhance the application, the following fields can be inferred or measured using IoT-enabled ECG sensors:
-
Resting ECG (
restecg):- Captured directly from ECG sensors to classify as normal, ST-T wave abnormality, or left ventricular hypertrophy.
-
Oldpeak:
- Derived from ST depression measurements during exercise relative to rest.
-
Slope:
- Determined from the behavior of the ST segment during physical activity.
-
Max Heart Rate (
thalach):- Measured directly as the maximum heart rate achieved during exercise.
-
Exercise Induced Angina (
exang):- Inferred from ischemic changes detected in ECG patterns during exercise.
-
Real-time Data Integration:
- Use IoT devices to stream real-time ECG data to the application.
- Implement APIs or MQTT protocols for seamless data transfer.
-
Machine Learning Models:
- Train models on ECG data to infer fields like
exangandslopewith higher accuracy.
- Train models on ECG data to infer fields like
-
Advanced Metrics:
- Incorporate Heart Rate Variability (HRV) and other ECG-derived metrics for deeper insights into cardiac health.
This future work aims to integrate IoT capabilities, enabling real-time and automated data collection for improved predictions and patient monitoring.










