Shapelet-based Model-agnostic Counterfactual Local Explanations for Time Series Classification

Qi Huang, Wei Chen, Thomas Bäck, Niki van SteinarXiv 2024

Abstract

In this work, we propose a model-agnostic instance-based post-hoc explainability method for time series classification. The proposed algorithm, namely Time-CF, leverages shapelets and TimeGAN to provide counterfactual explanations for arbitrary time series classifiers. We validate the proposed method on several real-world univariate time series classification tasks from the UCR Time Series Archive. The results indicate that the counterfactual instances generated by Time-CF when compared to state-of-the-art methods, demonstrate better performance in terms of four explainability metrics: closeness, sensibility, plausibility, and sparsity.

Introduction

As machine learning models grow in complexity, they often function as "black boxes," making it difficult to understand the reasoning behind specific decisions. This lack of transparency is particularly critical in safety-sensitive domains such as medical diagnostics or autonomous systems. In Time Series Classification (TSC), providing interpretable explanations is uniquely challenging due to the inherent temporal dependencies of the data.

Counterfactual explanations address this by identifying the minimal changes required to a specific instance to alter its predicted class—answering the question, "What is the smallest change I could make so that the model would classify this differently?" However, existing methods often fail to produce sparse or plausible results, frequently perturbing entire sequences or introducing unrealistic noise.

Methodology

Time-CF is a post-hoc, model-agnostic algorithm designed to generate realistic and sparse counterfactuals. It treats the underlying classifier as a black box and utilizes a multi-stage pipeline to synthesize explanations.

The Time-CF architecture combining Shapelet Transform and TimeGAN for counterfactual generation.

The process begins with Shapelet Extraction, using a Random Shapelet Transform (RST) to identify discriminative subsequences that characterize a specific class. Simultaneously, a TimeGAN is trained on the training set to learn the data distribution of the target class. To synthesize a counterfactual, the algorithm identifies a shapelet in the original "to-be-explained" instance and replaces it with a statistically realistic segment "cropped" from TimeGAN-generated instances. Finally, an optimization step selects the synthetic instance that successfully flips the classifier's prediction while minimizing the distance from the original data.

Experimental Evaluation

The performance of Time-CF was evaluated using four diverse real-world univariate datasets from the UCR Time Series Archive: ECG200 (electrocardiogram data), Wafer (semiconductor sensor signals), FordA (engine noise), and MoteStrain (humidity/temperature sensors). The method was tested against four distinct classifier types: CNNs, DrCIF, Catch22 with Random Forest, and K-Nearest Neighbors (KNN).

Key Results and Discussion

Time-CF was compared against state-of-the-art methods Native-Guide and mlxtend across four key metrics: closeness, sparsity, sensibility, and plausibility.

Sparsity comparison across datasets, showing Time-CF's superior performance in modifying only minimal segments.

A primary advantage of Time-CF is its high sparsity. While competing methods often modify the entire time series (resulting in near 0% sparsity), Time-CF focuses on minor, discriminative segments, achieving near 100% sparsity across all tested datasets. This makes the explanations far more intuitive for human users, as it highlights a specific "minor segment" responsible for the classification.

Furthermore, by leveraging TimeGAN, the generated counterfactuals maintain high plausibility. Using an Isolation Forest to detect outliers, the researchers found that Time-CF's counterfactuals were generally more realistic than those of competitors, especially on the Wafer dataset. This ensures that the suggested changes actually look like real data, increasing trust for end-users.

Conclusion

Time-CF provides a robust framework for explaining time series classifications through sparse and realistic counterfactuals. By combining the discriminative power of shapelets with the generative capabilities of GANs, it offers a significant improvement over existing techniques in terms of both interpretability and realism. Future work will focus on extending this approach to multivariate data and multi-class classification problems, as well as improving performance on highly imbalanced datasets.

Summary updated

BibTeX
@misc{huang2024shapelet,
  author = {Qi Huang and Wei Chen and Thomas Bäck and Niki van Stein},
  title = {{Shapelet-based Model-agnostic Counterfactual Local Explanations for Time Series Classification}},
  year = {2024},
  eprint = {2402.01343},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.01343},
}
Figure