Plug your brain to the shell — brain-computer interface via EEG + machine learning
This project builds a brain-computer interface (BCI) that classifies motor imagery tasks from electroencephalographic (EEG) signals. Using recordings from a motor imagery experiment (PhysioNet dataset), the system infers whether a subject was imagining a hand or foot movement.
The pipeline covers the full flow: raw EEG parsing and filtering, feature extraction, a custom dimensionality reduction algorithm (CSP or equivalent), and a real-time stream classifier — all integrated with scikit-learn's Pipeline API.
- Parse and visualize raw EEG data with MNE
- Filter signals to relevant frequency bands
- Implement a dimensionality reduction algorithm (CSP, PCA, ICA...)
- Integrate it as a custom
BaseEstimator+TransformerMixinfor sklearn - Classify a data stream in "real time" (< 2s per epoch)
- Achieve ≥ 60% mean accuracy across all 6 experiment types
PhysioNet EEG Motor Movement/Imagery Dataset
- 109 subjects
- Motor imagery tasks: hand and feet movements
- Labels indicate moments where subjects performed or imagined a task
- Download: https://physionet.org/content/eegmmidb/1.0.0/
The dataset is not included in this repository. It can be fetched programmatically via MNE:
from mne.datasets import eegbci
eegbci.load_data(subject=1, runs=[6, 10, 14])pip install -r requirements.txtRaw EEG data
│
▼
[1] Preprocessing
├── Parse .edf files with MNE
├── Bandpass filter (keep relevant frequency bands)
└── Epoch segmentation
│
▼
[2] Feature extraction
└── Signal power by frequency band and channel
│
▼
[3] Dimensionality reduction ← custom implementation
└── CSP / PCA / ICA (BaseEstimator + TransformerMixin)
│
▼
[4] Classification
└── sklearn classifier (SVM, LDA, etc.)
│
▼
[5] Stream prediction
└── Playback reading simulating real-time input
All steps are chained using a sklearn.pipeline.Pipeline object.
The core of this project is implementing a dimensionality reduction algorithm from scratch.
Given an EEG signal matrix:
{En} N_n=1 ∈ R^(ch × time)
where:
N= number of events per classch= number of channels (electrodes)time= length of each event recording
The goal is to find a transformation matrix W such that:
W^T · X = X_CSP
where X_CSP is the projected data maximizing variance between classes.
The implementation must subclass sklearn's BaseEstimator and TransformerMixin so it integrates natively into Pipeline and cross_val_score.
Numpy/scipy functions for eigenvalue decomposition, SVD, and covariance estimation are allowed.
- Use
cross_val_scoreon the full pipeline - Split data into train / validation / test sets (no overfitting, vary splits)
- Target: ≥ 60% mean accuracy across all subjects and experiment types on unseen data