# Contextual Background Estimation for Explainable AI in Temperature Prediction
## 2 Materials and Methods
### Description of Background Estimation Method
The decision of which background group to use and why depends on the user's context and goals. To facilitate the estimation of the reliability of explanations, an index named utility \(\psi\) was created. It can be calculated for each feature (\(x_{1}\) to \(x_{i_{max}}\)) and gathered in the vector \(\mathbf{\
abla}=[\psi_{1},\ldots,\psi_{i_{max}}]\). To calculate these values, mean percentage importance \(\overline{e}_{i}\) and standard deviation \(\sigma_{i}\) have to be used as follows:  
\[\overline{e}_{i}=\frac{\sum_{z=1}^{z_{max}}e_{zi}}{z_{max}}, \tag{6}\]  
\[\sigma_{i}=\sqrt{\frac{\sum_{z=1}^{z_{max}}|e_{zi}-\overline{e}_{i}|^{2}}{z_{ max}}}, \tag{7}\]  
\[\psi_{i}=\frac{\overline{e}_{i}}{\sigma_{i}} \tag{8}\]  
where \(\overline{e}_{i}\) is the mean percentage importance of feature \(x_{i}\) across all backgrounds and \(\sigma_{i}\) is the standard deviation of the percentage importance of feature \(x_{i}\) across all backgrounds. The utility index \(\psi_{i}\) for feature \(x_{i}\) is calculated by dividing \(\overline{e}_{i}\) over \(\sigma_{i}\). The utility index  
Figure 6: Schematically presented importance of each feature for set of time-series sequences chosen for particular \(y_{b}\). favors features with a high mean percentage importance as these features provide more explanatory power. However, it penalizes features with a wide standard deviation of percentage importance. If the mean percentage importance for a feature is high but its fluctuation is also significant, the utility would not recommend making decisions based on it. In contrast, a feature with a slightly lower utility but much lower standard deviation would be more reliable and, therefore, preferred. The process used for the Background Estimation Method is detailed in Algorithm 1. ```
Input: \(f:\) ML model, \(\mathcal{D}:\) Set of time-series sequences from entire dataset, \(y_{b}:\) Base value, \(\mathbf{M}_{e}:\) Time-series sequence to explain, which results in prediction \(f(\mathbf{M}_{e})=y_{e}\) Output: Utility for each feature: \(\psi_{1},\ldots,\psi_{i_{max}}\in\mathbf{\Psi}\) \(\mathbf{E}\leftarrow\mathbf{0}\)// Initialize \(\mathbf{E}\) as an empty matrix foreach\(\mathbf{M}\in\mathcal{D}\)do // Iterate over every sequence in dataset if\(y_{b}-m\leq f(\mathbf{M})\leq y_{b}+m\)then \(\varphi_{1},\ldots,\varphi_{i_{max}}\gets timeSHAP(\mathbf{M},f, \mathbf{M}_{e})\); // Calculate importance as Shapley value \(\varphi\) of each feature (\(x_{1}\) to \(x_{i_{max}}\)). Each Shapley value \(\varphi_{i}\) corresponds to respective \(x_{i}\) \(e_{1},\ldots,e_{i_{max}}\leftarrow\) percentage_of_importance(\([\varphi_{1},\ldots,\varphi_{i_{max}}]\)); // Calculate percentage of importance according to Equation (5) Add \([e_{1},\ldots,e_{i_{max}}]\) to \(\mathbf{E}\) as the next row;  end if  end for \(\mathbf{\Psi}\leftarrow[]\); // Initialize \(\mathbf{\Psi}\) as an empty vector foreach\(i\in[1,\ldots,i_{max}]\)do \(\psi_{i}\leftarrow\frac{mean(E[,j])}{std(E[,j])}\); // Calculate utility according to Equation (8) Add \(\psi_{i}\) to \(\mathbf{\Psi}\) end return\(\mathbf{\Psi}\);
```  
**Algorithm 1**Simplified algorithm for Background Estimation Method that uses timeSHAP as an XAI method