Saving Lives - Using BiLSTM Autoencoders to Detect Heartbeat Anomalies

Saving Lives - Using BiLSTM Autoencoders to Detect Heartbeat Anomalies

Every day, people all over the world suffer from heart anomalies. Some of the disorders induce severe cardiac problems, many go undetected and even more go unobserved. It's in those tiny aberrations that we don't know about where modest therapy today may save you money down the road. How can we use artificial intelligence today to look at data from the past in order to prevent heart problems tomorrow?

There are different types of heart anomalies, but the most common ones are tachycardia and bradycardia. Tachycardia is when the heart rate is too high, while bradycardia is when the heart rate is too low. Other less common heart anomalies include arrhythmias, which are irregular heart rhythms. Most anomalies lead to some form of heart failure.

In order to detect these anomalies, doctors typically use electrocardiograms (EKGs). EKGs are a common way to measure the electrical activity of the heart and can be used to diagnose various heart conditions. Using Apple's healthcare kit, we have access to a variety of different types of data that can be used to detect heart anomalies. These include heart rate, blood pressure, and electrocardiogram (ECG) data. Here, we will focus on using ECG data.

No alt text provided for this image

This is where artificial intelligence comes in. By using deep learning through neural networks, we can build models that are more robust to these factors and that can learn to detect heart anomalies from EKGs with a high degree of accuracy. In addition, these models can be customized to an individual, moving us closer to precision medicine.

There are two main types of neural networks that are well suited for time series data: recurrent neural networks (RNNs) and long short-term memory networks (LSTMs). RNNs are a type of neural network that can handle sequential data, such as time series data. LSTMs are a type of RNN that is specifically designed to remember long-term dependencies. In this project, we will be using a Bi-directional LSTM (BiLSTM) to detect heartbeat anomalies.

A BiLSTM is a type of neural network that is similar to a regular LSTM, except that it has two layers instead of one. The first layer reads the input sequence forwards, while the second layer reads the input sequence backward. This allows the BiLSTM to capture context from both past and future states.

We will be using a BiLSTM Autoencoder to detect heartbeat anomalies. An autoencoder is a type of neural network that is used to learn efficient representations of data. The autoencoder takes an input, encodes it, and then decodes it. The goal is to learn a representation (encoding) that is smaller than the input but still captures the important features of the data. The BiLSTM Autoencoder will take in a sequence of ECG readings and output a single anomaly score. If the score is above a certain threshold, then it will be classified as an anomaly.

No alt text provided for this image

So where do we start?

First, we enter the world of Python and we import the necessary libraries. These are Deep learning libraries, like TensorFlow and Keras, as well as some helper libraries like NumPy and Matplotlib.

Next, we will load the data. The data consists of EKGs from different patients. Each patient has two EKGs, one with a normal heartbeat and one with an abnormal heartbeat. This kind of data is annotated by a certified health specialist. Sidebar: This kind of project will often need to be reviewed by an Institutional Review Board.

After the data is loaded, we will need to do some pre-processing. This includes normalizing the data and creating train, validation, and test sets. Once the data is ready, we can start building the model. We will be using a BiLSTM Autoencoder. The first step is to define the model architecture. This includes specifying the input and output layers, as well as the hidden layers. We will also need to specify the loss function and optimizer that we want to use.

No alt text provided for this image

Now, we will define the BiLSTM autoencoder model. This model consists of two parts: the encoder and the decoder. The encoder part of the model will take in the EKG data and compress it into a lower-dimensional representation. The decoder part of the model will then take this lower-dimensional representation and reconstruct the original EKG data.

We will train the model by using the mean squared error loss function. Typically these temporal systems will also use the Adam optimizer and early stopping to prevent overfitting. Once the model is trained, we will also evaluate it on the test data. If the model achieves a high degree of accuracy on both the training and test data, this shows that the model is able to generalize well to new data. While this seems straightforward, getting to this point can be difficult.

There are many factors that can affect the performance of a deep learning model, such as the data, the model architecture, the loss function, the optimizer, and the hyperparameters. In order to build a robust model, we need to experiment with different configurations and find the one that works best for our data.

Now the model is ready to make predictions on new EKGs. We will start by loading normal EKGs and EKGs with arrhythmia previously unseen during the training process. The model predicts that the probability of the EKG is normal. Low probabilities indicate higher levels of abnormalities, such as arrhythmia.

No alt text provided for this image


While this approach is not sophisticated enough to be used to treat patients, it could be used in an advisory capacity. For example, if a patient has an EKG that is flagged as being abnormal, they could be sent to a cardiologist for further testing and treatment. It should be used by payers, like Cigna and Aetna, as a means to reduce or eliminate future treatment costs. This approach could also be used on a larger scale to screen for heart anomalies in the general population. For example, ECGs could be collected from people at risk for heart disease and those with abnormal ECGs could be referred for further testing.

Heartbeat anomaly detection is a difficult task, but by using deep learning, we can build models that are more accurate than traditional methods. BiLSTM is a powerful tool that can be used to detect heart anomalies from EKGs with a high degree of accuracy. This approach has the potential to save lives by helping to detect heart abnormalities early.


POST PUBLISHED ARTICLE FEEDBACK:

One of the comments noted that the Mayo Clinic developed a similar model. This is true. They are actively involved with modeling heart failure (HF) and acute heart failure (AHF). Their work is one of 47 or so prior or ongoing efforts to use neural networks in this area. Here is a link to their study.

The Mayo Clinic's HF development is based on a Recurrent Neural Network (RNN), which is the category in which LSTM resides. LSTM units include a 'memory cell' that can maintain information in memory for long periods of time. This memory cell lets them learn longer-term dependencies.?

RNNs are also capable of learning long-term dependencies, but they have difficulty doing so because they forget information quickly.?LSTMs solve this problem by using the memory cell to keep information in memory for longer periods of time.?

In the future, Transformers will most likely replace both LSTM and RNN. Training LSTMs is harder when compared with transformer networks. Moreover, it's impossible to do transfer learning in LSTM networks.

Rick Schlueter ??

I.T. Project Manager - I.T. Manager

2 年

I'm putting this out there - Cigna Fail Again - I wanted to go to the top and tell you how bad the services have been. I’m dealing with a needed back surgery authorization; when asked for a supervisor, they told me no. My surgery is scheduled for tomorrow at 1 pm PST, and I need your help, please. MY doctor’s assistant had called several times and had over 3 hours invested.? This is crazy, I'm not a cookie-cutting guy, I've had these issues going on for years and have had several fusions but the disk above or below the fused areas keeps blowing out; we've tried everything except a magic wand

Great effort to use technology for benefit of the humankind. Some challenge i see is on baseline creation for anomaly detection. Every individual would typically have different patterns during different times of the day / activity involved. Further across different people also it varies. These variations are sometime so complex that even cardiologists get confused unless very experienced (e.g. athletic heart). Need to figure out such challenges or define assumptions clearly.

Dr. Jerry A. Smith

Hands-On Transformative AI Leader | Architect of Generative AI & Neuroscience-Inspired Systems | $500M+ Value Delivered | VP of AI Strategy, Innovation, and Enterprise Transformation | Pilot & Nuclear Engineer

2 年

I chatted with Shail Jain (who is brilliant and was almost my boss a long time ago) about the model. He pointed out Mayo developed a similar model. Of course, he was correct :) Their work is one of 47 or so prior or ongoing efforts to use neural networks in this area. Here is a link to their study: https://www.mayoclinic.org/medical-professionals/cardiovascular-diseases/news/artificial-intelligence-enabled-ecg-screening-for-asymptomatic-left-ventricular-dysfunction/mac-20462666 The Mayo Clinic HF development is based on a Recurrent Neural Network (RNN), which is the category in which LSTM resides. LSTM units include a 'memory cell' that can maintain information in memory for long periods of time. This memory cell lets them learn longer-term dependencies.? RNNs are also capable of learning long-term dependencies, but they have difficulty doing so because they forget information quickly.?LSTMs solve this problem by using the memory cell to keep information in memory for longer periods of time.? In the future, Transformers will most likely replace both LSTM and RNN. Training LSTMs is harder when compared with transformer networks. Moreover, it's impossible to do transfer learning in LSTM networks.

Dr. Jerry A. Smith

Hands-On Transformative AI Leader | Architect of Generative AI & Neuroscience-Inspired Systems | $500M+ Value Delivered | VP of AI Strategy, Innovation, and Enterprise Transformation | Pilot & Nuclear Engineer

2 年

Francisco Arabia Of all the people I know, you being a leading Cardiothoracic Surgeon, one whose hands I would want in my chest if ever I had a problem. What do you think?

Dr. Jerry A. Smith

Hands-On Transformative AI Leader | Architect of Generative AI & Neuroscience-Inspired Systems | $500M+ Value Delivered | VP of AI Strategy, Innovation, and Enterprise Transformation | Pilot & Nuclear Engineer

2 年

要查看或添加评论,请登录

Dr. Jerry A. Smith的更多文章

社区洞察

其他会员也浏览了