Table of Contents
Fetching ...

From Prototypes to Sparse ECG Explanations: SHAP-Driven Counterfactuals for Multivariate Time-Series Multi-class Classification

Maciej Mozolewski, Betül Bayrak, Kerstin Bach, Grzegorz J. Nalepa

TL;DR

This work tackles the challenge of explainability in multivariate time-series ECG classification by introducing a prototype-driven, SHAP-based framework for sparse, physiologically coherent counterfactual explanations. It combines PHAR-derived interval rules, DTW-based medoid prototypes, and R-peak aligned sparsification to generate near real-time explanations that preserve waveform morphology while highlighting minimal, clinically meaningful changes. The approach is evaluated on the PTB-XL dataset, achieving strong validity for common conditions (e.g., MI) and improved temporal stability, while acknowledging challenges with underrepresented classes like Hypertrophy. The contributions include a fully offline prototype bank, a lightweight online explanation pipeline, and an expert-informed visualization strategy, collectively enabling interactive, clinically usable explainability platforms for AI-assisted ECG diagnosis.

Abstract

In eXplainable Artificial Intelligence (XAI), instance-based explanations for time series have gained increasing attention due to their potential for actionable and interpretable insights in domains such as healthcare. Addressing the challenges of explainability of state-of-the-art models, we propose a prototype-driven framework for generating sparse counterfactual explanations tailored to 12-lead ECG classification models. Our method employs SHAP-based thresholds to identify critical signal segments and convert them into interval rules, uses Dynamic Time Warping (DTW) and medoid clustering to extract representative prototypes, and aligns these prototypes to query R-peaks for coherence with the sample being explained. The framework generates counterfactuals that modify only 78% of the original signal while maintaining 81.3% validity across all classes and achieving 43% improvement in temporal stability. We evaluate three variants of our approach, Original, Sparse, and Aligned Sparse, with class-specific performance ranging from 98.9% validity for myocardial infarction (MI) to challenges with hypertrophy (HYP) detection (13.2%). This approach supports near realtime generation (< 1 second) of clinically valid counterfactuals and provides a foundation for interactive explanation platforms. Our findings establish design principles for physiologically-aware counterfactual explanations in AI-based diagnosis systems and outline pathways toward user-controlled explanation interfaces for clinical deployment.

From Prototypes to Sparse ECG Explanations: SHAP-Driven Counterfactuals for Multivariate Time-Series Multi-class Classification

TL;DR

This work tackles the challenge of explainability in multivariate time-series ECG classification by introducing a prototype-driven, SHAP-based framework for sparse, physiologically coherent counterfactual explanations. It combines PHAR-derived interval rules, DTW-based medoid prototypes, and R-peak aligned sparsification to generate near real-time explanations that preserve waveform morphology while highlighting minimal, clinically meaningful changes. The approach is evaluated on the PTB-XL dataset, achieving strong validity for common conditions (e.g., MI) and improved temporal stability, while acknowledging challenges with underrepresented classes like Hypertrophy. The contributions include a fully offline prototype bank, a lightweight online explanation pipeline, and an expert-informed visualization strategy, collectively enabling interactive, clinically usable explainability platforms for AI-assisted ECG diagnosis.

Abstract

In eXplainable Artificial Intelligence (XAI), instance-based explanations for time series have gained increasing attention due to their potential for actionable and interpretable insights in domains such as healthcare. Addressing the challenges of explainability of state-of-the-art models, we propose a prototype-driven framework for generating sparse counterfactual explanations tailored to 12-lead ECG classification models. Our method employs SHAP-based thresholds to identify critical signal segments and convert them into interval rules, uses Dynamic Time Warping (DTW) and medoid clustering to extract representative prototypes, and aligns these prototypes to query R-peaks for coherence with the sample being explained. The framework generates counterfactuals that modify only 78% of the original signal while maintaining 81.3% validity across all classes and achieving 43% improvement in temporal stability. We evaluate three variants of our approach, Original, Sparse, and Aligned Sparse, with class-specific performance ranging from 98.9% validity for myocardial infarction (MI) to challenges with hypertrophy (HYP) detection (13.2%). This approach supports near realtime generation (< 1 second) of clinically valid counterfactuals and provides a foundation for interactive explanation platforms. Our findings establish design principles for physiologically-aware counterfactual explanations in AI-based diagnosis systems and outline pathways toward user-controlled explanation interfaces for clinical deployment.
Paper Structure (47 sections, 10 equations, 14 figures, 12 tables)

This paper contains 47 sections, 10 equations, 14 figures, 12 tables.

Figures (14)

  • Figure 1: Overview of the proposed framework.
  • Figure 2: ECG explanation generation pipeline: from query ECG classification through prototype retrieval, R-peak alignment, and sparsity optimization to final counterfactual visualization.
  • Figure 3: 12-lead ECG multiclass classification architecture: raw signals (1000 time points $\times$ 12 leads) are processed through convolutional feature extraction (blue), batch normalization (purple), ReLU activations (pink), and max-pooling (green); then temporally modeled by a GRU (orange), transformed in latent space via RealNVP flow (lavender), and classified with an MLP head (yellow).
  • Figure 4: k-Means clustering results in MDS space for Conduction Disturbance (CD) class.
  • Figure 5: Silhouette analysis for optimal cluster selection in the Conduction Disturbance (CD) class.
  • ...and 9 more figures