EEG Analysis Studio

Educational project · Not a medical diagnostic tool · Runs 100% offline

Offline Bonn EEG seizure detection: 178-sample segmentation (173.61 Hz), 10 time-domain stats, 11 Welch PSD features, and a 300-tree Random Forest.

Loading 300-tree EEG Random Forest (2.0 MB) and Bonn recordings…

Interactive EEG Signal & Seizure Detection Workspace

178-sample segs · 21 features · 300 trees
In-sample reference demo · model trained on 11,500 Bonn segments

Loading Bonn recordings…

Recording Verdict
—
—
Mean Seizure Prob
—
—
Segments (178-pt)
—
—
Selected Segment
—
—
Dominant Freq
—
—
Segment 1 / 1
Hover trace for sample index, timestamp & amplitude
Click any bar to inspect that 178-sample segment · dashed line = 0.50 threshold
welch psd · frequency bands · tree consensus

Spectral Analysis & 300-Tree Consensus (Selected Segment)

Welch Power Spectral Density (periodic Hann window, nperseg = 128, noverlap = 64, constant detrend, fs = 173.61 Hz) integrated via the trapezoidal rule across five canonical EEG bands.

Hover PSD curve for frequency (Hz) and spectral density
Delta (0.5–4 Hz) Theta (4–8 Hz) Alpha (8–13 Hz) Beta (13–30 Hz) Gamma (30–60 Hz)

EEG Band Power Breakdown

300-Tree Random Forest Output

feature extraction · 21 model inputs

21 Extracted Features (Selected Segment)

Exact 21-feature vector fed to the Random Forest in fixed order [0..20]: 10 time-domain statistics followed by 11 Welch spectral features, shown alongside trained Gini feature importances.

group-aware evaluation · stratifiedgroupkfold

Group-Aware Cross-Validation & Honest Limits

Evaluated with 5-fold StratifiedGroupKFold (seed 42) across all 11,500 one-second segments from 500 Bonn recordings (20% seizure positive). All 23 segments from each recording stay on the same side of every fold.

Why Group-Aware Splitting Matters

With 20% positive segments, a trivial "always no seizure" classifier reaches 0.8000 accuracy with 0.0000 recall. Conversely, a plain random split places segments from the same recording in both train and test, inflating scores:

Random Forest F1 · Group CVAll segments of a recording kept together
0.9376
Random Forest F1 · Leaky random splitInflated by recording leakage
0.9580
Random Forest ROC-AUC · Group CVvs 0.9977 on leaky random split
0.9951
Honest Limitations:
  • Recording-level grouping only: Bonn files carry no patient/subject IDs, so splits are grouped by recording rather than person.
  • In-sample demo artifact: the deployed 300-tree Random Forest was trained on all 11,500 Bonn segments; scores on the built-in recordings are in-sample.
  • Single cross-validation seed: evaluation metrics come from one 5-fold split (seed 42); per-fold variation is shown above (F1 ranges from 0.8685 to 0.9835).
  • Benchmark scope: Bonn University segments are short and artifact-free compared to clinical continuous EEG, and this educational model is not intended for clinical diagnosis.
pipeline · bonn dataset · citation

Processing Pipeline & Scientific Grounding

  1. Signal Parsing & Segmentation: Numeric samples (173.61 Hz) are divided into non-overlapping 178-sample (~1.025 s) segments; trailing samples shorter than 178 points are dropped.
  2. Time-Domain Statistics (10 features): mean, population std, min, max, ptp, rms, biased skew and excess kurtosis, line_length, and mean-centered zero_crossings.
  3. Welch Band Power (11 features): Periodic Hann window (nperseg = 128, noverlap = 64, constant detrend), trapezoidal PSD integration across Delta (0.5–4 Hz), Theta (4–8 Hz), Alpha (8–13 Hz), Beta (13–30 Hz), and Gamma (30–60 Hz) as both absolute and relative power, plus dominant_freq.
  4. Float32-Matched Random Forest Inference: Features are cast via Math.fround (matching scikit-learn's float32 tree split inputs) and evaluated across all 300 trees with full float64 thresholds.

Bonn EEG Five-Class Dataset Structure

SetLabel IDDescriptionSegmentsBinary Target
S1Intracranial EEG during epileptic seizure (ictal)2,3001 · Seizure
F2Intracranial EEG from epileptogenic zone (interictal)2,3000 · Non-seizure
N3Intracranial EEG from opposite hippocampal formation (interictal)2,3000 · Non-seizure
O4Surface EEG from healthy volunteers, eyes closed2,3000 · Non-seizure
Z5Surface EEG from healthy volunteers, eyes open2,3000 · Non-seizure
Dataset Citation & Project: Andrzejak RG, Lehnertz K, Mormann F, Rieke C, David P, Elger CE (2001). Indications of nonlinear deterministic and finite-dimensional structures in time series of brain electrical activity: Dependence on recording region and brain state. Physical Review E 64, 061907. Implemented inside biomed-ml ↗.

← Biomedical AI Labbiomed-ml case study ↗ECG Analysis Studio →Heart Risk Studio →