Coder Social home page Coder Social logo

kryekuzhinieri / predicting-driver-stress-using-deep-learning Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 3.0 125 KB

Predicting driver stress levels using Physionet's SRAD (drivedb) dataset with methods such as LSTMs, RNNs, CNNs

License: MIT License

Python 100.00%
cnn lstm physionet rnn srad stress drivedb electrocardiogram electromyogram galvanic-skin-response

predicting-driver-stress-using-deep-learning's Introduction

Predicting Driver Stress Using Deep Learning

About the project

This project is part of my masters thesis and aims to predict driver stress levels using Physionet's SRAD (drivedb) dataset with methods such as LSTMs, RNNs and CNNs. It is a work based predominantly on Healey's paper titled "Detecting Stress During Real-World Driving Tasks Using Physiological Sensors" which can be found here.
The dataset contains inputs collected from physiological signals such as: Electrocardiogram, Electromyogram, and Galvanic Skin Response.

Getting started

The scripts are sorted in an alphabetical manner to make it easier for anyone to run the codes. Hence, if one is interested in running the c_preprocessing.py script, the data has to be provided as in the proceding scripts, i.e: a_convert_to_csv.py.

Convert the dataset

To convert the files from .dat format to csv, you can run the a_convert_to_csv.py file. This can be done by calling the convert_to_csv function with default parameters.

Get basic plots and info

To plot the data for each drive, the b_basic_information.py script can be utilized.

Preprocessing

The initial dataset does not contain the marker data. To attach the marker data to each csv, the process_data function from c_preprocessing.py script can be used.

Feature Selection

The dataset consists of 7 columns, namely: ECG, EMG, hGSR, fGSR, HR, RESP. To create a set of 22 features, d_feature_selection.py can be run which will create the following columns: EMG_mean, footGSR_mean, footGSR_std, footGSR_frequency, footGSR_magnitude, footGSR_duration, footGSR_area, handGSR_mean,handGSR_std, handGSR_frequency, handGSR_magnitude, handGSR_duration, handGSR_area, HR_mean, HR_std, HRV_ratio, RESP_mean, RESP_std, RESP_ulf, RESP_vlf, RESP_lf, RESP_hf, Stress.
Moreover, the data can be segmented into different intervals. The default value is 10 seconds.

Algorithms

Lastly, this project aims to predict stress levels using various reduction techniques with the aid of deep learning models such as LSTMs, CNN and RNNs. These techniques can be accessed in the e_models.py file.

Disclaimer

Please bear in mind that some of the default values for the functions may not directly mean best values or parameters because I have been playing with them. However, for a more detailed description of the parameters, you are encouraged to read my thesis by clicking here.

Feature Selection Infographics

Galvanic Skin Response Features Screenshot

Heart Rate Features Screenshot

Resp Features Screenshot

License

Distributed under the MIT License. See LICENSE for more information.

predicting-driver-stress-using-deep-learning's People

Contributors

kryekuzhinieri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

predicting-driver-stress-using-deep-learning's Issues

Conversion

Sir, after this script a_convert_to_csv.py, an empty folder is created, the respective folder does not contain any csv file, can you please help me, how to do the conversion properly?

Code that I am using

from pathlib import Path

import numpy as np
import pandas as pd
import wfdb # WaveForm-Database package. A library of tools for reading, writing, and processing WFDB signals and annotations.

def convert_to_csv(path='stress-recognition-in-automobile-drivers-1.0.0./', new_folder=True):
"""
Code to convert all .dat files (ECG signals) in a folder to CSV format
Path - location of the dat files (str)
new_folder - whether to put the files in a new csv folder (boolean)

@authors: Abhishek Patil, Enes Ahmeti
"""
print('Reading files...')
if new_folder:
    Path(path).joinpath("csv_files").mkdir(parents=True, exist_ok=True)
# Get list of all .dat files in the current folder
for file in read_data(path=path, extension="*.dat"):
    print(file)
    # Get only the name from file.
    filename = file.stem
    # Read the signal data
    record, fields = wfdb.rdsamp(filename)
    # Drive7 hand GSR is misspelled.
    fields['sig_name'] = ["hand GSR" if s == "hand GSr" else s for s in fields['sig_name']]
    # Column headers
    header = ",".join(["-".join(x) for x in zip(fields['sig_name'], fields['units'])])
    # Add to the corresponding folder
    filename = Path(path).joinpath("csv_files") / f"{filename}.csv" if new_folder else f"{filename}.csv"
    np.savetxt(filename, record, delimiter=",", header=header, comments="")
print('All files read successfully!')

def read_data(path, extension=".csv"):
"""
Function to read the all the csv/dat files.
Since there are many files, it returns an iterator.
path - path to the csv/dat files.
extension - csv/dat. (if csv, it returns the dataframe else only filename)
"""
file_paths = Path(path).glob(extension)
for file in file_paths:
if extension == "
.csv":
dataset = pd.read_csv(file)
yield file.stem, dataset
else:
yield file

convert_to_csv()

It would be a great help.

Result Verification

Sir, for the e_models.py

I have run this file using the following the code
if name == "main":
main(
feature_selection="rf", # Choose one: "lda", "pca", "autoencoder", "rf"
classifier="loop", # Choose one: "rf", "rnn", "loop"
undersample=True, # True or False
shuffle=True, # True or False
path=DATASET_PATH, # Provide the path to your dataset CSV file
)
Can you confirm that, if I am running the code in the proper way or not?

After running this code
I got the following results (Accuracy on the Testing Data)
lda + rf -> 54.76
lda + RNN -> 53.99
pca + rf -> 54.0575
pca + rnn -> 54.760
autoencoder + rf -> 50.86
autoencoder + rnn -> 52.65
rf + rf -> 70.95
rf + rnn -> 59.52

Can you please confirm these results?

And I still have to run the remaining combinations.
So for the remaining combinations, please tell me their accuracy too. 
It would be a great help. 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.