# Contextual Background Estimation for Explainable AI in Temperature Prediction
## 2 Materials and Methods
### Description of Background Estimation Method  
To address the issues of fluctuating Shapley values and the presence of different types of time-series sequences, a second new method was developed. This method offers deeper insights into the shifts caused by specific backgrounds, thereby providing more comprehensive information about the model's behavior. The main idea behind the Background Estimation Method is that, given a **predictive model**\(f\), a **sequence for prediction**\(y_{e}\), and a **reference target**\(y_{b}\), the validity of the explanations can be assessed. This method quantifies the extent to which the explanations vary depending on the background context for a given \(y_{e}\). Furthermore, it evaluates the reliability of the results produced by the applied XAI method for each feature. Additionally, it captures the dispersion of the importance across selected backgrounds. For example, if a user wants to explain why a model predicted a specific value \(y_{e}\) in comparison to \(y_{b}\), the user can select from dataset \(\mathcal{D}\) all time-series sequences \(\mathbf{M}\) that result in the prediction of \(y_{b}\), following the steps of the Mean Background Method depicted in Figure 5. This results in a new set of backgrounds \([\mathbf{M}_{1},\dots,\mathbf{M}_{z_{max}}]\). However, instead of creating a single mean background, each sequence is used as a background individually, one at a time. This approach results in numerous Shapley values for each feature. Assuming there are 200 sequences (\(z_{max}=200\)) that meet the requirement (3), then there is a new set of backgrounds \([\mathbf{M}_{1},\dots,\mathbf{M}_{200}]\). In this situation, each feature \(x_{i}\) receives 200 Shapley values, with one value calculated for each background \(\mathbf{M}_{z}\). The resulting importance can be organized into a matrix \(\mathbf{E}_{z_{max}\times i_{max}}\), where \(z_{max}\) represents the number of backgrounds \(\mathbf{M}\) and \(i_{max}\) represents the number of features \(x_{i}\). Thus, each column contains all Shapley values calculated for a given feature. To enhance interpretability, the elements of the matrix \(\mathbf{E}\) are transformed into percentages of importance. The values \(e_{zi}\) represent the importance as a percentage of the distance between the prediction \(y_{e}\) and the reference base value \(y_{b}\). The matrix \(\mathbf{E}\) consisting of the importance percentage can be presented as follows:\[\mathbf{E}= \begin{bmatrix}e_{11}&e_{12}&\cdots&e_{1i_{max}}\\ e_{21}&e_{22}&\cdots&e_{2i_{max}}\\ \vdots&\vdots&\ddots&\vdots\\ e_{z_{max1}}&e_{z_{max2}}&\cdots&e_{z_{maxi_{max}}}\end{bmatrix} , \tag{4}\]  
\[e_{zi}=\frac{\varphi_{zi}\cdot 100}{|y_{c}-y_{b}|} \tag{5}\]  
where index \(i\) is used to represent feature \(x_{i}\), index \(z\) is used to represent background meeting a requirement from Equation (3), and \(\varphi_{zi}\) represents the Shapley values corresponding to a given feature \(i\) and background \(z\), used to calculate it. In Figure 6, importance percentages of three features are presented. The three columns, corresponding to features \(x_{1},x_{2}\), and \(x_{3}\) from matrix \(\mathbf{E}\), are used to form histograms visible in Figure 6. This visualization makes it easy to understand the distribution of importance. It is also much easier to compare importance of each feature for different values of \(y_{b}\) when they are in percentages. If the distribution of percentage importance \([e_{1i},\ldots,e_{z_{max}i}]\) for a particular feature \(x_{i}\) is wide and short, it indicates high fluctuations, making the importance assigned to this feature uncertain and potentially risky to use. Conversely, if the distribution is narrow and tall, the importance for the feature is stable across the backgrounds for the given \(y_{b}\). In cases where the importance for a feature consists of multiple distinct distributions, further analysis is required. It may be possible to identify groups of backgrounds that cause this distinction.