Git Product home page Git Product logo

jorgesandoval / heartbeat-classification-cnn Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 15.92 MB

An advanced ECG anomaly detection system using deep learning. This repository contains a CNN autoencoder trained on the PTBDB dataset to identify abnormal heart rhythms. It employs various loss functions for model optimization and provides comprehensive visualizations of the results.

License: MIT License

Jupyter Notebook 100.00%
anomaly-detection autoencoder deep-learning ecg-analysis cardiology data-visualization healthcare-ai machine-learning tensorflow ptbdb-dataset

heartbeat-classification-cnn's Introduction

CNN Autoencoder for Anomaly Detection in ECG Data

License: MIT GitHub Stars GitHub Downloads GitHub Forks Alt text

This repository contains a CNN autoencoder trained on the PTBDB dataset to identify abnormal heart rhythms. It employs various loss functions for model optimization and provides comprehensive visualizations of the results.

๐Ÿ“– Table of Contents

๐Ÿ“Œ Overview

This repository demonstrates the use of Convolutional Neural Networks (CNN) based Autoencoders to perform anomaly detection on Electrocardiogram (ECG) data. Given ECG samples of normal and abnormal heart rhythms, the model aims to learn the intrinsic representation of the normal data using an autoencoder, then differentiate between normal and abnormal data based on the reconstruction error.

๐Ÿ“Š Dataset

This dataset consolidates heartbeat signals from the renowned MIT-BIH Arrhythmia Dataset. With a substantial sample size, it serves as a foundation for training advanced neural networks.

The purpose behind the dataset's curation has been to delve into the nuances of heartbeat classification employing deep neural network models and to discern the potential of transfer learning on such datasets. Each signal in the dataset portrays the ECG patterns of heartbeats, categorized into normal and those influenced by various arrhythmias and myocardial infarction. Each signal has undergone preprocessing and segmentation to represent individual heartbeats.

Arrhythmia Dataset :

  • Samples: 109,446

  • Categories: 5

  • Frequency: 125Hz

  • Origin: Physionet's MIT-BIH Arrhythmia Dataset

  • Class Labels: ['N': 0, 'S': 1, 'V': 2, 'F': 3, 'Q': 4]

  • File Name: ptbdb_normal.csv, ptbdb_abnormal.csv

  • Description: The datasets contain ECG recordings representing heart rhythms. The former encapsulates normal heartbeats, while the latter captures abnormal rhythms, offering a comprehensive view of cardiac activity variations.

โš™๏ธ Workflow:

1. Data Pre-processing:

  • Load normal and abnormal datasets.
  • Drop the target columns to obtain pure data samples.
  • Split the normal dataset into training and testing sets.

2. Device Check:

  • Detect if the code is running on a GPU, a conventional CPU, or an M1/M2 Mac and accordingly select an appropriate optimizer.

3. Model Training & Evaluation:

  • Train the autoencoder model using different loss functions.
  • Determine a threshold value for classification based on the 95th percentile of the reconstruction error on training data.
  • Evaluate model performance on combined validation data (normal + anomaly).
  • Visualize the reconstructed ECG signals for both normal and anomaly samples.

4. Best Model Selection:

  • Select the best model based on the minimum average validation error.

5. Classification & Metrics Calculation:

  • Classify reconstruction errors as either normal or anomaly.
  • Calculate and display performance metrics like accuracy, precision, recall, F1-score, and display the confusion matrix.

๐Ÿ”ง Dependencies

To run the notebook, you'll need the following libraries:

  • numpy
  • pandas
  • matplotlib
  • seaborn
  • platform
  • tensorflow
  • scikit-learn

You can install these using pip:

pip install pandas numpy matplotlib scikit-learn seaborn platform tensorflow

๐Ÿš€ Usage

  1. Clone the repository:

    git clone https://github.com/jorgesandoval/heartbeat-classification-cnn.git
  2. Navigate to the cloned directory and open the Jupyter notebook"

    cd heartbeat-classification-cnn
    jupyter notebook
  3. Run the notebook: Execute the notebook cells sequentially to preprocess the data, train the CNN Autoencoder model, and evaluate its performance.

๐Ÿ“ˆ Key Findings

  • The model achieved an accuracy of 99.66% in classifying ECG rhythms.
  • The precision score is 99.64%, indicating the proportion of positive identifications that were actually correct.
  • A recall of 100.00% means the model correctly identified all actual positives.
  • The F1 Score, a measure of the model's accuracy considering both precision and recall, stands at 99.82%. These metrics reflect the model's capability in ECG anomaly detection.

๐Ÿ“ Notes

  • For best results, adjust hyperparameters like batch size, epochs, or the architecture of the AutoEncoder class.
  • Ensure GPU support is enabled if available to speed up the training process.

๐Ÿ’ก Contributions

Contributions to this repository are very welcome! Whether it's fixing bugs, improving the documentation, adding new features, or providing feedback, your insights can help improve this project. Here's how you can contribute:

  1. Fork the Project
  • Navigate to the main page of the repository.
  • Click on the Fork button on the top right.
  1. Create Your Feature Branch

    git checkout -b feature/AmazingFeature
  2. Commit Your Changes

    git commit -m 'Add some AmazingFeature'
  3. Push to the Branch

    git push origin feature/AmazingFeature
  4. Open a Pull Request

  • Navigate back to the main page of your forked repository.
  • Click on the "Pull requests" tab.
  • Click on the green "New pull request" button.

๐Ÿ“œ License

Distributed under the MIT License. See LICENSE for more information.

๐Ÿ‘ค Authors

๐Ÿ™Œ Acknowledgements

Acknowledgment is extended to Mohammad Kachuee, Shayan Fazeli, and Majid Sarrafzadeh for their work, "ECG Heartbeat Classification: A Deep Transferable Representation." as documented in arXiv preprint arXiv:1805.00794 (2018).

heartbeat-classification-cnn's People

Contributors

jorgesandoval avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.