Enhancing Generalizability in Acute Mental Stress Detection:
A Machine Learning Approach Leveraging ECG from a Novel Dataset
This repository houses the codebase to predict stress solely on the electrical activity of the heart using machine learning techniques.
Report Bug
·
Request Feature
Table of Contents
This project aims to predict the stress of an unknown person soley on the electrical activity of the heart. This is achieved through training machine learning models on electrocardiogram (ECG) recordings.
The SiA-Kit is a package that provides human-readable and extendable pipelines to repeat the experiments described in the project. The builder pattern that is used throughout the pipelines, makes it easier to understand what is happening behind the scenes.
- Python v3.9+
- Install The Packages.
Open the terminal in the root directory and execute the following command,
pip[3] install -r requirements.txt
A step by step series of examples that tell you how to get the data cleaned.
- Prepare your dataset.
The directories that were used throughout the experiment can be found indata/
, which is separated into four parts,raw
for the raw data,cleaned
for the cleaned data,features
for the manually extracted features used to build the machine learning models, andsignal
which can be used by a neural network.
The use of these directories are optional, any directories can be used, as long as the paths are changed accordingly.
The dataset can be prepared by using the pipeline found in1_preprocessing.ipynb
, or by using the methods that can be found in the SiA-kit, like so,
sia.Preprocessing() \
.data(read_csv('<in_path>/*.csv')) \
.process(neurokit()) \
.to(write_csv('<out_path>/[0-9]{5}.csv'))
- Extract the features.
The features can be extracted by using the pipeline found in2_feature_extraction.ipynb
, or by using the methods that can be found in the SiA-kit, like so,
sia.Segmenter() \
.data(read_csv('<in_path>/*.csv')) \
.segment(SlidingWindow(WINDOW_SIZE, STEP_SIZE)) \
.extract(hrv([Statistic.MEAN, Statistic.CVSD, Statistic.NN20]))
.to(write_csv('<out_path>/[0-9]{5}.csv'))
- Build the model.
The model can be built by using the pipeline found in3_training.ipynb
.
- Where are the experiments?
For better readability, this repository has been overhauled. The notebooks with the experiments can be found in/deprecated
.