A CLI tool for seizure detection using interpretable ML
Project description
- SeizyML uses interpretable machine learning models to detect 🕵️♂️ seizures from EEG recordings coupled with manual verification in user-friendly GUI.
- 📖 To reference SeizyML, or view the manuscript, please refer to the following publication (To be updated soon).
- You can access the data and code used to reproduce the experiments and figures from the accompanying paper on Zenodo.
📚 Contents
📄 Additional Resources
Hardware requirements
- SeizyML is a lightweight application that utilizes Gaussian Naive Bayes (GNB) models to predict seizure events from EEG data.
- Any modern CPU with sufficient RAM to load your EEG recordings should work effectively.
- For example, a quad-core CPU with 16 GB RAM can efficiently handle 24-hour long EEG recordings with 2 channels sampled at 4000 Hz.
- No GPU is required for SeizyML's operation.
Installation
Conda (Recommended)
-
Download and install miniconda.
-
Clone or Download SeizyML on your machine.
-
Start Anaconda's prompt, navigate to the downloaded /seizy_ml to create the conda environment:
conda env create -f environment.yml -
Activate environment
conda activate seizyml -
Launch App
seizyml
Pip
-
Download and install Python 3.9.
-
In the terminal
pip install seizyml -
Launch App
seizyml
If this works you should see the SeizyMl CLI interface.
App Configuration
All settings are stored in the config.yaml file.
- This file will be created in the SeizyML folder from a template file (
temp_config.yaml) after you use the setpath command for the first time. ⚠️ Thetemp_config.yamlfile should not be edited by the user.
To edit the config.yaml use any text editor such as notepad:
- The only setting that requires editing before training a model and using the app is the
channelsfield. -
**channels** : List containing the names of LFP/EEG channels, e.g. ["hippocampus", "frontal cortex"] - All other settings can be left at default, given that the data were prepared in the recommended format (.h5 files with shape [Nsegments, 500 (1 segment), channels]).
- For data conversion check the accompanying app seizy_convert or the h5_conversion script for more help.
- An explanation of all other settings can be found here.
Model Training
- Before using SeizyML for seizure detection a model should be first trained on ground truth (hand-scored) data.
- Launch App.
For conda:
# In anaconda prompt
cd ./seizy_ml
conda activate seizyml
seizyml
For pip:
# In terminal
seizyml
- Set path for data processing.
seizyml setpath 'path'
-
This is the folder path where the training data in .h5 format along with the corresponding training labels in .csv format are stored.
-
The training data consist of each recording in .h5 format [Nsegments, 1 segment, Nchannels]. Where a segment is 500 (win*fs).
-
The training labels consist of a corresponding .csv file containing the ground truth labels (1 for seizure, 0 for non seizure) with length [Nsegments].
-
Training data and labels for each recording need to have a matching name.
-
The
win,fs,channelsfields should be set inconfig.yamlto match the shape of the data. Defaults are win=5, fs=100. -
The
config.yamlis created when the path is first set in SeizyML set from temp_config.yaml. -
This folder should be kept in one location as the trained models will be stored here.
-
If the folder is moved, then the
training_pathfield inconfig.yamlshould be updated to reflect the new location.
- Model Training
seizyml train
- This is a multi-step process:
- a) Data preprocessing (high pass filter and exterme outlier removal).
- b) Feature extraction.
- c) Find six best feature sets.
- d) Train a GNB model on these feature sets and select the one with highest F1 score.
- The model_id will be stored in the config.yaml file and will be used to load that model.
- Feature Contributions Features contribution to the GNB model can be visualized using the following command.
seizyml featurecontribution
How To Use
⚠️ Note: A model must be trained ☝️ before using the app for seizure detection.
- Launch App.
For conda:
# In anaconda prompt
cd ./seizy_ml
conda activate seizyml
seizyml
For pip:
# In terminal
seizyml
- Set path for data processing.
seizyml setpath 'path'
- This is the parent path where the child folder with h5 data resides and where all subsequent folders will be created. Check configuration settings for more information.
- The h5 data should be added in a child folder called
data.
- Run file check.
seizyml filecheck
- ⚠️ This step checks that the h5 files have the correct dimensions. For help on how to convert files to h5 have a look at the h5_conversion script.
- Preprocess data.
- This is the step where the h5 data files will be filtered and large outliers will be removed.
seizyml preprocess
- Generate model prections.
seizyml predict
- Here selected features will be extracted and model predictions will be generated using the selected model (model id can be found in the configuration settings file).
- Verify seizures and adjust seizure boundaries.
- This will launch a prompt to allow for file selection for verification.
- After file selection, a GUI will be launched for seizure verification and boundary adjustment.
seizyml verify
- Get seizure properties. -This step will generate a csv file with seizure properties for each h5 file.
seizyml extractproperties
Contributions
We welcome all project contributions including raising issues and pull requests!
-> Back to Top.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seizyml-0.1.0.tar.gz.
File metadata
- Download URL: seizyml-0.1.0.tar.gz
- Upload date:
- Size: 501.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8ddf4bef74d1d3a4b1c0d25a44eda7d19a792383558b7aa0cc8a791ab25cca9
|
|
| MD5 |
abbf79310c97c074595842124b8ccb04
|
|
| BLAKE2b-256 |
26175d93f62da85061c8ad532676d4559623c536464c03ce90230c0aa9bd5a28
|
File details
Details for the file seizyml-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seizyml-0.1.0-py3-none-any.whl
- Upload date:
- Size: 502.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8c771d43319e418ac0b4435128dbf597e10ff86c196b90f13a7432ac4f218e1
|
|
| MD5 |
87f5dfdae84b34850ba09e0bd7282487
|
|
| BLAKE2b-256 |
96ebc66ece11f8ab26a09767c5bae1bd4c8786858b149b4575aa212d3c69d838
|