Git Product home page Git Product logo

sleep-stages-classification-by-eeg-signals's Introduction

Sleep Stages Classification by EEG Signals

MATLAB Project to Classify Different Sleep Stages using Machine Learning. This is a simple project and simple classification model, much more can be added and better accuracy can be achieved but no time!

EEG Signals

EEG Signals EEG Signals

Model Details

  • Alpha, Beta, Theta, Delta, Spi & Saw signals were extracted by bandpass filter applied on EEG data.
  • Differencing applied on all the signals.
  • Different features were extracted including but not limited to STD, Skewness, Kurtosis, Max, Min, IQR, Mean freq, Median freq, SNR ...
  • The label is extracted using the CSV PSG files.
  • Two machine learning models were applied:
    • Random Forest RF:
      • 10 cross validation.
      • 300 trees with Min Leaf Size of 1
    • Support Vector Machine:
      • Gaussian Kernel
      • Coarse Grid Search with 5 cross validation (Tune the Parameters for Better Accuracy)

Accuracy

This is the accuracy for 4 files only (Two Subjects & Two Nights)

Random Forest

Random Forest Random Forest

Support Vector Machine

Support Vector Machine Support Vector Machine

Note: Not fully tuned ...

Hypnogram Data Extraction

A simple python script has been written to extract the Hypnogram data into CSV. It takes one parameter which is the directoy in which files exist.

#!/usr/bin/env python3
import pyedflib
import os
import sys

print(sys.argv[1])

for fileName in os.listdir(sys.argv[1]):
        if fileName.endswith("-Hypnogram.edf"):
                filePath = os.path.join(sys.argv[1], fileName)
                f = pyedflib.EdfReader(filePath)
                annotations1 = f.readAnnotations()
                filePath = filePath.replace("-Hypnogram.edf", ".csv")
                with open(filePath, 'w') as fileCSV:
                        for d in range(len(annotations1[0])):
                                fileCSV.write(str(annotations1[0][d])+','+str(annotations1[1][d])+','+ annotations1[2][d].replace("S>

Note: You need to install pyedflib package (pip3 install pyedflib).

Code Structure

  • data
    • Contains the *PSG.edf files whcih are whole-night polysmnographic sleep recordings
  • hypno
    • Contains the *Hypnogram.edf files which contain annotations of the sleep patterns that correspond to the PSGs. These patterns (hypnograms) consist of sleep stages W, R, 1, 2, 3, 4, M (Movement time) and ? (not scored).
  • feature_extractions
  • classifiers
    • Contains two codes for two classification algorithms, namly, RF and SVM.
  • plot
    • A simple code to plot different frequencies of the EEG signal

Dataset

B Kemp, AH Zwinderman, B Tuk, HAC Kamphuisen, JJL Oberyé. Analysis of a sleep-dependent neuronal feedback loop: the slow-wave microcontinuity of the EEG. IEEE-BME 47(9):1185-1194 (2000). https://physionet.org/content/sleep-edfx/1.0.0/

sleep-stages-classification-by-eeg-signals's People

Contributors

lcsig avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

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.