RLcapstone.ai

Inter-Patient Generalization in ECG Arrhythmia Classification

A 1D convolutional neural network that classifies individual heartbeats into four clinical categories — and a rigorous study of the inter-patient generalization gap, in which validation performance of ~96% falls to 44% on previously unseen patients.

Not a medical device. This is an educational study of biomedical signal classification on a public research dataset. It does not diagnose cardiac conditions and must not inform any medical decision. Read the full disclaimer.

Try it in your browser →
Classifies real heartbeats on your device — nothing is uploaded.

Android application
ECG Check · Android (arm64) · ~22 MB · v1.0.0

A native application running the same on-device model as the browser demonstration — offline, with no data uploaded.

Download APK →
Installation (sideloading)
  1. On an Android phone, open this page and tap Download APK.
  2. When prompted, permit your browser to install from unknown sources (Android requests this once, for safety).
  3. Open the downloaded file and tap Install.

Educational application — not a medical device and not a diagnosis. Distributed outside the Play Store and signed with a debug key, so Android displays a warning before installation; this is expected for a sideloaded educational build. Built for arm64 devices. Android only at present — an iOS build can be produced from the same codebase.

📄 Read the full capstone reportPDF, opens in your browser

Summary

TaskClassify each heartbeat into 4 AAMI classes (Normal, Supraventricular, Ventricular, Fusion)
DatasetMIT-BIH Arrhythmia Database — 48 records, ~100,000 cardiologist-labeled beats
SignalSingle lead (MLII), 360 Hz, one 260-sample window centered on each beat
Model1D CNN — four convolutional blocks, 77k parameters (312 KB)
ResultOn unseen patients: 70% accuracy, 44% macro-recall — strong on ventricular beats, weak on supraventricular
DeploymentONNX, on-device inference in the browser demonstration (28 KB model)

Why accuracy alone is misleading

Approximately 90% of the beats in this dataset are normal, so a trivial model that labels every beat "normal" attains 90% accuracy while detecting none of the abnormal beats that matter — the worst possible model presented with a favorable metric. The primary metric is therefore macro-recall, the unweighted mean of the per-class recall rates, which improves only when the model handles the rare, clinically important classes.

From signal to labeled beats

Each MIT-BIH record is a half-hour, two-channel ECG with a cardiologist's annotation on every beat. The pipeline reads the standard MLII lead, extracts a 260-sample (~0.7 s) window centered on each beat, normalizes it, and maps the fine-grained annotation symbols into the four AAMI super-classes. The single most consequential design decision is the train/test split, which is performed by patient, not by beat. A by-beat split allows a single patient's heartbeats to appear in both partitions, so the model learns to recognize individuals rather than arrhythmias — precisely the failure mode examined next.

Training progression and the generalization gap

During training, validation macro-recall climbs above 96% and appears excellent. However, that validation set shares patients with the training data. On the true test set — 22 entirely unseen patients — the honest macro-recall is 44%. The gap between the climbing curve and that figure is the central finding of the project.

Per-class analysis

The per-class breakdown is instructive. On unseen patients the model detects 86% of ventricular beats — genuinely useful — but only 9% of supraventricular beats. This is not random; it indicates what the model can and cannot perceive.

A ventricular beat has a distinctly abnormal waveform morphology, which a shape-sensitive model detects readily. A supraventricular beat, in contrast, is nearly identical in shape to a normal beat; its defining feature is timing — it occurs prematurely. Because the model processes each beat in isolation, with no representation of rhythm, it is structurally blind to the one feature that distinguishes the class it fails on.

Next iteration (v2)

The remedy follows directly from the diagnosis: provide the model with timing information. Adding RR-interval features — the intervals to the preceding and following beats — would allow the model to perceive prematurity, the hallmark of supraventricular beats. This is the planned next iteration, and its result will appear in the table above.