Performance Analysis of Machine Learning Algorithms for Classifying Hand Motion-Based EEG Brain Signals

Brain-computer interfaces (BCIs) records brain activity using electroencephalogram (EEG) headsets in the form of EEG signals; these signals can be recorded, processed and classified into different hand movements, which can be used to control other IoT devices. Classification of hand movements will be one step closer to applying these algorithms in real-life situations using EEG headsets. This paper uses different feature extraction techniques and sophisticated machine learning algorithms to classify hand movements from EEG brain signals to control prosthetic hands for amputated persons. To achieve good classification accuracy, denoising and feature extraction of EEG signals is a significant step. We saw a considerable increase in all the machine learning models when the moving average filter was applied to the raw EEG data. Feature extraction techniques like a fast fourier transform (FFT) and continuous wave transform (CWT) were used in this study; three types of features were extracted, i.e., FFT Features, CWT Coefficients and CWT scalogram images. We trained and compared different machine learning (ML) models like logistic regression, random forest, k-nearest neighbors (KNN), light gradient boosting machine (GBM) and XG boost on FFT and CWT features and deep learning (DL) models like VGG-16, DenseNet201 and ResNet50 trained on CWT scalogram images. XG Boost with FFT features gave the maximum accuracy of 88%.


Introduction
Amyotrophic lateral sclerosis (ALS) is a growing disease related to the nervous system that attacks nerve cells in the brain and disturbs muscle movement control. It is one of the rapidly spreading diseases as the symptoms of this disease get worse over time. Currently, medical science has no efficient treatment for this disease. Thus, it is highly desirable to detect it at an early stage. BCI offers patients with ALS and other neurological disorders to control prosthetic hands, wheelchairs, etc. [1]. Brain-controlled wheelchairs can improve the quality of life of an individual suffering from ALS. BCI has numerous other applications like controlling mouse cursors using imagined hand movements [2]. It used only one channel EEG signal to control a mouse pointer; this study uses eye blinks to switch between cursor movements like linear displacement. Spinning uses attention level to modulate the cursor's speed. It can also be used to classify inner speech; Kumar and Scheme [3] proposed a deep spatio-temporal learning architecture with 1D convolutional neural networks (CNNs) and long short-term memory (LSTM) for the classification of imagined speech. There are two types of techniques to measure brain signals, invasive and non-invasive procedures. First, electrodes are placed within or on the surface of the cortex and in the second, electrodes are placed on the scalp of the head. EEG is a noninvasive technique to measure brain signals using EEG headsets; these headsets have electrodes placed on the scalp of the head. The most challenging part is to extract brain commands from the brain signals as these signals have a low signal-to-noise ratio (SNR). The feature extraction method removes the features from raw brain signals and uses machine learning algorithms to classify them. BCIs measure brain activity using different techniques, analyze it, extract essential features and convert those features into commands that can control output devices like prosthetic hands, wheelchairs, IoT devices, etc. [4]. After reading brain signals, it will be processed and features will be extracted using different feature extraction methods like FFT and CWT. Using these features, brain commands will be extracted out using sophisticated ML models [5]. Once the brain commands are received, they will be directed towards the IoT devices that need to be controlled, in our case, its prosthetic hands and this is how the patient will be able to use BCI. The most challenging part of this project will be to extract brain commands from EEG Signals as EEG Signals have low SNR. Therefore, two types of noise are coming into the picture: external and internal noise (user-induced noise) [6]. These signals can be removed using signal processing and feature extraction techniques [7].
This study used a publicly available EEG dataset with events like hand motions and compared different ML models like logistic regression, random forest, KNN, light GBM and XG boost on FFT and CWT feature extraction methods. In addition, some deep learning (DL) approaches like VGG-16, DenseNet201 and ResNet50 are also used here. This study used different metrics like precision, recall, F1-score, support and accuracy to compare these ML and DL models. To progress this research, it is decided to use publicly available data from Kaggle, which have events like hand movements. This dataset was used in mind that the methods and machine learning algorithms we will be using can later be used for the wheelchair control dataset. The dataset used in this study was already epoched and pre-processed; we applied moving average filter as a processing technique and feature extraction methods like FFT and CWT. The main aim of this paper is to create brain-controlled interfaces for patients who have ALS. With the help of EEG headsets, patients will control IoT devices, wheelchairs, etc.

Literature Survey
Alam et al. [8], in 2021, used the power spectral density (PSD) feature extraction technique on Graz BCI competition IV dataset 2b and a significant increase in classification performance was observed. The classification was done between two classes of motor imagery left-hand and right-hand movement. Linear discriminant analysis (LDA) classifier gave 0.61 Cohen's Kappa accuracy [8].
İşcan and Nikulin in 2018 used SSVEP-based BCI parallelly during the conversations as some subjects' perturbations resulted even in better performance. For example, the decision tree gave excellent results (>95%) when compared with K-NN and naïve Bayes algorithms [9].
Narayan et al. [11] in 2021 applied different machine learning algorithms like support vector machine (SVM), LDA and multi-layer perceptron (MLP) classifier on EEG dataset acquired from 20 subjects; the data was pre-processed and followed by feature extraction and classification, it was found that SVM gave the best classification accuracy of 98.8% [11].
Lazarou et al. [12] in 2018, proposed an EEG-based BCI system for oneself with motor impairment for communication and rehabilitation like TTD system, Graz BCI system, web browsers, game applications, cursor movement system, virtual environments, speller systems like P300 and control of external applications [12].
Chaurasiya et al. [13], in 2015, applied the SVM classification technique to obtain an accurate and quick solution for the detection of target characters linked with the P300 speller system for BCI. This system needs the least pre-processing and gives a considerable transfer rate, fitting online analysis [13].
Zhang et al. [14], in 2020, used a deep attention-based LSTM network to classify hand movements using EEG and deployed LSTM to identify left/right-hand movement [14]. In addition, LaRocco et al. [15] in 2020 detected drowsiness with EEG headsets.
Bilucaglia et al. [16] analyzed previously recorded EEG activity while healthy participants were provided with emotional stimulation and high and low stimuli (auditory and visual). His target is to classify signal that was to initiate pre-stimulus brain activity. This paper compared three classifiers, namely, KNN, SVM and LDA using temporal and spectral features. Bilucaglia et al. [16] conclude that temporal dynamic features give better performance in terms of accuracy. Additionally, SVM with temporal features achieved 63.8% classification accuracy.

Methodology
This study uses different feature extraction methods and machine learning models to predict the probability of fist motion on EEG records. The dataset consists of already epoched EEG data for 19 electrodes which were then processed using moving average for noise removal; different feature extraction methods are applied like FFT [17] and CWT [18]. Two types of data were generated from the CWT feature extraction method, i.e., CWT coefficients as features and CWT signal spectrum image as a feature. On these features, different machine learning models were trained and compared. The overall workflow for EEG data analysis is shown in Fig. 1.

Dataset Description and Visualization
The  EEG data used in this research have opted from BCI EEG data analysis (NEUROML2020 class competition) [20].
Dataset snapshot of BCI EEG epoched signals is shown in Fig. 3; these recordings contain three events: event-1: resting-state, event-2 and event-3: hand motions. We generally get a continuous EEG signal from these headsets, which are further pre-processed and split into epochs. Dataset opted in this study is already epoched, because of which column named epoch is given (having epoch number) with the corresponding column named condition (1, 2 or 3). Each epoch is of size 81 which is shown in time column (0, 1, 2, 3….80, 0, 1, 2, 3….80 etc.).
This data was already pre-processed, though it was not mentioned in the EEG data description. EEG raw data pre-processing includes removal of DC component and it is usually done before epoching. Specifically,  we removed the DC component by calculating the mean and subtracting it from the EEG readings (datamean), which gave us a negligible mean, implying that the data was already pre-processed.
Here, BCI EEG data was visualized for each electrode to differentiate between the conditions. The mean of all epochs for condition one was plotted for all the 19 electrodes during the epoch period of 80 s, similarly grouped for second and third conditions, representing hand motions as shown in Fig. 4. These visualizations distinct the two conditions, i.e., hand movement and no hand movement (steady-state). Figure 4: Left visualization is for condition 1 (steady-state) and right visualization is for condition-2 and 3 (hand motions)

Data Processing
The moving average is one of the most common approaches used to capture significant trends in time series data. In addition, a finite impulse response (FIR) filter is used for a set of time-series data points by comparing different subsets of time-series data sets.
EEG brain signals can also be seen as a time series; therefore, moving average is used to remove the EEG signals' artifacts and noise, as shown in Fig. 5.

FFT Feature Extraction
Frequency domain features were extracted using FFT, a widespread feature extraction method [17] for raw EEG signals.
The considered dataset consists of EEG signals in the time domain and any time-dependent signal can be subdivided into a collection of sinusoids that can represent a single frequency. FFT converts the signal from the time domain to the frequency domain. Therefore, we can extract all the frequencies (sin waves) from which the signal is composed (ex: after performing the FFT, the raw EEG signal gave the frequencies: 2 Hz, 2.3 Hz, 13 Hz and 20 Hz). There are several types of brain waves, as shown in Fig. 6.
After applying FFT on raw EEG, we can use frequencies to say which waves dominate a specific event. We compared the bands for both the conditions (i.e., steady-state and hand motions).
As shown in Fig. 7, results show an increase in theta and alpha bands when the subject moved a hand. This concludes that the person goes from unconsciousness to consciousness when he does some action, i.e., hand motions.
Using the FFT feature extraction method, 180 epochs data were obtained; we calculated delta, theta, alpha and beta EEG band values for each channel. We took the standard deviation for each channel as an expected value. This makes a total of 19x4x2 = 152 Features, as shown in Fig. 8.

CWT Coefficient Feature Extraction and Scalogram Images
CWT feature extraction method applies inner products to estimate the pattern match between morlet wavelet (ψ) and EEG signal. CWT analyzes the EEG signal to stretched and shifted versions of compressed morlet wavelets. For a scale parameter, a > 0 and position, b, the CWT given by Eq. (2): In this study, we trained our machine learning model in this CWT Coefficients. As a result, we obtained 128 Features from CWT coefficients for each epoch, as shown in Fig. 9.
To apply CNN [22], we used scalogram images obtained from CWT coefficients, as shown in Fig. 10. These images are of dimension 32x81, where we used 32 CWT features and 81-time points of an epoch. We extracted images for each channel of each epoch which generated a total of 19x180 = 3420 images.
Light GBM trained on FFT features and CWT features have the following parameters: objective = binary, tree learner = data, number of leaves = 99, learning rate = 0.1, bagging fraction = 0.8, bagging freq = 1, feature fraction = 0.8, boosting type = gbdt and metric = binary logloss. The random forest model, trained on FFT Features, has criterion=entropy, min samples leaf = 5, min samples split = 2 and several estimators = 700 and for CWT features, it is criterion=gini, min samples leaf = 5, min samples split = 2 and number of estimators = 400.
XG Boost, which is trained on FFT features, has an objective of binary logistic with the number of estimators = 10 and the model trained on CWT features has the same objective but with the number of estimators = 20.
For classifying CWT scalogram images, pre-trained models like VGGnet-16, DenseNET201 and ResNet-50 were used with weights of the ImageNet. The model inputs a 32x81x3 input, where 32 are CWT features extracted and 81-time points. This image was provided to pre-trained models and subsequently passed through dense layers of 512 nodes for VGGnet and Resnet-50 and two 512 nodes layers in case of DenseNet201, Dropout of 0.5 was applied to avoid overfitting of data. Tab. 1 illustrates parameters for considered models with architecture mentioned in Section 2.5.

Result Analysis
This study's overall objective is to develop a robust and accurate workflow to predict hand motion and rest state. Our study presented the processing of EEG signals using the moving average method, two feature extraction techniques, i.e., FFT feature extraction and CWT feature extraction. Different machine learning models like the random forest, logistic regression, KNN, Light GBM and XG Boost for FFT features and Tab. 3 shows the accuracy obtained for different machine learning models on CWT.

Conclusion and Future Scope
In this study, different feature extraction methods and ML models have been used to predict the probability of fist motion on EEG records. Various feature extraction methods are applied, like FFT and CWT, on the dataset. On these features, different machine learning models were trained and compared. XG Boost and logistic regression models performed well in FFT features and achieved 88% and 83% accuracy, while XG Boost and KNN performed equally for CWT features with 74.85% and 73.34%. For  CWT scalogram images, ResNet50 performance is better than the VGG-16 as it gave an accuracy of 85%. This study shows that XG Boost trained on FFT Feature Extraction with Moving Average Filter as the signal processing technique gave the highest accuracy for the dataset of about 88%. To create BCI for ALS patients, we need a large EEG dataset. This dataset can also be created on our own using EEG headsets. It can be further extended towards brain-controlled wheelchairs for patients who have ALS or other BCI applications. Once brain commands have been detected, it will direct it towards the IoT devices such as prosthetic hands and this is how the patient will be able to use BCI.