This project explores classification techniques using machine learning on the MIT-BIH Arrhythmia database, which contains 10,000 electrocardiograms (ECG). Each ECG consists of 180 time samples and corresponds to one of five possible labels:
- 'A': Atrial premature beat
- 'L': Left bundle branch block beat
- 'N': Normal beat
- 'R': Right bundle branch block beat
- 'V': Premature ventricular contraction
The project consists of two main parts:
- Unsupervised Learning: Principal Component Analysis (PCA) and Clustering (K-Means)
- Supervised Learning: Logistic Regression, Naive Bayes, and Support Vector Machine (SVM)
The analysis expects the following NumPy arrays, which are not included in this repository. You must obtain the dataset from an authorized source and prepare these files before running the notebook:
- X_tp1.npy: A
(10000, 180)NumPy matrix containing ECG signals. - Y_tp1.npy: A
(10000,)NumPy vector with corresponding labels ('A','L','N','R','V').
- Normalization using
StandardScaler() - Label encoding using
LabelEncoder() - Splitting data into training and testing sets (
train_test_split)
- Dimensionality reduction: PCA was applied to reduce 180 dimensions to a lower number while retaining 95% of variance.
- Visualization: Cumulative explained variance plot.
- Reconstruction: Compared original ECG signals with their PCA-reconstructed versions.
- K-Means was applied with
K=5(cheating, since we know the actual number of labels). - Performance was evaluated using:
- Homogeneity: Do clusters contain samples from the same class?
- Completeness: Are all samples of the same class grouped together?
- V-Measure: The harmonic mean of homogeneity and completeness.
-
Logistic Regression
- A simple linear model with
max_iter=10000 - Achieved 82.9% accuracy on the test set.
- Moderate confusion in overlapping classes.
- A simple linear model with
-
Gaussian Naive Bayes
- Based on the assumption of feature independence.
- Performed poorly with 55.1% accuracy due to unrealistic Gaussian assumptions.
-
Support Vector Machine (SVM)
- Two kernels were tested:
- RBF kernel: Best performance with 91.8% accuracy.
- Linear kernel: Slightly worse with 87.6% accuracy.
- The RBF kernel effectively captured nonlinear relationships.
- Two kernels were tested:
-
Decision Tree (Bonus)
- 100% training accuracy, but 87.67% test accuracy, indicating overfitting.
- PCA successfully reduced dimensionality, but classification still required the full feature set.
- K-Means clustering did not perform well due to overlapping classes.
- SVM with RBF kernel was the best classifier, showing the best generalization performance.
- Decision Tree overfitted, making it unreliable for real-world predictions.
Make sure you have the required dependencies installed:
pip install numpy scikit-learn matplotlib