Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Total Perspective Vortex

Plug your brain to the shell — brain-computer interface via EEG + machine learning

Python MNE scikit--learn 42 School


Overview

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.


Goals

  • 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 + TransformerMixin for sklearn
  • Classify a data stream in "real time" (< 2s per epoch)
  • Achieve ≥ 60% mean accuracy across all 6 experiment types

Dataset

PhysioNet EEG Motor Movement/Imagery Dataset

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])

Installation

pip install -r requirements.txt

Pipeline

Raw 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.


Implementation

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 class
  • ch = 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.


Evaluation

  • Use cross_val_score on 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

About

Total_perspective_vortex

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages