Detection of Epileptic Seizure using Deep Learning Technique

By Richa Bhatia, Computer Engineering, VESIT

What is EEG?

Electroencephalography ( EEG) is a method of electrophysiological monitoring to record activities of the brain. It is a non-invasive method in which electrodes are placed along the scalp. Brain cells communicate with each other through electrical impulses, An EEG can be used to help identify possible issues relevant to this operation of the brain. 

During EEG electrodes with wires are attached to one’s head. This electrode detects the brain waves and the EEG machine amplifies it and later the wave pattern is recorded on screen or paper. Most commonly used for evaluating the form and origin of seizures.

What is Epilepsy?

  • Epilepsy is a neurological disorder in which brain activity becomes abnormal resulting in the exhibition of seizures, unusual behavior, sensations, and loss of consciousness. 
  • Epilepsy causes recurrent seizures without any provocation. 
  • The two main types of seizures include focal and generalized seizures. 
    • A focal seizure is those which start at a particular part of the brain and are named after the origin. They result in both physical and emotional effects.
    • Generalized seizures are those in which the brain misfires and result in muscle spasms and blackouts.

Dataset Used

It has 2 parts:

  1. Features
    1. There are different files containing recordings of brain activity up to 23.6 seconds.
    2. The whole recording of 23.6 seconds is sampled into 4097 data points.
    3. Chunks of 23 data points are made to form a single datapoint.
    4. And Therefore after processing EEG signals, 178 features are obtained.
  2. Label Class:
    1. The classification done is binary
      1. detection of epileptic seizure
      2. an absence of epileptic seizure

LSTM

Architecture

In the domain of Deep Learning techniques, to prevent the complication of vanishing gradient  LSTM an artificial RNN architecture is used widely.

Fig. 1. Architecture of LSTM

The data and knowledge passed on the cell state is decided by the gates.

LSTM Architecture is expressed using three different types of gates

  1. Forget Gate:
    1. The Sigmoid function is loaded with data from preceding hidden state and current input state.
    2. The value close to 0 indicates that the value from the previous cell state should be forgotten and value close to 1 indicates that it should be kept.
    3. Let’s say the output(f)
  2. Input Gate:
    1. The Sigmoid function is loaded with data from preceding hidden state and current input state.
    2. Let’s say the output(u)
    3. It indicates which values to be used from the input.
    4. The Sigmoid function is loaded with data from preceding hidden state and current input state.
    5. Let’s say the output(c'<t> )
    6. The results from tanh function are amplified by results from sigmoid function as it helps in making decisions regarding the value which should be fed further for execution. (let say X).
    7. Now the cell state is ready to be updated.
    8. The previous cell state is multiplied with the output from forget gate and then edition is done with X which updates the cell state to new Values.
    9. Let’s say the output(c<t>)
  3. Output Gate:
    1. It decides what the next hidden state should be.
    2. The Sigmoid function is loaded with data from preceding hidden state and current input state.
    3. Let’s say the output(o)
    4. The newly updated value of cell state is loaded into tanh Function.
    5. Now the results from tanh function are amplified by results from sigmoid function which provides with the hidden state for following LSTM Model.
    6. Let’s say the output(a<t>)
Equations

The Following are the equations for forward pass of an LSTM.

a<t-1> : previous hidden state.

x<t> : content input.

Wq : weight matrices where q can be u for input gate, f for forget gate, c for memory cell.

Implementation
ParametersValue
Loss FunctionBinary cross entropy
OptimizerAdam
Dropout0.5
Epochs100
Batch size128
MetricsAccuracy
Table 1. Parameters used to create LSTM Model
Fig. 2. Four Layer LSTM cell network architecture

Our model has 4 LSTM Layers with a dropout of 0.5 at every layer. The dense layer finally results in the output list of probabilities with ideally 100% for the output class and 0% for the other class.

Results and Analysis

Loss Function and Accuracy are method of evaluation that estimates how well a specific algorithm or model performs. 

Results obtained by splitting the dataset into training and testing in the ratio of 70 and 30 and by performing 10-fold cross validation for classifying the dataset into epileptic or not epileptic 

  1. 70-30 validation technique
Fig. 3. loss vs epochss for 70-30 validation technique
Fig. 4. accuracy vs epochs for 70-30 validation techniques
Fig. 5. Confusion matrix for 70-30 validation technique
  1. 10-fold cross validation technique
Fig. 6. loss vs epochs for 10-fold cross validation technique
Fig. 7. accuracy vs epochs for 10-fold cross validation technique
Fig. 8. Confusion matrix for 10-fold cross validation technique

A confusion matrix is a table that compares the actual values to the predicted values, therefore evaluating the performance of the classifier on test data to which the true values are known

Here, Validation loss has deviated from training loss but the deviation is not too much which indicates our model is not overfitted.

Also they are no overlapping, which indicates our model is neither underfitted.

Our model has accuracy 98% which indicates an overall performance of our model to be quite accurate and satisfactory.

Validation Technique Accuracy (%)  Precision (%)  Recall (%)  F1 score (%)  
70 and 30 ratio 98.029097.4085 92.6087 94.9480 
cross validation 98.000096.7480 93.130494.9047
  Table 2. Performance Metrics for LSTM Model

CNN

Architecture

The Convolutional Neural Network (CNN) is class of Deep Neural Network, most widely used for working with 2d image data, although it can be used to work with 1d and 3d data also. CNN was inspired from the biological process and its architecture is similar to the connections between the neurons in the human brain. The name CNN refers to the network using a mathematical operation called convolution. Convolution is a linear operation and the networks are essentially neural networks, which use convolution in at least one of their layers instead of general matrix multiplication. 

Fig.9. Architecture of CNN model

The CNN model consists of an input layer and output layer and 4 hidden layers which has a dense layer.

Implementation

Our CNN model is a 1 dimensional fully connected sequential model with an input layer an output layer and 4 hidden layers which has one dense layer. SoftMax and ReLu were used as the activation functions and Adam as the optimizer. Compilation of the CNN model was done by specifying the loss function as “categorical_crossentropy” and evaluation metric as “accuracy”. Training of the CNN model was done with batch-size equal to 16 for 15 epochs. When validated with the test set, an accuracy of 98.19% was obtained. 

Results and Analysis
70-30 validation technique
Fig. 10. loss vs epochs for 70-30 validation technique
Fig. 11. accuracy vs epochs for 70-30 validation techniques
Fig. 12. Confusion matrix for 70-30 validation technique
10-fold cross validation technique
Fig. 13. loss vs epochs for 10-fold cross validation technique
Fig. 14. accuracy vs epochs for 10-fold cross validation technique
Fig. 15. Confusion matrix for 10-fold cross validation technique
Validation Technique Accuracy (%)  Precision (%)  Recall (%)  F1 score (%)  
70 and 30 ratio 98.72 96.64 97.65 97.14 
cross validation 99.32 91.21 99.71 95.27 
Table 3: For Performance Metrics of the CNN model

Conclusion

The first step in diagnosing a neurological disorder is always to assess if an EEG record indicates irregular or regular brain activity. Since manual EEG perception is a costly and time-consuming process, any classifier automating this first distinction will have the capability to minimize delays in treatment and alleviate the caregivers. So, we have introduced a novel LSTM and CNN architecture designed to be flexible and adaptable and therefore suitable for the analysis of EEG data and to diagnose precisely whether or not a person is suffering from Epilepsy.

References

  1. Epileptic Seizure Recognition
  2. Emotion recognition using fourier transform and genetic programming
  3. Doma, Vikrant & Pirouz, Matin. (2020). A comparative analysis of machine learning methods for emotion recognition using EEG and peripheral physiological signals. Journal of Big Data. 7. 10.1186/s40537-020-00289-7.

This project was done under the guidance of Ms .Divya Acharya(Bennett University)

Team Members:

  1. Richa Bhatia(Vivekanand Education Society’s Institute of Technology)
  2. Varsha Shaju(Vidya  Academy of science and Technology)
  3. Anushna Gowreddygari(VNRVJIET)
  4. Aparna.S(Saintgits college of Engineering)
  5. Gunapati Adi Lakshmi(R.V.R&J.C College of Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *