Skip to content
Ankit Raj Mehta
← all posts

MindTune: reading stress from a consumer EEG headset

TL;DR: We wore a consumer Bluetooth EEG headset through 65 recorded sessions, labelled each second as calm, neutral or stressed, and trained classifiers on it. Tree ensembles came out on top (Extra Trees at about 0.85 weighted F1), but the plots below show why that number needs care: the class differences in the raw signal are small, and the strongest effects come from what the person is doing, not from how they feel.

The setup

The headset is a Toshiba MindTune (px3809N-1ETC). It streams NeuroSky ThinkGear packets over a Bluetooth serial port, about once a second: a signal-quality value, two 0-100 “eSense” scores called Attention and Meditation, and the power in eight frequency bands (delta, theta, low and high alpha, low and high beta, low and mid gamma).

I wrote a Tkinter collector that records the stream while an annotator presses hotkeys. One set of keys marks the participant’s emotion (calm, stressed, delighted, angry, unknown) and another marks events as they happen: speaking, a question being asked, a Q&A stretch, being scolded, being praised, and a tech issue. Every row gets the current emotion and the events that are active, and each session is saved with its markers.

For training, the emotions were folded into three classes: stressed if the annotator marked stressed, calm if they marked calm, and neutral for everything else. The merged dataset has 11,945 rows from 65 sessions.

What the data looks like

Bar and pie chart of samples per class: calm 2,097 (17.6%), neutral 3,662 (30.7%), stressed 6,186 (51.8%)
Half the dataset is labelled stressed

The classes are lopsided. Stressed rows (6,186) outnumber calm ones (2,097) by about three to one, with neutral in between (3,662). So the training split is stratified, and models are compared on weighted F1 rather than plain accuracy, since a model that always answered “stressed” would already be right about half the time.

Eight histograms of log10 band power, one per band from delta to mid gamma; each is roughly bell-shaped, and delta sits highest, around 10 to the 6
Raw band power, on a log scale

The raw band powers span three to four orders of magnitude, and on a log scale each one looks roughly bell-shaped, so the raw values are close to log-normal. Delta is by far the strongest band (around 106, and skewed to the left), and the faster bands sit two orders of magnitude lower. Raw values like these are hard to compare across people and sessions, so the features use each band’s share of the total power instead.

Grouped bar chart of mean band percentage by class: delta about 67%, theta about 17%, every other band under 5%, with the three classes almost identical in each band
Mean share of each band, per class, good-signal rows only

This is the most humbling chart in the project. As shares, delta takes about 67% of the power and theta about 17%, and everything else is under 5%. The calm, neutral and stressed bars are almost the same height in every band. On average, a stressed second looks very much like a calm one.

Radar chart of the eight bands for each class. Calm is at the centre on every axis except delta, where it reaches the edge; neutral is largest on the alpha, beta and low gamma axes; stressed peaks on theta and mid gamma
The same class means, with each band rescaled

The radar chart shows the same kind of class means with each band’s axis stretched between the lowest and the highest class, so the tiny gaps from the bar chart become visible. Read this way, calm has the most delta and the least of everything else, neutral leads on alpha, beta and low gamma, and stressed leads on theta and mid gamma. The shapes look very different, but only because of the rescaling. The bar chart above shows how small the real differences are.

Lower-triangle correlation matrix of the bands, attention, meditation, three band ratios and the label. Delta is negatively correlated with every other band; the label row is near zero everywhere
Pearson correlation between the features and the label

The correlation matrix shows three things:

  • Delta pulls against everything else (r between -0.50 and -0.71). The features are shares of a total, so when delta’s share goes up, every other band’s share has to go down.
  • Neighbouring fast bands move together. High beta and low gamma correlate at 0.61, and low and high beta at 0.53. Theta/beta and the slow/fast ratio correlate at 0.70, which makes sense because both have slow activity on top and fast activity underneath.
  • The label row is almost empty. No single feature correlates with the class by more than 0.09. Whatever separates calm from stressed in this data is not a simple straight-line relationship with any one band, which is part of why the tree models win later.

Attention and Meditation

Four panels: histograms of attention (mean 49.7) and meditation (mean 50.2), a scatter of attention against meditation with r = 0.228, and box plots of per-session averages
The headset's two built-in scores across all samples

The eSense scores are centred near 50 (means 49.7 and 50.2), with a spike at exactly 0. The headset reports 0 when it loses contact, so those rows are dropouts, not very relaxed or very distracted people. Across individual samples, attention and meditation are only weakly related (r = 0.23), and the per-session averages (box plots) put meditation slightly above attention. The correlation matrix above gives a much higher 0.72 for the same pair. That comes from a different notebook with different filtering, and it shows how much the choice of which rows count as “good signal” can move a statistic like this.

Six panels comparing calm, neutral and stressed: attention and meditation density curves, a scatter, box plots, and mean bars; the three classes overlap almost completely
Attention and Meditation split by class

Split by class, the density curves lie almost on top of each other. There is a faint trend in the means: going from calm to stressed, attention rises slightly (about 47 to 50) and meditation drops slightly (about 53 to 51). It points the expected way, but it is far too weak to classify with on its own.

Events: what the person is doing

Bar chart of samples with each event active: Q&A 2,397, speaking 2,128, question 2,041, scolded 594, tech issue 322, praised 26
How many seconds each event marker was active

Q&A, speaking and questions each cover around 2,000 seconds. Being scolded (594) and tech issues (322) are rarer, and praise was marked for only 26 seconds in the whole dataset. Keep that 26 in mind for the next chart.

Heatmap of the percentage change in each band when an event is on versus off. Praised shows +106.5% in low gamma and +82.6% in high beta; Q&A is negative in every band; tech issue is positive in most bands
Change in each band's power while an event is happening, against when it isn't

This heatmap shows how each band’s power changes, in percent, while an event is happening compared with when it isn’t. A few rows stand out:

  • Praised has the largest values on the board: low gamma +106.5%, high beta +82.6%, high alpha +40.4%. They come from just 26 seconds, though, so this is a strong hint rather than a finding.
  • Speaking raises low gamma by 35.5%. That is very likely partly muscle, not mind. A sensor on the forehead also picks up jaw and face muscle activity, and that shows up as high-frequency power.
  • Q&A lowers every band (low alpha -20.7%, theta -14.9%).
  • Tech issues raise almost everything: theta +16.6%, high beta +19.6%, mid gamma +19.0%.
Radar chart of percentage change in attention, meditation, theta/beta and alpha/beta for each event. Praised spikes on meditation; tech issue extends furthest on theta/beta and alpha/beta
Each event's effect on the eSense scores and two band ratios

The same comparison on the higher-level signals gives each event its own shape. Praise sends meditation up sharply and pulls theta/beta down. Tech issues push theta/beta and alpha/beta up the most. Attention barely moves for any event, staying within a few percent of its baseline.

Heatmap and grouped bars of how often each event is active within each class. In stressed samples Q&A is active 56.6% of the time and questions 48.4%; in calm samples speaking is active 51.6%
How often each event is active within each class

This chart turns the question around: given the label, what was going on? Stressed seconds mostly happen during Q&A (56.6% of them) and while questions are being asked (48.4%). Scolding (13.4%) and tech issues (13.7%) are also clearly more common in stressed seconds than in calm ones (5.0% and 0.7%). Calm seconds are mostly speaking (51.6%), so presenting your own material seems to feel fine, and being questioned on it is when stress shows up. That fits everyday experience, and it is also the main risk in the data: event markers predict the label well, and a model that has them can learn “Q&A means stressed” without reading the brain at all.

Whole sessions

Four stacked time-series for session 0091: attention and meditation, slow band shares, fast band shares, and the label with event spans. Attention and meditation flatten and drop to zero for long stretches; the label is stressed at the start, calm in the middle and stressed again from about 400 seconds when speaking and Q&A begin
One full session (0091), second by second

A single session shows what the averages hide. In session 0091, the eSense scores hold flat for long stretches and drop to 0 between roughly 260 and 510 seconds. That is the headset losing contact, not the person. Delta’s relative power swings between about 0.2 and 0.9 from one second to the next, while the fast bands stay low with the odd spike. The bottom panel lines the label up with the events: stressed at the start while a tech issue was active, calm through the middle, then stressed again from about 400 seconds, when speaking, questions and Q&A begin.

Three stacked time-series for session 67: attention mostly above meditation, log theta, alpha and beta power moving together, and spans of speaking, question, scolded and Q&A events
Session 67, with cleaner signal throughout

Session 67 kept good contact the whole way through. Attention sits mostly above meditation. The log power in theta, alpha and beta rises and falls together, so much of the second-to-second change is the overall signal getting louder or quieter (movement, contact) rather than one band changing on its own. That is the reason for using band shares and ratios. The event track shows the structure of the session: speaking early on, then questions and Q&A from about two minutes to the end, with a long scolded stretch between about 280 and 480 seconds.

The classifier

Each row’s features are the band shares, three ratios (theta/beta, alpha/beta, and slow/fast), the eSense scores, and the mean and standard deviation of the last five samples. The rolling window smooths out one-second blips, so a single cough doesn’t flip the prediction.

Horizontal bar chart of weighted F1 for 13 models: Extra Trees about 0.85, Random Forest about 0.82, Decision Tree about 0.78, MLP about 0.77, KNN 0.75, Gradient Boosting 0.72, then linear models around 0.60 to 0.63 and Gaussian Naive Bayes about 0.47
Weighted F1 for 13 models on the same split

The models fall into clear groups. Tree ensembles lead: Extra Trees at about 0.85 and Random Forest at about 0.82, followed by a single decision tree, an MLP and k-nearest neighbours, all between 0.75 and 0.78. The linear models (logistic regression, LDA, linear SVC, SGD, ridge) are bunched around 0.61-0.63, and Gaussian Naive Bayes trails at about 0.47. That gap is what the correlation matrix predicted: no single feature separates the classes, but combinations and thresholds do.

I don’t take 0.85 at face value, though. The split is a random 80/20 over individual rows, so neighbouring seconds of the same session, which share most of a five-second window, end up in both the training and the test set. The event markers and the time into the session were also part of the features in this run. Both make the score optimistic. The live app drops the markers, because nobody presses event keys during a real reading. The honest next test is to hold out whole sessions, or whole people.

The live app

The end result is a small Tkinter app. It reads the headset over Bluetooth, buffers five packets, builds the same features and shows the predicted state in large coloured text. It uses a LightGBM model trained without the event markers. The code is on the classifier branch.

What I’d take away

  • Consumer EEG works, but it is noisy. Dropouts, contact problems and muscle activity are a large part of the signal, so check signal quality before trusting any number.
  • Context is a strong signal, and a trap. The events explain the labels better than the brainwaves do, so any evaluation has to make sure the model isn’t just learning the situation.
  • Validate across sessions. A random row split flatters a model trained on time series.

The collector, notebooks and classifier are in mindtune-brainwave.