From Beats to a Classifier
Introduction
Project introduction
From Beats to a Classifier
You have written the pieces of a heartbeat classifier, which are baseline removal with a moving average, the slope energy that turns every QRS complex into one bump, R peak picking with an adaptive threshold and a refractory period, fixed windows around every beat, and per-class sensitivity and precision.
In the notebook they run on the first 15 minutes of 44 recordings from the MIT-BIH Arrhythmia Database, about 50,000 beats that cardiologists labeled one by one. The functions from the coding problems come already written. Seven cells ask you for new work that only makes sense on real recordings, such as choosing the baseline window by measuring it, finding out why the detector loses most beats of one patient, splitting the beats by patient, and testing a fix on more than one seed.
What you will find out
Your detector finds 98.3% of the marked beats, and Pan and Tompkins' search-back rule raises that to 99.8% by rescuing a patient whose tall ventricular beats pushed the threshold above every normal beat. A small 1D CNN then learns to sort beats into normal (N), supraventricular (S), ventricular (V) and fusion (F).
Shuffle the beats and split them in half, and the network gets 96.7% of the test beats right. Train on 22 patients and test on 22 others, as de Chazal and colleagues proposed in 2004, and accuracy falls to 77.3%, S beats are almost never found, and a few patients lose most of their normal beats to wrong V calls. You will see why the first number was too good, and why only the second tells you what would happen with the next patient. This is a learning exercise and not a diagnostic tool.
One patient's heartbeats
6 s of a real ECGHow the notebook is organized
01
Find heartbeats
Clean the signal, build the detector, and score it against the cardiologists on every patient.
02
Random split
Cut a window around every beat, train a small CNN, and score it class by class on shuffled beats.
03
New patients
Split by patient, find out why the score falls, and run the whole pipeline on one new recording.
Build and honestly test a heartbeat classifier
Run the whole build in the browser, about 45 minutes.