Detection of epileptic seizure in EEG signals using machine learning and deep learning techniques

Around 50 million individuals worldwide suffer from epilepsy, a chronic, non-communicable brain disorder. Several screening methods, including electroencephalography, have been proposed to identify epileptic episodes. EEG data, which are frequently utilised to enhance epilepsy analysis, offer essential information on the electrical processes of the brain. Prior to the emergence of deep learning (DL), feature extraction was accomplished by standard machine learning techniques. As a result, they were only as good as the people who made the features by hand. But with DL, both feature extraction and classification are fully automated. These methods have significantly advanced several fields of medicine, including the diagnosis of epilepsy. In this paper, the works focused on automated epileptic seizure detection using ML and DL techniques are presented as well as their comparative analysis is done. The UCI-Epileptic Seizure Recognition dataset is used for training and validation. Some of the conventional ML and DL algorithms are used with a proposed model which uses long short-term memory (LSTM) to find the best approach. Post that comparative analysis is performed on these algorithms to find the best approach for epileptic seizure detection. As a result, the proposed model LSTM gives a validation accuracy of 97% giving the most appropriate and precise result as compared to other mentioned algorithms used in this study.


Introduction
Epilepsy is a persistent, non-communicable brain condition.A hereditary condition or an acquired brain disorder, such as a trauma or stroke, may cause epilepsy.A person who is having a seizure exhibits strange behaviour, symptoms and sensations, sometimes even losing consciousness.According to the most recent assessment by the World Health Organization (WHO), around 50 million people worldwide experience epileptic seizures, and the majority of them are unaware of their illness.
Most of the time seizure attacks are the cause of accidents.Seizures are a result of excessive electrical discharges in a group of brain cells.A patient who has a seizure attack for more than 5 min needs to be medicated as soon as possible, but due to the lack of knowledge about this condition, it is not treated at early stages.It is not possible to treat any brain-related condition just by observing the patient.The ionic current passing through the brain neurons is observed using electroencephalogram (EEG) which provides a graph of temporal and spatial information about the brain.However, it is challenging to obtain comprehensive information about these dynamic biological signals due to the non-linear and non-stationary nature of EEG signals.
Depending on the seizure characteristics, epilepsy has various types of epilepsy seizures [1].In recent years, treatment of epileptic seizures is possible due to advancements in the medical field, but still, detection and classification of epileptic seizures are tedious tasks without using automation that can be done using various machine learning and deep learning techniques.Also, there are different times to observe patient brain signals.Using various ML and DL techniques on EEG signal data to detect seizure helps to get insights into a patient's brain condition more preciously.
There is a lot of work done in this domain already, but most algorithm fails to get validation accuracy and other model performance parameters.Also, the implemented model sometimes fails because of a lack of dataset.
The proposed system is intended to solve the problem of automation in epileptic seizure detection.The proposed model uses LSTM to detect seizure patients or normal persons by considering observations from the UCI-Epileptic Seizure detection dataset.Also, the designed system matches the research gaps in this area by providing a more accurate classification of the signal into two categories.
The proposed model is implemented by considering various ML algorithms and deep learning algorithms and their performance on the UCI dataset, so that the validation accuracy can be increased by observing other models' performance.The detailed comparison of machine learning and deep learning models is done with a proposed model to solve many problems.

Related work
Various papers were studied to know about the research done in the area.Some of the important surveys and techniques are explained below: In [2], a survey on scalable technologies assisting in early screening and predictive analysis for lifestyle diseases is done.Study [3] explores various forms of artificial intelligence on large volumes of data in medical technology.In [4][5][6], various studies explored that machine learning and deep learning techniques have been efficiently used for enhanced medical innovations.In the paper [7], the authors proposed a system which uses empirical mode decomposition (EMD) and extracted time and frequency domain features for extracting features from EEG signals.The CHB-MIT dataset is used here.The model has given a higher true-positive rate of 92.23%, and the average prediction time is 23.60 min on the scalp for all subjects in the dataset.
In the paper [8], emphasis is placed on computational complexity, and other models are also compared by systems with multiple classifications.The three main basic parts are as follows: the first one is feature extraction, the second one is hierarchical attention layer and the last is classification layer.Three scenarios were used to evaluate this system: based on combinations of interictal, preictal and ictal.In the paper [9], the author proposed a system focused on feature extraction and classification.The model used Taylor Fourier, rhythm-specific and filter bank for preprocessing and at the end feature extraction and classification SVM used.The model achieved an accuracy of 94.88%.The Bonn University Database is used here.In the paper [10], using a corpus of EEG data from Temple University Hospital, the authors applied CNN and transfer learning to categorise seven variations of seizures with non-seizure EEG.This study's goal is to carry out a multiclass categorisation.Before being fed as input to CNN, the signal was transformed into a spectrogram.To choose the best network for the given study, many DL pre-trained networks were employed.82.85% (Googlenet) and 88.30% (Inceptionv3) are the best categorisation accuracy models used in this study.In this system [11], to examine alternative model assessment parameters, two fusion methods were considered: the first one is ensemble, and the second one is Choquet fuzzy integral used with the deep neural network used in the system.In the paper [12], a singular value decomposition fuzzy k-nearest neighbour classifier methodology based on discrete wavelet transform offers about 100% accuracy and nearly about 93.33% on two and three classes using the Bonn University Dataset.In [13], the authors categorise EEG data into ictal and interictal types.The primary problem here is the non-stationary and non-linear character of the EEG signal while attempting to understand brain output.The main emphasis is on feature extraction from seizure EEG recordings to create a method for epileptic seizure identification on the CHB-MIT dataset that uses both fuzzy-based and conventional machine learning techniques.In [14], the authors suggest using deep learning to identify seizures in paediatric patients.To implement the supervised classifier, the CHB-MIT dataset is used to classify ictal and interictal brain state signals.Two-dimensional deep convolution auto-encoder connected to a neural network.The paper [15] intended to use the principal components analysis used for the feature reduction approach to the signals in order to obtain the optimum classification algorithm for epileptic seizures.Using the dataset to predict epilepsy, KNN, RF, SVM, ANN and DT algorithms are used, and the performance of classifiers is examined both with and without PCA.This paper [16] reviews different deep learning algorithms with CNN for 1D CNN, 2D CNN, CNN using transfer learning and LSTM.The author reviewed different approaches for each technique in which the CNN and LSTM were showing significant accuracy of around 99%.The different dataset was considered CHB-MIT, BON, Flint Hills and Bern Barcelona.The paper [17] presents a model which solves the issues of data imbalance, low accuracy and classification model with sampling techniques including downsampling, random sampling and the synthetic minority oversampling technique.The authors proposed the heterogeneous deep ensemble model which gives an accuracy score of 0.93) and an F-measure value of 0.91.The paper's [18] authors say manual observation of EEG is performed to detect epilepsy which makes it difficult and easy to switch over automated diagnosis system.The Bonn EEG Dataset is used.The authors proposed a least squares support vector machine (LSSVM) as a better approach to deal with linear equations with an accuracy of 94.7%.In the paper [19], the authors worked on EEG signal noise removal.The EEG signal gets compromised by background noise or any muscle movement which makes it difficult to detect in automatic mode.After taking this limitation, the paper reviews different automatic approaches which state feature selection and classification are the tedious and error-prone area in epilepsy.In the paper [20], the authors proposed ResNET-50 as an automated system which will define the EEG data into non-ictal, ictal and pre-ictal classes.The CHB-MIT, Freiburg, BONN Dataset and BERN Dataset use CNN by transforming the 2D EEG images from 1D EEG images which give 94.88% accuracy.In the paper [21], the authors proposed CNN for the classification of an epileptic seizure.The proposed model contains four models: the CNN model, fusion of two CNN; fusion of 3 CNN, fusion of 4 CNN model and transfer learning using ResNet 50.The fusion of 3 and 4 CNN models gave significantly best results with 95% accuracy.The two convolution layers with 32 filter and 3 × 3 kernel size are used as a single CNN model which after concatenated for fusion of 2, 3 and 4 CNN models.In the paper [22], the authors proposed a deep neural network with hierarchical attention mechanisms.The system starting layer was of two separate CNN for extracting the feature and connected to the hierarchical attention layer and fully connected layers for classification.The computation time of the proposed model was 0.23 s for classification and 0.014 for feature extraction.In the paper [23], a novel seizure prediction model called TASM ResNet was proposed by the authors.It is based on an intracranial EEG signal-based pre-trained ResNet and a temporal attention simulation module.The simulation module was created to take raw EEG data, transform it into data that resembles images and then extract temporal characteristics.ResNet was utilised in this case to decrease the amount of training data.Additionally, the final outcomes demonstrated that an image network that has been pre-trained on a sizable dataset using a simulation module can migrate EEG signals.

Proposed methods
The proposed system follows the traditional way of model training and testing as shown in Fig. 1.The UCI-Epileptic Seizure Dataset is firstly pre-processed to feed to the model.After dataset pre-processing done, the dataset split into training and testing data.After that model is selected, there are logistic regression, KNN, SVM, ANN and LSTM.Next, the selected model is trained based on UCI training dataset.The testing data is feed to model to get results.Finally, the model was evaluated based on various parameters such as accuracy, confusion matrix, precision, recall and F1 score.

Dataset
The UCI-Epileptic Seizure Dataset is the set of data that is utilised for model performance.The original dataset consists of 100 files in 5 separate folders, each of which corresponds to a particular patient.23.6-s recording of brain activity is stored in each file.A total of 4097 information/data points from the associated time series are sampled.Each data point represents the EEG recording's value at a particular time point.There are 500 people in all, each having 4097 data points.Every 4097 information points, it is split and jumbled into 23 sets, each of which has 178 information points for 1 s and represents the value of the EEG recording at a particular time.As a result, there are now 23 (sets) × 500 (people) = 11,500 informational pieces, each of which comprises 178 information points for 1 s (a column), the last column represents the class as y {1,2,3,4,5}.The dataset therefore has 179 total columns, the first 178 of which are input vectors, and the 179th of which is a categorisation for patients (Table 1).

Dataset preprocessing
The dataset consists of 5 different classes mentioned as follows:

2-EEG activity in the vicinity of the tumour 1-Seizure activity recording
All patients in classes 5, 4, 3 and 2 are those where there is no experience of seizures, according to an analysis of the dataset.The dataset is then encoded using the One-Hot method for binary classification, with all classes except 1 being transformed to 0 to indicate no seizures and 1 to indicate seizure sufferers.

ML and DL model selection
As the part of comparative study, there are a total of five models compared based on model evaluation parameters.Logistic regression, SVM classifier and KNN are traditional machine learning algorithm; as there is binary classification, these models were selected.The artificial neural network was used for complex analysis, and the last model was the LSTM-based neural network; with this model, other models were compared.

Model 1: Logistic regression
The regression algorithm for binary classification is used for detecting seizure activity.The model used test spilt as 33% of the dataset for validation.The training accuracy of the model is 66.92%, and the validation accuracy is 63.9%.Using validation data, as shown in Fig. 2, the true-negative value percentage was 67.17%, true-positive Fig. 2 Logistic regression confusion matrix 0.0%, false-positive rate 32.83% and false negative 0.0%.As the confusion matrix is shown in Fig. 2, the classes are not perfectly classified, and it is not useful for this classification task.

Model 2: SVM
For binary classification, SVM is used.The model is trained on 67% of the dataset.The validation accuracy is 97.2%, and the training accuracy is 98.09%.The model has a 0.0% true-positive classification on validation data.As shown in Fig. 3, false positive 19.10%.The true negative was 80.90%, and the false negative was 0%.The validation data is 720 rows as positive class and 3025 as negative class.As the confusion matrix is shown in Fig. 3, the classes are not perfectly classified, and it is not useful for this classification task.

Model 3: K-nearest neighbour
The KNN is used for the classification of seizure activity.The neighbour value is 5, and the distance formula is Euclidean distance.The training accuracy of the model is 93.61%, and the validation accuracy is 91.96% based on 33% data of the dataset.Using validation data, the true-negative percentage was 87.59% and the true positive as 0.0%.The false-negative value is 0.0%, and the false-positive value is 12.41% as shown in Fig. 4. As the confusion matrix shown in Fig. 4, the classes are not perfectly classified, and it is not useful for this classification task.

Model 1: Artificial neural network (ANN)
The multiple-layer ANN model is implemented with four layers.The input shape for the model was 178.1 that is 178 data points.The first, second and third, layers with 32 neurons and Relu is the activation function, and the fourth layer with 2 neurons with softmax is the activation function.Adam optimiser was used as a model optimiser.Binary cross entropy is used as loss as there is binary classification.The total trainable parameters are 7906.The model is trained on 67% data.The model training accuracy was 98.9%, and the validation accuracy was 97% which is tested on 33% of testing dataset.It was observed a sudden increase in training accuracy while training the model after the first epoch from 0.91 to 0. 96% and a slow increase in accuracy shown in Fig. 5.
The training loss is 0.03, and the validation loss is 0.08 as shown in Fig. 6.Based on validation data, the confusion matrix is shown in Fig. 7.
True negative (TN) is 78.89%, true positive (TP) is 18.16%, false positive is 0.81% and false negative is 2.13%.The model validation values for negative class (no seizure) precision were 0.97%, recall 0.99% and F1 score 0.98% and positive class (seizure activity) precision 0.96%, recall 0.89% and F1 score 0.92%.The total number of negative class data rows is 3025 and the positive class 770.As the system works for the medical domain, there is importance to the false-negative value which looks effective in ANN, so using the ANN model for this task is not that much good choice.

Model 1: Proposed model-long short-term memory
The multiple-layer LSTM model is implemented with three layers.The input shape for the model was 1178 that is 178 data points.The first LSTM layer with 64 neurons  The training loss is 0.006, and the validation loss is 0.106 as shown in Fig. 9. Based on validation data, the confusion matrix is shown in Fig. 10.   2, the positive class (seizure activity) have 770 rows for validation and 3025 as a negative class (no seizure).The logistic regression achieves training and validation accuracy of 66.92% and 63.9%, respectively, comparatively less than the SVM used on the same dataset.Similarly, with precision, the F1 score and recall value in the logistic regression algorithm show very less effect in seizure classification.Refer to the confusion matrix of SVM shown in Fig. 3

Conclusions
As the proposed system intended to classify the healthy person's brain EEG signal and seizure patient brain EEG signal, the system classifies the signal data with the LSTM model with a validation accuracy of 97% and false negative 2.06%.As shown in Table 2, the conventional machine learning algorithms logistic regression, SVM and KNN achieve good accuracy but not work fine in classification.Also, considering the ANN achieves good model evaluation parameters but somewhat less precise in false negative area.In conclusion, the proposed model works better as compared to other models used in this study.The system can be useful in epileptic seizure detection.
The proposed system currently works good in binary classification.There are also types of epileptic seizure that can be detected precisely as it deals with the medical domain.The dataset used in this study is somewhat insufficient to train model, and also dataset is unbalanced as the other categories are converted using one-hot encoding for binary classification.Also, in the proposed model, there is a scope of improvement in the false-negative section.The limitation of the proposed system is that it needs to test for multiclass classification of epilepsy seizures.The similar work has been carried out in [24].Also, work needs to be tested with other datasets like stateof-the-art work [25][26][27].The other alternatives to test the results are to use EEG datasets like CHB-MIT, TUH EEG Corpus and Bonn University with methods like CNN, SofMax and Bi-LSTM to improve false negatives.

Fig. 1
Fig.1General system architecture where model is replaced

Table 1
Sample data from the dataset great training accuracy of 98.09% and validation accuracy of 97.23% but not able to predict classes as shown as true positive.The KNN showed training accuracy and validation accuracy of 93.61% and 91.96%, respectively, but not able to detect classes as the true positive rate is 0.0%.The ANN model was able to classify true-positive rate (sensitivity) value with minimal false positive compared to SVM.ANN shown in Table 2 gives a precision value of 0.96, recall 0.89 and F1 score 0.92 for seizure signals and precision value 0.97, recall 0.99 and F1 score 0.98 for healthy signals.The proposed model LSTM was able to classify more accurately than ANN with very minimal difference in training and validation accuracy.The proposed model was able to achieve 99.88% accuracy on training data and a validation accuracy of 97.1% as compared to ANN validation accuracy of 97.0%.LSTM shown in Table 2 gives a precision value of 0.96, recall 0.90 and F1 score 0.93 for seizure signals and precision value 0.97, recall 0.99 and F1 score 0.98 for healthy signals.Based on the overall comparison, LSTM-based model performs better.