Differentiating Mental Stress Levels: Analysing Machine Learning Algorithms Comparatively For EEG-Based Mental Stress Classification Using MNE-Python

Mental stress is a prevalent and consequential condition that impacts individuals' well-being and productivity. Accurate classification of mental stress levels using electroencephalogram (EEG) signals is a promising avenue for early detection and intervention. In this study, we present a comprehensive investigation into mental stress classification using EEG data processed with the MNE-Python library. Our research leverages a diverse set of machines learning algorithms, including Random Forest (RF), Decision Tree, K-Nearest Neighbors (KNN), Multilayer Perceptron (MLP), Support Vector Machine (SVM), Adaboost, and Extreme Gradient Boosting (XGBoost), to discern differences in classification performance. We employed a single dataset to ensure consistency in our experiments, facilitating a direct comparison of these algorithms. The EEG data were pre-processed using MNE-Python, which included tasks such as signal cleaning, and feature selection. Subsequently, we applied the selected machine learning models to the processed data and assessed their classification performance in terms of accuracy, precision, recall, and F1-score. Our results demonstrate notable variations in the classification accuracy of mental stress levels across the different algorithms. These findings suggest that the choice of machine learning technique plays a pivotal role in the effectiveness of EEG-based mental stress classification. Our study not only highlights the potential of MNE-Python for EEG signal processing but also provides valuable insights into the selection of appropriate machine learning algorithms for accurate and reliable mental stress assessment. These outcomes hold promise for the development of robust and practical systems for real-time mental stress monitoring, contributing to enhanced well-being and performance in various domains such as healthcare, education, and workplace environments.


Introduction
Mental stress, usually referred to as psychological or emotional stress, is a significant problem in contemporary culture.It appears when people believe they can't successfully handle the expectations being placed on them.This view may be caused by a variety of things, including demands at work, academic obstacles, financial difficulties, interpersonal disputes, and life events.If stress is not well controlled, it can seriously harm both a person's physical and mental health.It is associated with a range of health issues, including cardiovascular problems, compromised immune function, anxiety disorders, depression, and reduced cognitive performance.Additionally, chronic stress can contribute to the development of more severe mental health conditions over time [1].Understanding and effectively managing stress are critical for maintaining a healthy and productive life.Traditionally, stress assessment has relied on subjective methods, such as self-reporting through questionnaires or interviews.While these methods can provide valuable insights into an individual's perception of stress, they have limitations like subjectivity, lack of objectivity, inability to capture variability [2].

EEG and Stress Assessment
EEG one of the key methods for brain mapping.About 50-100 billion neurons in the human brain continuously generate electrical impulses.With the aid of an EEG machine, these electrical impulses in the brain can be spatially characterised and recorded.It is a test that logs electrical signals from the scalp to estimate cortical activity.Actually, electroencephalography is the study of the tiny, continuously varying electrical potentials produced by the cerebral cortex.EEG activity is the result of thousands or millions of synchronously active neurons with comparable spatial orientation.EEG measures the electrical activity of the brain, capturing patterns of neural activity associated with cognitive processes, emotions, and stress responses [3,4].When an individual experiences stress, specific EEG patterns may emerge, making EEG a potential tool for objective stress assessment.For example, heightened activity in certain brain regions and changes in brainwave frequencies have been linked to stress.EEG's direct measurement of brain activity with high temporal precision, its non-invasive and safe nature, realtime monitoring capabilities, and sensitivity to cognitive and emotional states make it a valuable tool for objectively evaluating and quantifying mental stress levels.Its potential to identify biomarkers and integrate with machine learning further enhances its effectiveness in stress assessment [5].
Researchers and practitioners have increasingly explored the use of EEG in stress assessment.EEG offers the advantage of being non-invasive, capable of real-time monitoring, and sensitive to subtle changes in brain activity associated with stress.To harness the potential of EEG for stress classification, various machine learning techniques have been applied to analyse EEG data, allowing for more accurate and reliable stress assessment.

Role of Machine Learning in EEG-based Stress Classification
Machine learning's role in EEG-based stress classification is fundamental, as it empowers the automated and precise categorization of stress levels based on patterns discerned within EEG data.One of the key functions of machine learning in this context is feature extraction.EEG data comprises an abundance of data points, making manual analysis impractical.Machine learning algorithms excel at extracting relevant features from EEG data, such as spectral power, coherence, or statistical measures derived from EEG signals.These features capture crucial aspects of brain activity associated with stress [6].
Furthermore, machine learning plays a crucial role in classification.Once machine learning models are adequately trained, they can categorize EEG data into distinct stress categories, such as low stress, moderate stress, or high stress, based on the patterns they have identified.This classification can be conducted in realtime, allowing for immediate and continuous stress assessment, which is essential given the dynamic nature of stress.Personalization is another notable feature of machine learning in this context.EEG patterns associated with stress can vary significantly from person to person [7].Machine learning approaches can adapt and learn an individual's unique stress response, improving the accuracy of stress classification for each individual.
Continuous monitoring of stress levels is facilitated by EEG-based stress classification with machine learning.Stress can fluctuate throughout the day and in response to different situations.Machine learning models are well-suited for providing real-time updates on an individual's stress state, ensuring timely intervention if necessary [8].Integration with EEG-based biomarkers is another strength of machine learning.Biomarkers, such as specific brain regions or frequency bands associated with stress responses, can be seamlessly integrated into machine learning classification algorithms, enhancing the accuracy of stress assessment.
The main goal of this work is to evaluate and contrast the effectiveness of several machine learning algorithms in the context of EEG-based mental stress classification.Specifically, it aims to assess the effectiveness of machine learning algorithms like SVM, Random Forest, Decision Tree, MLP, Adaboost, and XGBoost in accurately classifying mental stress levels using EEG data processed with the MNE-Python library.

Related Work
An overview of prior research on EEG-based stress classification reveals a growing body of work that leverages electroencephalogram (EEG) data to assess and classify mental stress.Several existing methodologies for EEG-based stress classification have been developed and applied in research.
Three different groups of human subjects-normal control, mild cognitive impairment, and dementia-are proposed by the authors [9] to perform four visual-based cognitive tasks to extract distinct neural activity patterns.These tasks are fixation, mental imagery, symbol recognition, and visually evoked related potential.They sought to determine the best cognitive tests for detecting dementia and how to use EEG signals to do it.
The investigators used wearable EEG built into a set of over-ear headphones to calculate the user's cerebral flow during mental arithmetic activities.The effect's magnitude was comparable to what a pupilometer, which is routinely used to gauge cognitive strain, would have yielded.They found that the EEG band power underwent significant changes throughout flow states and other stressful or boring testing conditions [10].Their proposed model outperformed the conventional classifier based on EEG band power in the three-way classification task with an accuracy rate of 65%.In another study [11], brainwaves from 48 participants were used in a simulated driving exercise along with the two-state classification.Feature extraction was done using source space-FC.The beta-band crucial connections SVM model with RFE as the feature selection produced the highest classification result of 93%.The EEG signals for alert and fatigued states were not continual in their study.When the investigation began, the alert signals were gathered from the drivers.When the investigation ended, the fatigue signals were gathered from the drivers.
In order to characterise the pilot's mental states, researchers [12] conducted an exploratory analysis utilising unprocessed EEG data and ensemble learning methods.They also showed how different mental states of the pilot affected physiological signs.They offered a viable strategy for autonomously processing EEG data.The processed data underwent feature extraction, where spatial covariance matrices were constructed and then mapped into the Riemannian tangent space, before moving on to the classification stage.Tangent space vectors were used to train the four ensemble learning models, RF, ERT, GTB, and Adaboost, as well as a hybrid ensemble model.When tested on cleaned EEG data, the suggested method outperformed earlier methods in terms of accuracy, obtaining an accuracy of 86%.Another study's goal is to determine whether an EEG-based ML model can successfully identify common activities including resting, motor, and cognitive processes.For the investigation, 75 healthy volunteers without a history of neurological disorders were examined [13].EEG recordings were made while subjects were at rest, performing the walking and working motor control tests, and doing the reading task.The most crucial EEG spectral properties of HAR models were clinically interpreted using Local Interpretable Model-Agnostic Explanations.Multiple ML models for activity detection were trained using EEG data.The Random Forest and Gradient Boosting models in particular showed great capacity in differentiating the analysed human activities in the classification findings of the HAR models.
The classification of mental stress levels through the study of EEG signals is the topic of the thorough assessment and analysis of published academic articles and research studies that we give in Table 1.EEG is a crucial technique for assessing stress objectively since it records the electrical activity of the human brain.For the purpose of setting the scene and furthering our own study, it is essential to comprehend the research procedures and findings from earlier studies.

Materials and Methods
Four phases are commonly involved in classifying mental states: gathering data, processing it, choosing significant features, and making predictions.In the initial step, brain signals are recorded and digitally transformed.Then, through pre-processing, any unnecessary noise or artefacts present in the data are eliminated to guarantee correct analysis.Next, specific data properties are picked out and retrieved in order to prepare for categorization.A classifier uses these extracted features to determine the class to which the data belongs.We describe the main components of our study in this part, starting with the procedure for gathering data.The experiments were then thoroughly described, and we finished by talking about the techniques for signal analysis and categorization.The theoretical foundations of our suggested methods for identifying mental stress are shown in Figure 1.

Data Acquisition
We investigated one publicly accessible data set [21] in the initial phase of our study.Four people, two men and two women, were observed for 60 seconds in every single one of the three mental states: relaxed, concentrated, and neutral.The 'TP9', 'AF7', 'AF8', and 'TP10' EEG locations were recorded utilising dry electrodes and a 'Muse EEG headband' to acquire the data.

Fig. 2. MUSE EEG Headband Electrode Placement Using the 10-20 Electrode Mapping System
The EEG data collected by the MUSE headband offers a real-time look into the human brain.The electrodes are placed on the scalp at locations "AF7," "AF8," "TP9," and "TP10" in line with the 10-20 electrode positioning method, with a reference electrode at Fpz.The headband is easily adjustable.Figure 2 depicts the MUSE EEG electrode placement using the 10-20 positioning system.

EEG Pre-processing with MNE-Python
An open-source programme called MNE-Python is used to visualise and analyse medical records including MEG, EEG, and ECG.It supports analysis of statistics, machine learning, time-frequency analysis, source estimation, and data pre-processing [22].MNE-Python supports a variety of filtering techniques, including bandpass, low-pass, high-pass, and notch filtering.Finite impulse response (FIR) and infinite impulse response (IIR) filters based on the Fast Fourier Transform (FFT) can be used to filter instances of raw data.
Pre-processing is the initial stage in analysing recently acquired EEG data.Pre-processing entails running the data through filters to bring to light the relevant data.In addition to eliminating irrelevant data from the research, these filtering techniques can also amplify essential data by making it more obvious during data collecting.It is possible to remove general signal noise (background noise), as well as artefacts associated with head movement, eye movement, other muscle movements, and blinking, using EEG filtration techniques.

Data Cleaning and Artifact Removal
Artifacts in EEG signals can occur due to various factors such as muscle movements, changes in the subject's electromagnetic condition, or interference from external electromagnetic signals during EEG data collection and analysis.These disturbances can manifest as noticeable alterations in the recorded signal, and their presence can depend on how sensitive the EEG sensor is.For instance, artifacts can be caused by actions like moving one's head, jaw or eye movements, blinking, or any muscle activity that generates a significant electromagnetic field.[23].
Even changes in the subject's head position can affect their natural electromagnetic field and introduce artifacts, even when the subject is not actively thinking or producing brain activity.Dealing with artifacts involves a process known as artifact removal, where the distorted parts of the EEG signal are replaced with estimates of what the signal would have looked like without the disruption or through other corrective techniques [24].This artifact removal process is crucial for ensuring the quality and accuracy of EEG data in research and analysis.
We have undertaken a crucial data pre-processing step in our EEG data analysis.This involved the careful selection of specific EEG channels from the raw EEG data while also excluding channels that have been identified as "bad."In essence, we are curating our dataset to focus solely on the EEG channels that are relevant to our analysis, discarding those with known issues such as noise or poor signal quality.We utilized the MNE library for this task.To accomplish this, we employed the `raw.pick_types() ` method, which allows us to pick and retain EEG channels (channels capturing electrical brain activity) while excluding channels related to other types of neuroimaging, such as magnetoencephalography (MEG) and electrooculography (EOG).Furthermore, we made use of the "exclude" option to ensure that channels previously marked as "bad" are not considered in our subsequent analyses.
This meticulous data preparation step is fundamental to the quality and integrity of our EEG data, setting the stage for more accurate and meaningful analyses in our research.By focusing on the relevant EEG channels and excluding problematic ones, we enhance the reliability of our findings and contribute to the robustness of our study.
Band power calculations, which determine the energy associated with various frequency bands, frequently span the theta wave (4-8 Hz), delta wave (0-4 Hz), alpha wave (8-12 Hz), and beta wave (12-30 Hz) bands [25][26][27][28].We have utilized a rich set of metadata associated with our EEG (Electroencephalogram) dataset to gain valuable insights into the characteristics and setup of our recorded EEG data.This metadata encompasses critical details that guide our data pre-processing and analysis efforts.Our dataset comprises a total of 59 EEG channels, as indicated by the "chs" field, shedding light on the scale and scope of our EEG data collection.
Filtering parameters, including a high-pass filter with a cut-off frequency of 0.1 Hz and a low-pass filter with a cut-off frequency of 40.0 Hz, are outlined, providing insights into signal processing applied to the EEG data.

Fig. 3. Exploratory Visualization of Pre-processed EEG Data
To visualize the pre-processed EEG data and gain insights into the recorded brain activity, we employed the "raw.plot()" command.This visualization step was essential for our exploratory data analysis, enabling us to inspect patterns, identify potential artifacts, and assess the quality of our EEG data shown in Fig. 3.

Feature Extraction
EEG signals are very informative about the functioning patterns of the brain.The primary goal of feature extraction from EEG signals is to obtain pertinent data that may be applied to a classification problem [29].
There are numerous ways to extract features from EEG data.Calculations of the periodogram and power spectral density as well as band waves of multiple frequencies must be combined in order to extract features using the FFT [30].EEG is a collection of random signals that masks incredibly nuanced facts.The extreme nonlinearity of its features makes them susceptible to jarring variations.However, the human mind moves gradually from one condition to the next.In order to associate EEG segments with mental states, feature extraction seeks to extract pertinent elements from the data [31].
The Power Spectral Density (PSD) is a way to measure the strength of a signal based on its frequency components.It's commonly used in EEG research to extract important features.PSD works by converting data from how it changes over time to how its power is distributed across different frequencies.This conversion is done using a mathematical method called the Fourier Transform (FFT), which helps analyse the frequency components of a signal.The PSD essentially shows how much power the signal has at different frequencies.
In our study, we used the Maximum Power Spectral Density (PSD) feature set, which is a specific aspect of PSD analysis.

Machine Learning Algorithms for Classification
Machine learning algorithms play a pivotal role in EEG-based mental stress classification due to their ability to recognize intricate patterns, handle complex relationships in EEG data, and provide automation and scalability.They offer an objective and standardized approach to classifying stress levels, reducing the subjectivity associated with traditional methods.Machine learning models can adapt to individual variations in stress responses, enhancing the accuracy of assessments [32].Additionally, these algorithms enable realtime monitoring and integration with EEG-based biomarkers, contributing to efficient and personalized stress assessment.Their capacity to process large datasets and provide continuous assessments makes them indispensable tools in the field of mental health assessment and stress management, improving our understanding and management of stress-related conditions.

EEG Classification
Data points are grouped into predetermined classes or categories according to their properties or features in the process of classification, which is a fundamental activity in machine learning and data analysis.The primary objective of classification is to learn a model or algorithm from labelled training data, where each data point is associated with a known class or category, and then use this model to predict the class labels of new, unlabelled data points.In our research, we used machine learning methods to categorise human stress level using EEG data that showed neurological activity.To classify EEG-based mental stress using EEG characteristics, we specifically used the Random Forest (RF), Decision Tree, K-Nearest Neighbor (KNN), Multilayer Perceptron (MLP), Support Vector Machine (SVM), Adaboost, and Extreme Gradient Boosting Model (XGBoost) methods.

Random Forest (RF)
A classification method based on decision trees is known as a random forest, sometimes known as a random decision forest.This algorithm creates a lot of decision trees when training.The majority of trees choose this algorithm's output class.These trees' high accuracy is primarily attributable to their low correlation [33].Automatic stress detection and mental state analysis can both be done with a random forest classifier.Its ability to handle high-dimensional data, robustness to noise, capacity to capture non-linear relationships, and provision of feature importance make it a valuable tool in understanding and objectively assessing mental stress levels based on EEG data [34].

Decision Tree
It is a machine learning algorithm used in EEG-based mental stress classification.It creates a tree-like structure to make decisions based on EEG features, helping identify stress levels.It's interpretable and can handle nonlinear relationships in EEG data [35].

K-Nearest Neighbor (KNN)
K-Nearest Neighbors (K-NN) is a machine learning algorithm used in EEG-based mental stress classification.It classifies stress levels based on the similarity of EEG feature patterns to neighbouring data points.K-NN is effective in capturing local patterns in EEG data but may require careful selection of the "k" value for optimal performance.It's simple to implement and interpret but can be sensitive to noise [36].The fundamental idea behind KNN is that a set of k samples are found in the calibration dataset that are closest to the unknown samples.The outcome may be noise-sensitive if the value of k is too tiny.However, if the value of k is too high and the neighbours contain an excessive number of points from different classes, the outcome may be wrong.

Multilayer Perceptron (MLP)
A neural network-based machine learning approach called Multilayer Perceptron (MLP) is employed in the classification of mental stress based on EEG data.The input, hidden, and output layers are among them.While the output layer generates the outcomes, the input layer receives the patterns.Each link between a layer's neurons and those in the next layer has a certain weight, which affects how those neurons respond in the layer below [37].

EEG-based mental stress classification uses the machine learning technique Support Vector Machine (SVM).
It operates by identifying the hyperplane in EEG feature space that best distinguishes between various stress levels.SVM works well with high-dimensional data and is successful for both linear and non-linear classification applications.It is well known for being reliable and for being able to determine the ideal margin between classes, making it appropriate for stress evaluation using EEG data [38].In order to divide training samples into numerous classes with the largest margin of error and the fewest classification errors, SVM determines the best N-dimensional hyperplane.With a fair level of generalisation, SVM has been used successfully in numerous BCI systems, enabling it to handle overtraining and highly dimensional data effectively [39].

Adaboost
A machine learning approach called AdaBoost, short for Adaptive Boosting, is employed in the classification of mental stress based on EEG data.It builds a strong classifier from the combined results of several weak classifiers.AdaBoost concentrates on challenging-to-classify cases by giving misclassified data points higher weights.AdaBoost is a helpful technique for this application since it can enhance accuracy in the context of stress classification by iteratively focusing more attention on difficult EEG data samples [40].

Extreme Gradient Boosting (XGBoost)
Extreme Gradient Boosting, also known as XGBoost, is a potent machine learning technique utilised in the classification of mental stress based on EEG data.It excels at processing high-dimensional data, such as EEG characteristics, and is an optimised version of the gradient boosting framework.In order to improve performance, XGBoost constructs an ensemble of decision trees and applies boosting [41].It is renowned for being effective, quick, and capable of managing big datasets.When dealing with EEG data for stress classification, XGBoost can offer excellent accuracy and is frequently utilised to enhance classification outcomes.
In our study focused on EEG-based mental stress classification, we have carefully selected a suite of machine learning algorithms to address the unique challenges presented by EEG data and to provide accurate insights into individuals' stress levels.These algorithms include Random Forest, Decision Tree, KNN, MLP, SVM, Adaboost, and XGBoost.Each algorithm has been chosen for specific reasons: Random Forest and Decision Tree for their interpretability and non-linear pattern recognition, KNN for its ability to capture local patterns, MLP for its deep neural network capabilities, SVM for its effectiveness with high-dimensional data, Adaboost for iterative improvement, and XGBoost for handling large datasets efficiently.These algorithms collectively offer a comprehensive toolkit for EEG-based mental stress classification, enabling us to analyse EEG features and provide valuable insights into individuals' stress levels accurately and reliably.

Performance Metrics
Performance metrics-also referred to as evaluation metrics or evaluation criteria-are numerical measurements that are used to gauge the efficiency or performance of a model, algorithm, system, or procedure.From the confusion matrix of the models generated by machine learning, we calculated a number of performance measures, including precision, recall, F1-score, and accuracy.We computed accuracy, precision, and recall scores for each individual model and then proceeded to evaluate and compare how each model performed relative to the others in the study.This comparative analysis allowed us to assess the strengths and weaknesses of each model in a broader context, providing insights into their respective classification capabilities.
The four concepts employed in the metrics are True Positive (TP), False Positive (FP), True Negative (TN), and False Positive (FN).These measures are given in further depth as follows:

Accuracy
A performance metric called accuracy is used to assess a classification model's general correctness.In order to quantify the model's capacity to produce accurate predictions, it counts the percentage of correctly categorised instances (both true positives and true negatives) among all the examples in the dataset.

Precision
Precision, in classification, is a metric that assesses the accuracy of positive predictions made by a model.It measures how well the model avoids making false positive errors, which is essential when these errors are costly in a given context.A higher precision value signifies a lower occurrence of false positives.

Recall
Recall, sometimes referred to as Sensitivity or True Positive Rate, is a performance metric used in classification to assess a model's capability to recognize all pertinent instances within a dataset.It quantifies how well the model captures all positive instances without omitting any.

F1-Score
Precision and recall are combined into single value in the classification performance metric known as the F1-score, which strikes a balance between the two criteria.An increase in the F1-score, which ranges from 0 to 1, suggests improved model performance in terms of recall and precision.

Results and Discussion
We outlined the study's experimental findings in this section, followed by how they were interpreted.The major goal of the study is to evaluate the performance of each of the models and see how well it predicts.

Data Analysis Results
In our study, we conducted an analysis of EEG data, which is a fundamental component of our research on mental state assessment.To begin with, we needed to access and pre-process the EEG data, which was stored in a file.This file is part of the MNE-Python and serves as a valuable resource for our research.We utilized the MNE library for this task.This file contains data crucial for our analysis and is located in a specified data folder.By loading this custom data alongside the MNE sample data, we were able to perform a comprehensive examination of EEG signals in the context of mental state classification.
To ensure that our analysis focused on EEG channels, we implemented channel selection and data cleaning steps.We excluded channels related to magnetoencephalography (MEG) and electrooculography (EOG), as they were not relevant to our EEG-based investigation.Additionally, we took measures to exclude any channels marked as "bad" due to noise or other issues that could affect data quality.This data pre-processing is a crucial initial step to ensure that our subsequent analyses are based on clean and relevant EEG signals.Following data pre-processing, we narrowed our focus by cropping the EEG data to a specific segment of interest.This segment encompassed a duration of 60 seconds and was defined in the frequency range of 0-40 Hz.
In this study, pre-processed EEG recordings from four channels such as 'AF7', 'AF8', 'TP9', and 'TP10' and three bands are used to extract three groups of characteristics.We chose a sizable pool of features from numerous feature sets.Each electrode's signal features were taken out.Furthermore, we conducted feature extraction in the frequency domain by calculating the PSD and corresponding frequency values.

Fig. 4. Power Spectral Density (PSD) Analysis of EEG Data
The visualization of the power spectral density (PSD) of the EEG data is shown in Fig. 4.This plot displays the PSD curve, offering insights into the distribution of power across various frequencies within the EEG signal.
To ensure meaningful results, we specified parameters for this analysis.We set the sampling frequency to 256 Hz and defined a frequency range of interest, ranging from 1 Hz to 40 Hz.This frequency range encompassed the typical EEG frequency bands relevant for our study.Our choice of the multitaper method allowed us to perform spectral analysis efficiently.The use of multiple tapers in this method reduces spectral leakage and enhances the accuracy of the PSD estimation.Overall, this feature extraction step in the frequency domain enabled us to obtain essential information about the EEG data's spectral characteristics.These features served as valuable inputs for subsequent analyses and classification tasks related to mental state assessment using EEG signals.
In our work, we conducted a visual analysis of the PSD values extracted from EEG data.The line plot was designed to display PSD values against corresponding frequency values, as shown in Fig. 5.Each line on the plot represented a specific channel or feature of the EEG data, and we transposed the PSD data to arrange it accordingly.In our study, the visualisation was crucial in giving us insightful understandings into the complex interplay of spectral power across various frequency bands in our EEG dataset.The fundamental understanding of how the EEG signal power dynamically varied across the frequency band was developed by this visualisation.This comprehension turned out to be of utmost importance in comprehending the subtle brain activity and identifying characteristic patterns linked to different mental states, such as states of relaxation, concentration, and neutral.We were able to identify and distinguish the distinctive patterns indicative of various mental states as a result of our study of these PSD curves, which enhanced our research findings and advanced our understanding of EEG-based mental stress classification.

Classification Results
Random Forest, Decision Tree, KNN, MLP, SVM, AdaBoost, and XGBoost are some of the machine learning classification techniques employed in this work.Based on the useful information discovered from the extracted features, these classification algorithms have been utilised to classify EEG recordings into stress categories.
We have evaluated the Random Forest classifier for the job of classifying mental stress using EEG data.It uses the specified parameters, estimators, and random_state in the context of machine learning for the classification of mental stress based on EEG data.The number of decision trees to be built in the Random Forest ensemble is specified by the estimator parameter.One hundred decision trees are created in this scenario.The Random Forest classifier's accuracy was calculated as 0.9489, which indicates that for around 94.89% of the test samples, the model accurately predicted the mental state.
The overall accuracy of the Decision Tree classifier is approximately 89.79%, indicating that it correctly classified about 89.79% of the samples in the test dataset.In terms of precision, recall, and F1-score, the classifier performs well across all three classes, with F1-scores ranging from 0.87 to 0.94.
In our study, mental stress is classified using EEG data using the K-Nearest Neighbours (KNN) classifier with a parameter setting of 5 neighbors.By locating the "k" nearest data points in the training dataset and selecting the class label that is most prevalent among those neighbours, the KNN machine learning algorithm categorises samples.The KNN classifier's overall accuracy is roughly 88.44%, meaning that it successfully identified 88.44% of the samples in the test dataset.The classifier's performance varies among the three classes in terms of precision, recall, and F1-score, with F1-scores ranging from 0.85 to 0.93.
For the categorization in our investigation, we used the MLP Classifier as a machine learning approach.An example of an artificial neural network with numerous layers is the MLP Classifier, which has input, hidden, and output layers.In our example, we used the rectified linear unit (ReLU) activation function, which is frequently used in neural networks to create non-linearity, and constructed the MLP with a single hidden layer having 64 neurons.About 91.40% of the samples in the test dataset were successfully classified according to the MLP classifier.SVM classifier was configured with a linear kernel, suitable for handling high-dimensional data like EEG features.The SVM classifier's overall accuracy is roughly 91%.
For our classification investigation of mental stress, we used two ensemble-based machine learning algorithms, AdaBoost and XGBoost.We instantiated the AdaBoost Classifier with the specified hyper parameters, including the number of base estimators set to 100 and a random state for reproducibility.We also employed the XGBoost Classifier, an implementation of the popular XGBoost algorithm.XGBoost is known for its efficiency and effectiveness in handling high-dimensional data, making it well-suited for EEG-based mental stress classification.The AdaBoost model has an accuracy rate of about 84.41%, whereas the XGBoost model has a remarkable accuracy rate of about 97.85%.
In order to evaluate the performance of the various machine learning algorithms employed in our study for mental stress classification, the final results of the seven distinct models have been meticulously summarized and presented in Table 2.For our dataset, 1, 2, and 3 in the given table, respectively, stand for relaxed, concentrated, and neutral mental stress.
In our comparative analysis of the seven classification algorithms used for mental stress classification based on EEG data, we observed variations in their performance.Random Forest demonstrated the highest accuracy at 94.89%, showcasing its capability to robustly classify mental states.It provided a precision, recall, and F1score all at 95%, making it an excellent choice for EEG-based mental stress classification.Decision Tree followed closely with an accuracy of 89.79% and well-balanced precision, recall, and F1-score metrics at 90%.KNN offered a reasonable accuracy of 88.44% but displayed sensitivity to noise in the data.It showed precision, recall, and F1-score values of 88%, 89%, and 88%, respectively.The MLP classifier achieved an accuracy of 91.40% with a balance between precision, recall, and F1-score metrics around 91%. SVM delivered an accuracy of 90.59% and maintained a consistent balance between precision (91%), recall (91%), and F1-score (91%).AdaBoost and XGBoost, while having lower accuracies at 84.41% and 97.85%, respectively, showed good precision, recall, and F1-scores, indicating their potential for mental stress classification.XGBoost emerged as the best-performing classifier with an accuracy of 97.85%.This comparative analysis provides valuable insights for choosing the most suitable classifier for EEG-based mental stress classification tasks.

Fig. 6. Comparative Analysis of Model Accuracies
In our study, we employed seven distinct classification algorithms for mental stress classification, each of which exhibited unique strengths and weaknesses.AdaBoost enhanced classification accuracy by focusing on challenging data points, but its performance depended on the quality of individual weak classifiers.Finally, XGBoost displayed high efficiency, superior performance, and excellent interpretability, making it suitable for various scenarios but still requiring careful hyper parameter tuning for optimal results.The choice of the most suitable algorithm depended on considerations such as EEG data characteristics, computational resources, interpretability requirements, and the trade-off between model complexity and performance.

Future Work
Future research in mental stress classification using EEG data can focus on several avenues for improvement.Firstly, exploring advanced feature engineering techniques and dimensionality reduction methods can enhance the quality of input features, potentially leading to improved classification performance.Additionally, investigating novel machine learning algorithms or hybrid approaches that combine the strengths of multiple models could yield even more accurate results.Furthermore, expanding the dataset size and diversity can enhance model generalization and reliability, particularly for real-world applications where data variability is significant.To get over the restriction, future research has to look more closely at the brain activities of the many subcategories of Alzheimer's disease.To enhance classification performance, we also intend to research deep learning models and appropriate inductive biases for classifying mental disorders.

Conclusion
In conclusion, our study explored seven distinct machine learning algorithms for EEG-based mental stress classification.Our findings demonstrated that XGBoost outperformed other models, achieving a remarkable

Fig. 5 .
Fig. 5. Different Domain Analysis of Mental States: Power Spectral Density Variation

Table 1 . Overview of Studies Focusing on the Classification of Mental Stress Using EEG Signals in the Human Brain Reference, Year Aim Methods Used Accuracy in %
MLPs are useful for classifying stress levels because they are able to capture non-linear correlations.They can benefit from larger training datasets and thorough hyper parameter optimisation.
It can recognise intricate patterns in EEG data because it has numerous interconnected layers of

Table 2 .
Performance Evaluation of Machine Learning Models for Classification of Mental Stress Differentiating Mental Stress Levels: Analysing Machine Learning Algorithms Comparatively For EEG-Based Mental Stress Classification Using MNE-Python accuracy of 98%.This underscores the significance of algorithm selection in EEG-based stress classification, emphasizing the need for careful consideration of data characteristics, interpretability, and computational resources.Our research contributes valuable insights to the field and highlights the potential for further advancements in hybrid approaches and real-world applications, advancing our understanding of mental stress assessment.In EEG-based stress classification, the choice of algorithm holds immense significance.It directly impacts accuracy, interpretability, and the practicality of the classification model.Diverse algorithms offer unique strengths, making careful selection paramount.Algorithms like Random Forest and XGBoost excel in handling high-dimensional data, while decision trees and linear SVMs prioritize interpretability.Algorithm selection also affects feature engineering and the model's adaptability to real-world scenarios.MNE-Python holds great potential for processing EEG signals in the context of classifying mental stress.A comprehensive and adaptable infrastructure is provided by MNE-Python for precisely pre-processing, analysing, and interpreting EEG data.Its sophisticated feature extraction, spectrum analysis, and source localization capabilities let researchers find complex patterns and signs connected to various stress levels.Additionally, MNE-Python has strong visualisation capabilities that make it easier to explore EEG data and identify stress-related neural signatures.Since it is open-source, the research community is encouraged to collaborate and innovate, which makes it a great tool for advancing our understanding of mental stress and its neurological correlates.MNE-Python has a lot of potential to improve the precision and breadth of EEG-based investigations on mental stress classification.