SleepSense
about this project
SleepSense was my machine learning capstone at the University of Maryland, built with Noah Cauchi and Jonathan Moses and advised by Dr. Min Wu. Sleep apnea is diagnosed with an overnight sleep study in a clinic, which is expensive and hard to get, and most adults who have it have never been diagnosed. A lot of people already wear a watch to bed that measures their pulse with a light sensor (PPG). We wanted to know if that signal is good enough to tell someone they should go get a sleep study. We built a pipeline that takes wrist PPG from the DREAMT dataset, removes stretches ruined by movement, cuts the night into 10-second windows, and has six models (three classical, three deep learning) decide whether each window is part of an apnea event. It then turns those windows into an estimate of the apnea-hypopnea index (AHI), the number clinicians use to grade severity, and shows it in a web app. We presented it at the Spring 2026 Design Expo.
We started with a vague goal of helping people with sleep problems, which isn't something you can build or test. Most of the early work was narrowing it down to a question with a number attached: for one person and one night, how close does our AHI estimate get to the one a sleep technician scored? That question decided most of what came after. We split training and test data by patient instead of by window, because windows from the same night look almost the same and a random split would let a model memorize people. We cared more about missed cases than false alarms, because this is a screening tool and the next step after a false alarm is a sleep study, not treatment. We picked our decision threshold without ever looking at the test patients. Each of those choices is written down below with what would make me change it.
The results are modest, and most of this page is about how far they can be trusted. A model that flags apnea a little better than chance can still look good on a poster if you report the right metric. This project is where I learned to compare a result against what a trivial model would score, to look for leakage before celebrating, and to keep "the model picks up apnea-like signal" separate from "this would help a patient," which is a much harder claim we never tested. Those are the habits I want to bring to ML and safety research.
the question
An apnea is a stretch of at least 10 seconds where breathing stops or drops sharply. The body responds: oxygen falls, the nervous system tightens blood vessels, and the heart rate shifts. A wrist PPG sensor can't see breathing, but it can see some of that response in the pulse wave. So the question is whether those changes are strong and consistent enough to find apnea events from the wrist alone, and whether counting them gets close to a clinical AHI.
pipeline
In words:
- Each night is wrist PPG (blood volume pulse) from an Empatica E4, recorded alongside a clinical sleep study that a technician scored for apnea events.
- We drop samples where the accelerometer shows real movement, and flag stretches whose shape doesn't look like a pulse (Hjorth parameters).
- The night is cut into 10-second windows. Each window is labeled apnea or not from the technician's events. Windows scored as wake are removed, since AHI only counts sleep.
- Classical models see summary features: heart rate variability, plus a detector for drops in pulse amplitude (DAP) that we reimplemented from the literature. Deep models see the raw window.
- Every model outputs a probability per window. A threshold turns that into yes or no, the yes windows are turned into events per hour of sleep, and the app shows that as an AHI and a severity tier.
decisions, and what would change them
1. Split by patient, never by window
- Context
- Neighboring 10-second windows from the same night look almost identical. Each person's pulse also has its own shape.
- Decision
- Train and test patients don't overlap. Cross-validation folds are also grouped by patient.
- Instead of
- A random split of windows. It's the default in most tutorials and it would have given us much better numbers, because the model would be tested on people it had already seen.
- Cost
- Fewer, noisier test units. With only 100 people in DREAMT, a single unusual patient moves the results.
- Revisit if
- Never for the headline number. The question is how it does on a new person.
2. Weigh missed cases over false alarms
- Context
- Most windows are not apnea. A model that always says "no" gets high accuracy and is useless.
- Decision
- Report precision, recall, F1, and the Matthews correlation coefficient (MCC) for the apnea class, and lean toward recall. For a screening tool, a false alarm costs a sleep study. A miss costs years of untreated apnea.
- Instead of
- Accuracy, or F1 alone. F1 ignores true negatives, so it can hide a model that flags almost everything.
- Cost
- A recall-leaning model tells more healthy people to get tested. That's a real cost in a tool people would use at home.
- Revisit if
- The tool were used to rule apnea out instead of in. Then false negatives matter even more, and we'd need to report specificity and calibration too.
3. Pick the threshold on out-of-fold predictions
- Context
- The default 0.5 threshold is arbitrary, especially after rebalancing the training data. Tuning it on the test set would make the test number meaningless.
- Decision
- Run patient-grouped cross-validation on the training patients, collect each window's prediction from the fold where it was held out, choose the threshold that maximizes MCC on those, then retrain on all training patients and apply that threshold once to the test patients.
- Instead of
- Training-set predictions (overconfident, so the threshold comes out wrong) or the test set (leakage).
- Cost
- More training runs, and the threshold is tuned for MCC, not for any specific clinical trade-off.
- Revisit if
- A clinician gave us a target, like "catch 90% of moderate cases." Then we'd set the threshold for that instead.
4. Remove movement with a fixed accelerometer cutoff
- Context
- Movement wrecks a PPG signal, and people move during apnea arousals. Cut too much and we delete the events we're trying to find.
- Decision
- Drop samples where the accelerometer magnitude is above 75 units (about 1.17 g, roughly 5 standard deviations above the mean). That removed 0.45% of samples.
- Instead of
- A tighter cutoff. It looked cleaner but would have removed data right next to apnea events.
- Cost
- Smaller movements stay in. We rely on the Hjorth check to catch those.
- Revisit if
- We checked what share of removed samples fall inside or next to labeled events. We didn't, and that's the right way to set this number.
5. Set artifact thresholds per recording
- Context
- Hjorth parameters (activity, mobility, complexity) describe a signal's shape, and their normal range depends on the person and the sensor fit. There are no labeled artifacts in DREAMT to set them from.
- Decision
- For each recording, compute them over overlapping windows and flag anything above that recording's 95th percentile.
- Instead of
- One fixed threshold copied from a paper that used a different sensor.
- Cost
- It always flags about 5% of every recording, clean or messy. A very clean night loses good data. A very noisy night keeps bad data.
- Revisit if
- We hand-labeled artifacts on a few nights. Then the threshold could be fit and checked instead of assumed.
6. Reimplement a published DAP detector, with one change
- Context
- When breathing stops, the pulse wave often gets smaller for a while. Published work detects these decreased amplitude periods (DAPs) with an envelope and an adaptive threshold.
- Decision
- Follow the paper closely: an RMS envelope over two cardiac cycles, a threshold at 60% of the mean of the last 10 seconds of clean envelope, frozen during DAPs, artifacts, and abrupt changes (α = 5). We left out the minimum-duration rule.
- Instead of
- Letting the classical models find amplitude drops on their own from generic features.
- Cost
- Without a minimum duration, short dips count as DAPs. That makes the feature noisier than the paper's version, and our results aren't a fair test of their method.
- Revisit if
- First thing I'd fix. It's a few lines.
how much to trust these results
| Could it be that… | Status | Why |
|---|---|---|
| the model memorized patients? | ruled out | Train and test patients don't overlap, and cross-validation folds are grouped by patient. |
| the threshold was tuned on the answers? | ruled out | It was chosen on out-of-fold predictions from training patients and applied to the test set once. |
| the model is just exploiting class imbalance? | partly | We report MCC, which a model that always says "no" (or always says "yes") can't game. But the poster showed F1, precision, and recall, and some models' precision was close to the share of windows that are apnea. That's what you'd get by flagging windows at random. The table above should be read against that line, not against zero. |
| the numbers on the poster don't add up? | partly | Going back through the poster chart for this page, some bars can't all be right: an F1 can't be higher than both its precision and its recall. The chart's labels were likely swapped in one revision. The table above is rebuilt from the notebook, not read off the poster. |
| counting windows isn't counting events? | not ruled out | AHI counts events per hour. One 30-second apnea covers three windows. If positive windows are counted one by one, AHI comes out too high for long events. Merging back-to-back positive windows into one event fixes most of this, and we should report both. |
| the labels are off at the edges? | not ruled out | A window counts as apnea if it overlaps a technician-scored event, but the body's response (and the PPG change) lags the event by several seconds. Some "wrong" predictions near event boundaries are probably the model seeing the lag. |
| a preprocessing bug weakened the classical models? | partly | We found that our bandpass filter removed the 0.04–0.4 Hz band that the low- and high-frequency HRV features are computed from. |
| the test set is too small to rank models? | not ruled out | We didn't compute confidence intervals or resample by patient. Small gaps between models, especially among the classical ones, should be treated as ties. |
| it works the same on a regular smartwatch? | not ruled out | DREAMT uses a research wristband that exposes raw 64 Hz PPG. Consumer watches sample less often, filter on the device, and often don't give apps the raw signal at all. |
| it works the same on the people who'd use it? | not ruled out | DREAMT was recorded at the Duke Sleep Disorders Center from people already sent for a sleep study (mean age about 56, most with a BMI of 30 or more). In the general population apnea is rarer, so the same model would raise more false alarms per real case. |
limitations
- One night per person. A single night varies a lot. The app is designed around several nights and a trend, but we only had one night per patient to test on.
- Screening, not diagnosis. Even a perfect window classifier answers "does this look like apnea," not "does using this help anyone." That would take a study with outcomes, which we didn't do.
- Apneas and hypopneas together. We treated every scored event as one class. Hypopneas are subtler and probably account for many of the misses.
what I'd do next
- Merge consecutive positive windows into events before computing AHI, and report AHI error with and without it.
- Add patient-level bootstrap intervals to every metric, so ties look like ties.
- Use neighboring windows as context. Adjacent windows are highly correlated, and the model currently sees each one alone.
- Try a Transformer for longer-range patterns across the night, and compare it to the Random Forest, not just to the other deep models.
- Treat apnea as anomaly detection on each person's own normal sleep, which handles the class imbalance directly.
- Add the DAP minimum-duration rule and hand-label artifacts on a few nights to check the 95th-percentile cutoff.