This repository provides Python scripts for sleep stage classification using EEG data. It includes code for both Exploratory Data Analysis (EDA) and machine learning models (with and without class balancing). These scripts are based on MNE-Python and SciKit-Learn. The classification scripts also support running the analysis using different wavelet transforms, such as Daubechies (db4
), Coiflet (coif5
), and Biorthogonal (bior1.3
).
The project contains four main scripts:
SSC_EDA.py
: Performs exploratory data analysis (EDA) on EEG data, including signal plotting, power spectral density, event distributions, and channel correlations.SSCwithSMOTE.py
: A machine learning pipeline for classifying sleep stages using SMOTE (Synthetic Minority Oversampling Technique) to handle class imbalance and support for multiple wavelet transforms.SSCwithclassbalance.py
: A machine learning pipeline for classifying sleep stages using class weighting to handle class imbalance and support for multiple wavelet transforms.SSCwithoutclassbalance.py
: Similar to the previous scripts, but without class balancing, and also supporting multiple wavelet transforms.
Before running the scripts, ensure you have the following Python packages installed:
pip install numpy matplotlib seaborn mne scipy scikit-learn pywavelets imbalanced-learn
- The scripts expect EEG data in
.edf
format. You'll need a folder containing.edf
files for sleep scoring. - Place your
.edf
files in a folder and update thefolder_path
in the scripts to point to your data folder.
To run any script, simply execute it in your terminal:
python <script_name>.py
For example, to run the SSC_EDA.py
script:
python SSC_EDA.py
To run the classification scripts with wavelet support, you can specify the wavelet type as follows:
python SSCwithclassbalance.py --wavelet coif5
If no wavelet is specified, the default wavelet (db4
) is used.
The classification scripts (SSCwithSMOTE.py
, SSCwithclassbalance.py
, and SSCwithoutclassbalance.py
) support different wavelet families for feature extraction using the PyWavelets library. You can use the following wavelet variants:
- Daubechies (db): For example,
db4
- Coiflet (coif): For example,
coif5
- Biorthogonal (bior): For example,
bior1.3
You can specify the wavelet to use by passing it as a command-line argument when running the script:
python SSCwithSMOTE.py --wavelet coif5
If no wavelet is specified, the default wavelet db4
is used.
This script performs exploratory data analysis on sleep stage EEG data, providing various visualizations:
- Raw EEG signal plots
- Power Spectral Density (PSD) plots
- Event distribution (sleep stages)
- Epoch variance and mean distributions
- Correlation matrix between EEG channels
python SSC_EDA.py
- Plots of raw EEG signals and their PSD
- Bar charts for sleep stage distribution
- Histograms for epoch variance and mean
- Correlation matrix heatmap
This script performs sleep stage classification using machine learning models with SMOTE (Synthetic Minority Over-sampling Technique) to handle class imbalance. It supports Random Forest, Gradient Boosting, and Support Vector Machine (SVM) classifiers. You can also choose which wavelet to use for feature extraction by passing it as a command-line argument.
python SSCwithSMOTE.py --wavelet coif5
- Confusion matrices and classification reports for each model
- Model comparison in terms of accuracy
--wavelet
: Specify the wavelet type to use. Supported wavelets includedb4
,coif5
,bior1.3
. Default isdb4
.
This script performs sleep stage classification using machine learning models with class weighting to handle class imbalance. It supports Random Forest, Gradient Boosting, and Support Vector Machine (SVM) classifiers. You can also choose which wavelet to use for feature extraction by passing it as a command-line argument.
python SSCwithclassbalance.py --wavelet coif5
- Confusion matrices and classification reports for each model
- Model comparison in terms of accuracy
--wavelet
: Specify the wavelet type to use. Supported wavelets includedb4
,coif5
,bior1.3
. Default isdb4
.
This script performs sleep stage classification using machine learning models without any class balancing techniques. It supports Random Forest, Gradient Boosting, and SVM classifiers, and allows for wavelet-based feature extraction.
python SSCwithoutclassbalance.py --wavelet bior1.3
- Confusion matrices and classification reports for each model
- Model comparison in terms of accuracy
--wavelet
: Specify the wavelet type to use. Supported wavelets includedb4
,coif5
,bior1.3
. Default isdb4
.
This project is licensed under the MIT License.