CoolFace
Modelpublic

Rinil-Parmar/ecg-arrhythmia-kan-comparison

sourceHugging Facemitupdated 5mo agoView on Hugging Face
2likes
Model Card

language: en license: mit library_name: pytorch tags:

  • —ecg
  • —arrhythmia
  • —classification
  • —pytorch
  • —cnn
  • —kan ---

ECG Arrhythmia Classification — CNN+MLP vs CNN+KAN

This repository provides two trained PyTorch models for ECG beat classification on the MIT-BIH Arrhythmia Database:

  • —CNN+MLP (baseline)
  • —CNN+KAN (proposed Kolmogorov–Arnold Network head)

Both models classify ECG beats into 5 AAMI-style classes and are evaluated on a held-out test set.

Models and Files

  • —CNN+MLP weights: checkpoints/cnn_mlp.pth
  • —CNN+KAN weights: checkpoints/cnn_kan.pth

Task

Time-series classification of single ECG beats.

Class Labels

LabelMeaning
NNormal / Non-ectopic beat
SSupraventricular ectopic beat
VVentricular ectopic beat
FFusion beat
QUnknown / Unclassifiable beat

Data

  • —Dataset: MIT-BIH Arrhythmia Database (PhysioNet)
  • —Lead: MLII (lead 0)
  • —Sampling rate: 360 Hz
  • —Beat window: 256 samples (128 before + 128 after annotation)
  • —Normalization: per-beat z-score
  • —Split: stratified train/val/test = 70% / 15% / 15%

Training

  • —Optimizer: Adam
  • —Learning rate: 1e-3
  • —Weight decay: 1e-4
  • —Batch size: 128
  • —Epochs: up to 50, early stopping (patience 10)
  • —Loss: class-weighted cross-entropy
  • —Gradient clipping: max norm 1.0 (for KAN stability)

Results (Test Set)

Overall Metrics

ModelAccuracyMacro F1Weighted F1Macro AUCParamsInference (ms/sample)
CNN+MLP0.98000.90190.98090.9965175,9730.3664
CNN+KAN0.94760.81670.95400.9924285,2800.6308

Per-Class F1

ClassCNN+MLPCNN+KAN
N0.98890.9690
S0.81110.5968
V0.95770.9070
F0.75890.6270
Q0.99300.9836

How to Use (PyTorch)

python
import torch
from src.models.cnn import ECGCNN
from src.models.cnn_kan import ECGCNNWithKAN

# Choose model
model = ECGCNN(num_classes=5)      # or ECGCNNWithKAN(num_classes=5)

# Load weights
ckpt = torch.load(CHECKPOINT_PATH, map_location="cpu")
model.load_state_dict(ckpt["model_state"])
model.eval()

# Example input: [batch, 1, 256]
x = torch.randn(1, 1, 256)
proba = torch.softmax(model(x), dim=1)
pred = proba.argmax(dim=1).item()