# Contextual Background Estimation for Explainable AI in Temperature Prediction
## 1 Introduction
### Limits of XAI
#### 1.2.2 TimeSHAP and Background  
There are several methods available for explaining predictions made by models using time-series data. One such method is timeSHAP [54], which builds upon the Kernel SHAP framework and incorporates base values to explain predictions. It is schematically described in Figure 4. The method is specifically designed to handle time-series data, taking into account the temporal dependencies within the data. However, when the model input is not a vector with \(i_{max}\) features but a matrix **M** with \(j_{max}\) rows and \(i_{max}\) columns (as is the case with time-series data), the input \(\mathbf{M}_{b}\) used to predict the base value must also be a \(j_{max}\times i_{max}\) matrix.  
The timeSHAP framework consists of several steps, of which only the first two are used to obtain results in this article: (i) pruning and (ii) calculation of feature importance.  
To optimize the calculation, timeSHAP in the first step iterates over the time steps \(t_{j}\) to find the threshold step that divides the input sequence into the most current time steps, which influence the results, and the previous ones, which do not change the prediction. Thereafter, the pruned (old) time steps are treated as one, a separate feature for which a Shapley value is also calculated.  
After pruning, timeSHAP creates a set \(\mathcal{S}\) of coalitions with different combinations of features. Each feature that is not included in the coalition is replaced by a feature from a background \(\mathbf{M}_{b}\). A coalition consisting of all the features is equal to time-series \(\mathbf{M}_{e}\) for prediction \(y_{e}\) that requires explanation, while a coalition consisting of an empty set (no  
Figure 4: Schematic description of results of first two steps of timeSHAP—pruning and calculation of feature importance.  
features) is equal to the background \(\mathbf{M}_{b}\). All the features are replaced with features from the background.  
Currently, the process of background preparation involves calculating the mean values of each feature over the entire dataset, just as in the case of one-dimensional input. However, in the case of two-dimensional input, the mean values of the features (\([\bar{\mathbf{x}}_{1},\ldots,\bar{\mathbf{x}}_{i_{max}}]\)) are not simply used as one vector. Instead, these values are multiplied by the length of the input sequence \(j_{max}\) to receive matrix \(\mathbf{M}_{b}=\mathbf{M}_{i_{max}\times j_{max}}\), which would fit the shape of the input. In this matrix, each column is the same, representing the mean values of the features.  
The two-dimensional sequence used in this context to predict the base value is referred to as the **background**. The background is used to calculate the base value \(y_{b}\) of the model.  
With background \(\mathbf{M}_{b}\) and set of coalitions \(\mathcal{S}\), Kernel SHAP is applied within timeSHAP to approximate the Shapley values corresponding to each feature. Here, Shapley values for features (not time steps) are used. This means that, further in this article, the main focus will be on the importance of features, not on the exact time steps that were important within each feature.  
By using this background, timeSHAP can explain how each feature at each time step contributes to the model's prediction, again showing it as a shift from the base value towards a particular prediction or away from it.