Table of Contents
Fetching ...

Explainable time-series forecasting with sampling-free SHAP for Transformers

Matthias Hertel, Sebastian Pütz, Ralf Mikut, Veit Hagenmeyer, Benjamin Schäfer

TL;DR

The paper tackles the challenge of explainable time-series forecasting by eliminating sampling-based SHAP approximations and introducing SHAPformer, a Transformer-based model that enables exact, fast SHAP explanations through attention manipulation and feature grouping. By training with masked inputs and distributing contributions via Owen values, SHAPformer delivers sub-second explanations while maintaining competitive forecast accuracy on real-world load data. It is validated on a synthetic dataset with ground-truth explanations and on the TransnetBW dataset, where it identifies past load as the key predictor and uncovers interpretable temporal and holiday effects. The work demonstrates substantial speedups over permutation-based SHAP methods and provides a practical, open-source package for researchers and practitioners to apply explainable forecasting across domains beyond electrical load.

Abstract

Time-series forecasts are essential for planning and decision-making in many domains. Explainability is key to building user trust and meeting transparency requirements. Shapley Additive Explanations (SHAP) is a popular explainable AI framework, but it lacks efficient implementations for time series and often assumes feature independence when sampling counterfactuals. We introduce SHAPformer, an accurate, fast and sampling-free explainable time-series forecasting model based on the Transformer architecture. It leverages attention manipulation to make predictions based on feature subsets. SHAPformer generates explanations in under one second, several orders of magnitude faster than the SHAP Permutation Explainer. On synthetic data with ground truth explanations, SHAPformer provides explanations that are true to the data. Applied to real-world electrical load data, it achieves competitive predictive performance and delivers meaningful local and global insights, such as identifying the past load as the key predictor and revealing a distinct model behavior during the Christmas period.

Explainable time-series forecasting with sampling-free SHAP for Transformers

TL;DR

The paper tackles the challenge of explainable time-series forecasting by eliminating sampling-based SHAP approximations and introducing SHAPformer, a Transformer-based model that enables exact, fast SHAP explanations through attention manipulation and feature grouping. By training with masked inputs and distributing contributions via Owen values, SHAPformer delivers sub-second explanations while maintaining competitive forecast accuracy on real-world load data. It is validated on a synthetic dataset with ground-truth explanations and on the TransnetBW dataset, where it identifies past load as the key predictor and uncovers interpretable temporal and holiday effects. The work demonstrates substantial speedups over permutation-based SHAP methods and provides a practical, open-source package for researchers and practitioners to apply explainable forecasting across domains beyond electrical load.

Abstract

Time-series forecasts are essential for planning and decision-making in many domains. Explainability is key to building user trust and meeting transparency requirements. Shapley Additive Explanations (SHAP) is a popular explainable AI framework, but it lacks efficient implementations for time series and often assumes feature independence when sampling counterfactuals. We introduce SHAPformer, an accurate, fast and sampling-free explainable time-series forecasting model based on the Transformer architecture. It leverages attention manipulation to make predictions based on feature subsets. SHAPformer generates explanations in under one second, several orders of magnitude faster than the SHAP Permutation Explainer. On synthetic data with ground truth explanations, SHAPformer provides explanations that are true to the data. Applied to real-world electrical load data, it achieves competitive predictive performance and delivers meaningful local and global insights, such as identifying the past load as the key predictor and revealing a distinct model behavior during the Christmas period.
Paper Structure (17 sections, 3 equations, 10 figures, 3 tables)

This paper contains 17 sections, 3 equations, 10 figures, 3 tables.

Figures (10)

  • Figure 1: Overview of the proposed method. The model receives the past target and covariate time-series as input. The features are grouped as indicated by colors. SHAPformer makes predictions based on masked inputs. SHAP values are derived from the marginal feature contributions, defined as the difference of the prediction with and without a feature group. Multiple local explanations of forecasts get combined into global feature importance values and feature dependence plots.
  • Figure 2: Global explanations on the synthetic test data. A: SHAPformer approximates ground truth feature importances well (TFT: Temporal Fusion Transformer). B and C: dependence on the six most important features. The strongest interacting feature is shown in color (interactions mean that the SHAP value depends on the interacting variable). For discrete variables, noise was added in the x-direction for visibility reasons.
  • Figure 3: Global explanations on real-world load data from TransnetBW. A: Feature importance scores by SHAPformer, a Transformer model explained using the Permutation Explainer and the Custom Masker, and Temporal Fusion Transformer (TFT). B: Dependence plots from SHAPformer, with feature values on the x-axis and corresponding SHAP values on the y-axis. The strongest interacting variable is indicated by color. For discrete variables, noise was added in the x-direction for visibility reasons.
  • Figure 4: Local explanations of examples from the real-world load data of TransnetBW. The start of the forecast horizon on the left-hand side is December 1, 2019, 13:00 and on the right-hand side December 17, 2019, 22:00. Panel B shows the prediction as a red line.
  • Figure 5: Overview of the SHAPformer architecture (A) and the masked feature attention mechanism (B). $N$ encoder and decoder blocks are stacked. The masked feature attention is used to drop out variables ($v_2$ in the example in B). Masked self-attention and masked cross-attention are used to drop out time steps (days 2, 3 and 6 in the example in A).
  • ...and 5 more figures