# The Quest for the Best Explanation: Comparing Models and XAI Methods in Air Quality Modeling Tasks
## 2 Materials and Methods
### Methods
#### 2.2.2 Explainability Methods  
The two main explainability-related algorithms that we used were SHAP and LIME. Both algorithms work on a different level and address different problems of explainability; therefore, their usage should be utilized in combination to improve robustness. Firstly, LIME operates on individual points; it explains a single estimation by creating a local approximation of the model around that specific instance (data point). It alters the input by a slight amount (adding some noise) and observes the error generated by this alteration whilst building a simpler, more interpretable model (i.e., a linear regression model). The main principle is to illustrate the original model by using a simple version for a specific prediction. Therefore, it explains why the model made a specific estimation for this data point. From the mathematical point of view, the aim of LIME is to approximate a (generally complex) model \(f\) (commonly a classifier, considered a black-box model), near a specific instance \(x\in R^{d}\) using a local surrogate model \(g\in G\), \(G\) representing a family of interpretable models (usually a linear regression model or a simple decision tree). On this basis, LIME tackles the following optimization problem:  
\[\underset{g\in G}{\text{argmin}}L(f,g,\pi_{x}),+\Omega(g) \tag{3}\]  
where  
* \(f\): the original model;
* \(g\): the interpretable surrogate model (i.e., linear regressor);
* \(\pi_{x}(z)\): a proximity measure between the instance \(x\) and perturbed sample \(z\) (\(z\in Z\) where Z is the set of samples generated around instance x);
* \(L(f,g,\pi_{x})\): a local fidelity loss function that ensures the surrogate model g closely approximates model f in the neighborhood of instance x;
* \(\Omega(g)\): a complexity penalty for the model g, promoting interpretability (e.g., sparsity in a linear model).  
On the other hand, SHAP operates on a global level by considering all predictions in total. It considers the model itself (that works as input) with the final predictions to estimate the so-called Shapley values for each feature that was used to produce those predictions. SHAP is a model-agnostic interpretability method that bases its function in cooperative game theory, more specifically from Shapley values. Shapley values were originally introduced to fairly distribute a total reward among players in a cooperativegame, based on their individual contribution [14]. In our case, each training feature represents a \"player\" and the model output is the total \"payout\".  
The fundamental idea behind SHAP is that each feature importance is estimated by its contribution to every possible subset of features. Given a set of \(\mathcal{F}\) features and a model function \(f\), the Shapley value for a specific feature \(i\) is given by  
\[\phi_{i}=\sum_{S\subseteq F\setminus\{i\}}\frac{|S|!(|F|-|S|-1)!}{|F|!}[f(S \cup\{i\}-f(S)] \tag{4}\]  
where \(S\) is a subset of features excluding \(i\), \(f(S)\) represents the model's output when only features in \(S\) are present, and \(|F|\) is the total number of features. The fraction within the sum represents a weighting factor, as it calculates the distribution of all possible sequences of features where the subset \(S\) appears right before adding the feature \(i\). Therefore, this fraction serves the purpose of weighting the term and ensures that each contributor (player, i.e., feature) is fairly averaged without giving more importance to specific features by chance.