The question in one sentence
A standard EEG uses about 21 electrodes. We ask: if we use only 8, can a computer still spot seizures about as well? Fewer electrodes means a simpler, cheaper headset for home use.
Below is the whole pipeline, start to finish, in plain language. No step is a black box — you can see exactly what the program measures and how it decides.
Start with brain-wave recordings
EEG electrodes sit on the scalp and record tiny electrical voltages from the brain, hundreds of times per second (256 times/second here). Each electrode pair is a channel. During a seizure, the brain's electrical activity changes in ways that often show up in the signal — sharper, more rhythmic, higher-energy waves.
We use the CHB-MIT dataset: real recordings from pediatric epilepsy patients, where doctors have already marked the exact start and end of every seizure. Those marks are our "answer key."
Cut the recording into 4-second windows
A one-hour recording is far too long to judge all at once, so we slice it into short 4-second windows (overlapping by half, so we don't miss anything that falls on a boundary). The model looks at one window at a time and answers a yes/no question: does this 4 seconds look like a seizure?
Each window gets a label from the doctors' answer key: seizure if it overlaps a marked seizure, otherwise background.
Turn each window into numbers (the features)
A computer can't learn from a raw squiggle directly, so for every window we measure a set of meaningful numbers. These are chosen to be understandable, not mysterious:
Shape of the wave (time-domain)
- Line length — how wiggly / jagged it is (spikes raise this)
- Energy & variance — how big and how spread-out the swings are
- Peak amplitude — the single largest spike
- Skew & kurtosis — how lopsided or spiky the distribution is
Rhythm of the wave (frequency-domain)
- Band power — how much energy sits in each brain-wave band: delta, theta, alpha, beta, gamma
- Spectral entropy — whether the rhythm is focused or chaotic
- Peak frequency — the dominant rhythm in that window
We compute these for each channel, then summarize across channels (average, strongest, and spread). The result is one tidy list of numbers per window — the "fingerprint" of those 4 seconds.
Teach a model to tell seizure from background
We use a Random Forest — think of it as a committee of hundreds of simple yes/no decision trees. Each tree learns rules like "if theta-band power is high AND the line length spikes, lean toward seizure." They vote, and the majority wins.
Seizures are rare (most of an hour is normal brain activity), so we tell the model to weight the rare seizure windows more heavily — otherwise it could score well by just guessing "background" every time.
We train on part of the data and keep the rest hidden for testing, so the model is always judged on windows it has never seen.
Make a prediction, then group flags into alarms
For each test window the model outputs a probability. Above 50% we flag it as a seizure. But a single real seizure spans many windows, and we don't want to count each flagged window as a separate alert. So we merge nearby flags (within 20 seconds) into one alarm event — the way a real monitor would raise one alert, not dozens.
Check the guesses: two honest scores
Seizure sensitivity
Of the real seizures, how many did we raise an alarm for?
detected ÷ total seizures
This is the safety number. Missing a seizure is the worst outcome, so we want this high.
False alarms per hour
How many alarms fired when there was no seizure, per hour of recording?
false alarms ÷ hours
This is the cost number. Every false alarm wastes a clinician's review time, so we want this low.
We run this twice — once with all 21 channels, once with just 8 — on the exact same recording, and compare. If the 8-channel scores stay close, the cheaper setup is justified.
The math, exactly as the code computes it
Every formula below maps to a real line in our feature or scoring code. For a window we write the EEG samples of one channel as \(x_1, x_2, \dots, x_N\) (here \(N = 4\text{s} \times 256\,\text{Hz} = 1024\) samples).
Time-domain features (the shape of the wave)
Frequency-domain features (the rhythm of the wave)
We estimate how the signal's power is spread across frequencies using the Welch power spectral density \(S(f)\) (the signal is split into overlapping pieces, each Fourier-transformed, and the results averaged to reduce noise). From \(S(f)\) we read off:
The model: Random Forest
The \(T\) features above (per channel, summarized across channels) form a vector \(\mathbf{z}\). A Random Forest of \(B\) decision trees each outputs a class, and the forest's seizure probability is simply the fraction of trees that vote "seizure":
Each tree \(t_b\) splits the data to reduce Gini impurity \(\;G = 1 - \sum_k p_k^2\;\) (lower = purer, more one-class groups). Because seizure windows are rare, we weight each class inversely to how often it appears, so the rare seizure class isn't ignored: \(\; w_k = \frac{\text{total samples}}{(\#\text{classes}) \cdot (\text{samples in class } k)} \).
Turning a probability into a decision
The two scores
We also report the window-level F1 score, the harmonic mean of precision and recall: \(\; F_1 = 2\cdot\dfrac{\text{precision}\cdot\text{recall}}{\text{precision}+\text{recall}} \), which balances "don't miss seizures" against "don't over-flag."
▶ See these equations run on a real seizure window
Every number below was computed by our actual pipeline on one real 4-second window from patient chb06 (starting 1,722 seconds into the recording), on a single EEG channel. Nothing here is made up.
Input
- 4 seconds × 256 samples/sec → N = 1024 samples
- First voltage readings: 125.2, 120.9, 117.0, 111.2 … µV
Time-domain equations
| Variance \( \sigma^2 = \tfrac1N\sum(x_i-\mu)^2 \) | = 4,418.8 |
| Line length \( \sum\lvert x_{i+1}-x_i\rvert \) | = 6,786 µV |
| Energy \( \sum x_i^2 \) | = 4,525,327 |
| Skew | = −0.242 |
| Kurtosis | = −0.411 |
Frequency-domain equations (band power \( \int S(f)\,df \))
| Delta (0.5–4 Hz) | 39.4% of total power |
| Theta (4–8 Hz) | 20.8% |
| Alpha (8–13 Hz) | 4.1% |
| Beta (13–30 Hz) | 7.8% |
| Gamma (30–80 Hz) | 0.6% |
| Spectral entropy \( -\sum p_f\log_2 p_f \) | = 3.502 |
| Peak frequency \( \arg\max S(f) \) | = 1.0 Hz |
These ~17 numbers (per channel) form the feature vector the Random Forest votes on. Important: on this single window, theta was only ~1.6× background and line length wasn't elevated — no one feature or channel decides it. Only when all features across all channels are combined (where theta averages 6–13× higher) does the seizure clearly separate out. That's exactly why we use a trained model, not a single hard threshold.
How we make the comparison fair
- Same patient, same recording, same windows — the only thing that changes between the two runs is how many channels the model sees.
- Same train/test split, so neither montage gets an easier test.
- We report results per patient (the model is calibrated to each person), which mirrors how a real home monitor would be set up.
From a detector to a product: the alert tiers
A raw seizure flag is not an action. The goal is a wearable home monitor that loops in the right person at the right urgency. So the detector's two signals — how confident it is and how long the abnormal activity lasts — decide one of three actions:
Dismiss
A brief or low-confidence blip. No action — this absorbs most false alarms so the patient and clinician aren't bothered.
Notify clinician
Moderate confidence, or confident but short. Ask a human: "is this a false positive, or are you OK?"
Escalate
High confidence and sustained. After a patient non-response window, a real device would contact emergency services.
The two gates we use: notify at probability ≥ 0.50; escalate only when probability ≥ 0.80 and the episode lasts ≥ 20 seconds. Requiring both confidence and persistence is what prevents a single twitchy window from triggering an emergency.
Why this answers the "false positives" problem
On our data, the one false alarm the 8-channel model produced did not become a false emergency — it was downgraded to a "notify the clinician" event, because it wasn't confident-and-sustained enough to escalate. Every real seizure still reached the emergency tier. In other words, we don't chase an impossible zero-false-positive model; we design the system so that imperfect detections fail safe.
This is a demonstration of the decision logic on a small dataset. The prototype never contacts a clinician or emergency services, and an auto-escalating medical alert device would require clinical validation and regulatory clearance before any real use.
What this does and doesn't prove
- Does: show that, for these patients, dropping to 8 electrodes kept seizure detection close to the full 21-electrode setup.
- Doesn't: prove it works for everyone — our sample is small (a few patients, one seizure each). It's promising, not conclusive.
- Doesn't: predict seizures ahead of time — it detects them as they happen.
- Doesn't: prove dollar savings yet — fewer electrodes should mean simpler, cheaper equipment, but we haven't measured actual cost.
- This is a research prototype, not a medical device.