Chapter 4 — A Classical Baseline (The Thing to Beat)
Think of it like this: imagine teaching someone to sort laundry without ever explaining what a "shirt" or "sock" actually is. Instead, you hand them a measuring tape and a checklist: how big is it, how stretchy, does it have sleeves. They sort using only those numbers — no eyes needed, just measurements. That's exactly what a classical classifier does with sleep stages: instead of a human eyeballing the squiggle like you did in Chapters 1–3, it gets a handful of numbers per epoch (the band-power values from Chapter 3) and sorts using only those.
The Ingredients: Features
Band power (how much delta, theta, alpha, sigma, beta) is the main ingredient, but real pipelines often add a few more measurements per epoch: Hjorth parameters (three simple numbers describing a signal's overall activity, mobility, and complexity — think of them as "how big, how fast-changing, how jagged" in one line each) and entropy measures (roughly: how unpredictable or random the signal looks, moment to moment). Conceptually, this entire step is what YASA and Dreamento's own DreamentoScorer already do under the hood.
The Judge: Random Forest
A Random Forest is like asking a big group of slightly-different-opinion friends to each look at the same measurements and make an independent guess, then going with whatever the majority says. Each "friend" is a decision tree that was shown a slightly different slice of the training data, so their individual mistakes tend to be different — and different mistakes tend to cancel out when you average them, which is why the group vote usually beats any single tree.
The One Rule That Makes or Breaks This Chapter
Here's the part that trips up almost everyone the first time: you must always split your train and test data by subject, never by epoch. If even a few epochs from the same person end up on both sides of the split, the model can partly "cheat" by recognizing that specific person's individual brain signature — skull thickness, electrode placement quirks, personal rhythm — rather than genuinely learning sleep stages in general. The accuracy number you get back will look great and mean almost nothing.
Reading the Result: the Confusion Matrix
A single accuracy percentage hides the interesting part. A confusion matrix is a grid showing exactly which stage the model guessed versus what the real label was, for every combination — so instead of "73% accurate," you get to see precisely where the mistakes cluster. Spoiler, consistent with everything so far in this course: watch the N1/REM corner.
THE LAB
Load two different people's real sleep recordings, extract band-power features, train a Random Forest on one person, test on the other (never mixed), and read your own confusion matrix.
Try It: Leaky or Legit?
The next lesson is a dedicated game drilling the subject-split rule specifically — it's the single most common beginner mistake in this entire field, worth a few minutes of deliberate practice before you write a line of training code.
DONE WHEN
You have a working baseline with a confusion matrix, and can explain where it fails — almost certainly N1 and REM confusion, same as every human scorer and every model in this course. That accuracy number is the thing Chapter 6's neural network has to actually beat, not just match.