T-Explainer: A Model-Agnostic Explainability Framework Based on Gradients
Evandro S. Ortigossa Fábio F. Dias Brian Barr Claudio T. Silva Luis Gustavo Nonato


Violation of Bell inequalities in an analogue black hole
    Mathieu Isoard
    
========================================================





    The development of machine learning applications has increased significantly in recent years, motivated by the remarkable ability of learning-powered systems to discover and generalize intricate patterns hidden in massive datasets. Modern learning models, while powerful, often exhibit a level of complexity that renders them opaque black boxes, resulting in a notable lack of transparency that hinders our ability to decipher their decision-making processes. Opacity challenges the interpretability and practical application of machine learning, especially in critical domains where understanding the underlying reasons is essential for informed decision-making. Explainable Artificial Intelligence (XAI) rises to meet that challenge, unraveling the complexity of black boxes by providing elucidating explanations. Among the various XAI approaches, feature attribution/importance XAI stands out for its capacity to delineate the significance of input features in the prediction process. However, most existing attribution methods have limitations, such as instability, when divergent explanations may result from similar or even the same instance. In this work, we introduce T-Explainer, a novel local additive attribution explainer based on Taylor expansion endowed with desirable properties, such as local accuracy and consistency, while stable over multiple runs. We demonstrate T-Explainer's effectiveness through benchmark experiments with well-known attribution methods. In addition, T-Explainer is developed as a comprehensive XAI framework comprising quantitative metrics to assess and visualize attribution explanations.

    
    Keywords: Black-box models, explainable artificial intelligence, XAI, interpretability, local explanations.This work has been submitted to the IEEE for possible publication. Copyright may be transferred without notice, after which this version may no longer be accessible.





§ INTRODUCTION



    Artificial Intelligence is not a vision for the future. It is our present reality. 
    Terms such as Neural Networks, Machine Learning, Deep Learning, and other facets of the Artificial Intelligence universe have seamlessly shifted from futuristic concepts to near-ubiquitous elements in our daily discourse.
    The confluence of recent strides in hardware processing capabilities, abundant data accessibility, and refined optimization algorithms has facilitated the creation of intricate and non-linear machine learning models <cit.>. In the contemporary landscape, those models have achieved unprecedented performance levels, surpassing what was deemed inconceivable just a few years ago, outperforming human abilities and previously known methods in central research areas <cit.>.

    The complex non-linear structures and vast number of parameters inherent in such models pose a challenge to transparent interpretation and comprehension of the rationale behind their decisions. Such characteristic transforms those models into black boxes, wherein one can discern only what inputs are provided and what outputs are produced without a clear understanding of the internal decision-making processes <cit.>. 
    The absence of transparency gives rise to trust-related apprehensions, hindering the effective deployment of potent machine-learning models in critical applications <cit.>. Additionally, it poses challenges in adhering to emerging regulatory norms observed in numerous countries <cit.>, thereby complicating compliance efforts.
    
    Widely used machine learning models are impenetrable as far as simple interpretations of their mechanisms go <cit.>.
    In this context, Explainable Artificial Intelligence (XAI) has emerged to address the challenges outlined above, seeking to provide human-understandable insights into the complexities of models that are inherently challenging to interpret. Significantly, the field of explainability has progressed with the introduction of innovative methodologies, and research focused on discerning the strengths and limitations of XAI models <cit.>.
    Feature attribution/importance methods <cit.> are of particular relevance, aiming to quantify the contribution of individual input variables on predictions made by black-box models <cit.>. 
    
    While feature attribution methods prove valuable, they come with drawbacks that diminish the trust and confidence placed in their application.
    For instance, different methods can result in distinct explanations for the same data instances, making it difficult to decide which outcome to believe <cit.>. 
    Moreover, many well-known methods, including SHAP <cit.> and LIME <cit.>, suffer from instability, producing different explanations from different runs on a fixed machine learning model and dataset <cit.>.

    To be considered stable, an explanation method must produce consistent explanations in multiple runs on the same and similar instances. 
    Stability is a fundamental objective in XAI, as explainability methods that generate inconsistent explanations for similar instances (or even for the same instance) are challenging to trust. 
    If explanations lack reliability, they become essentially useless. 
    Therefore, to be considered reliable, an explanation model must, at a minimum, exhibit stability <cit.>.

    In this work, we introduce , a novel post-hoc explanation method that relies on the solid mathematical foundations of Taylor expansion to perform local and model-agnostic feature importance attributions.
     is a local additive explanation technique with desirable properties such as local accuracy, missingness, and consistency <cit.>. 
    Furthermore,  is entirely deterministic, guaranteeing stable results across multiple runs and delivering consistent explanations for similar instances.
    
    To evaluate the quality and usefulness of the , we performed several quantitative comparisons against well-known local feature attribution methods, assessing the stability and additivity preservation of such XAI methods.
    We implemented the  integrated with the visualization tools available in the SHAP library, incorporating a suite of quantitative metrics to evaluate feature importance explanations, rendering the  a comprehensive XAI framework.
    
    In summary, the main contributions of this work are:
    
    
        
  * , a stable model-agnostic local additive attribution method derived from the solid mathematical foundation of Taylor expansions. It faithfully approximates the local behavior of black-box models using a deterministic optimization procedure, enabling reliable and trustworthy interpretations.
        
        
  * A comprehensive set of comparisons against well-known local feature attribution methods using quantitative metrics, aiming mainly to assess stability and additivity preservation.
        
        
  * A Python library that integrates  with other explanation tools, making the proposed method easy to use in different applications. The framework, datasets, and all related materials are openly available online[
        The GitHub link will be provided upon acceptance.

        
        ].
    




§ RELATED WORK



    Several XAI techniques have been proposed to deal with black-box models.
    To contextualize our contributions, we focus the following discussion on post-hoc feature importance/attribution methods <cit.>. 
    A more comprehensive discussion about XAI can be found in several surveys summarizing existing approaches and their properties <cit.> and metrics for evaluating explanation methods <cit.>.
    
    <cit.> proposed one of the first approaches to identify the features most impacting a model prediction. Breiman's solution is model-specific (Random Forests) and involves permuting the values of each feature and computing the model loss. Given the feature independence assumption, the method identifies the most important features by prioritizing those that contribute the most to the overall loss. 
     
    More general approaches, the so-called model-agnostic techniques, can (theoretically) operate with any machine learning model, regardless of the underlying algorithm or architecture.
    In this context, LIME (Local Interpretable Model-agnostic Explanations) <cit.>, SHAP (SHapley Additive exPlanations) <cit.>, and their variants <cit.> are model-agnostic methods widely employed to explain machine learning models' behavior in healthcare <cit.>, financial market <cit.>, and engineering <cit.> applications. 
    
    Although broadly used, LIME and SHAP have significant drawbacks that demand care when using such techniques. 
    For instance, LIME lacks theoretical guarantees about generating accurate simplified approximations for complex models <cit.>. 
    Moreover, different simplified models can be fit depending on the random sampling mechanism used by LIME, which can lead to instability to small data perturbation and, sometimes, entirely different explanations by just running the code multiple times <cit.>.
    
    SHAP has a solid theoretical foundation derived from game theory <cit.> that grants SHAP desirable properties such as local accuracy, missingness, and consistency <cit.>.
    However, the exact computation of SHAP values is NP-hard, demanding Monte Carlo sampling-based approximations <cit.>, which introduces instability similar to the LIME method, even in its model-specific variants <cit.>. 
    To avoid instability, deterministic versions of LIME <cit.>, optimization <cit.>, and learning-based <cit.> approaches have been proposed, but with the price of increasing the number of parameters to be tuned.
    
    Gradient-based methods are another important family of explanation approaches.
    Those methods attribute importance to each input feature by analyzing how their changes affect the model's output, relying on gradient decomposition to quantify those effects.
    Vanilla Gradient <cit.> introduced the use of gradients to feature attribution tasks. The method computes partial derivatives at the input point 𝐱 with a Taylor expansion around a different point 𝐱^' and a remainder bias term, for which neither is defined <cit.>. 
    Monte Carlo sampling can be used to estimate derivatives, but it makes Vanilla Gradient suffer from instability and noise within the gradients.

    LRP (Layer-wise Relevance Propagation) <cit.> identifies properties related to the maximum uncertainty state of predictions by redistributing an importance score back to the model's input layer <cit.>.
    The Integrated Gradients method <cit.> quantifies the feature importance by integrating gradients from the target input to a baseline instance. 
    Input × Gradient <cit.> highlights influential regions in the input space by computing the features' element-wise product and corresponding gradients from the model's output. 
    DeepLIFT (Deep Learning Important FeaTures) <cit.> is based on LRP's importance scores to measure the difference between the model's prediction of a target input and baseline instance.
    
    The stability of gradient-based methods depends on factors such as the gradient propagation, the model's complexity, and the baseline choice <cit.>. 
    Additionally, most of those methods are designed specifically for explanation tasks in Neural Networks and other models with differentiable parameters, which impairs their application to classifiers such as Random Forests and SVMs.
    
     differs from the methods described above in three main aspects: 
    (i) it is deterministic,  defines an optimization procedure based on finite differences to estimate partial derivatives, thus being stable by definition; 
    (ii)  relies on just a few hyperparameters, rendering it easy to use; 
    and (iii)  is not dependent on baselines. 
    Moreover, the  is built upon the solid mathematical foundations of Taylor expansion, which naturally endows it with desirable properties similar to those in SHAP. 
    Although , in theory, is designed to be applied to differentiable models, we show experimentally that it also produces interesting results operating with non-differentiable models, which makes  more flexible than previous gradient-based methods. 
    




§ THE T-EXPLAINER



    In this Section, we introduce the theoretical foundations, properties, and computational aspects of the proposed  method.
    
    Let 𝐗 be a multidimensional dataset where each data instance 𝐱 = (x_1,…, x_n) ∈𝐗 is a vector in ℝ^n and f be a  model. For simplicity, let's assume that f is a binary classification model trained on 𝐗, that is, f(𝐱) ∈ [0,1] accounts for the probability of 𝐱 belonging to class 1, and (1 - f(𝐱)) is the probability of belonging to class 0. All the following reasoning can be extended to regression models. 
    
    The model f can be seen as a real-valued function:
    
    
    f : 𝐗→ [0,1] ⊂ IR

    
    As a real function, f can be linearly approximated through first-order Taylor's expansion:
    
    
    f(𝐱 + 𝐡) ≈ f(𝐱) + ∇ f(𝐱) ·𝐡

    
    where 𝐡 is a displacement vector corresponding to a small neighborhood perturbation of 𝐱 and ∇ f(𝐱) is the gradient (linear transformation) of f in 𝐱, given by:
    
    
    ∇f(𝐱) = [∂ f(𝐱)/∂ x_1, … , ∂ f(𝐱)/∂ x_n].


    The i-th gradient element corresponds to the partial derivative of f concerning the i-th attribute of 𝐱. 
    Note that the gradient of f at 𝐱 corresponds to the Jacobian matrix when f is a real-valued function. 
    The dot product between the gradient and the displacement vector 𝐡 is a linear map from ℝ^n to ℝ, being well-known as the best linear approximation of f in a small neighborhood of 𝐱 <cit.>.
    Therefore, the gradient can be used to analyze how small perturbations in the input data affect the model output.
    The right side of Equation <ref> is a linear equation that approximates the behavior of f nearby 𝐱, and by being a linear mapping, it is naturally interpretable. 
    In other words, the gradient of a model f can be used to generate explanations.

    The formulation above resembles the Vanilla Gradient <cit.> Taylor expansion-based procedure to compute saliency maps. The difference is that, in our case, the attributions are not dependent on class information and do not rely on further parameters specific to the model's architecture. In addition, T-Explainer differs from previous gradient-based methods by relying on additive explanation modeling and a deterministic optimization procedure to approximate gradients, as described below.

    Let 𝐡=𝐳^'∈ℝ^n be a perturbation in 𝐱, that is, 𝐱^'=𝐱+𝐳^' is a point in a small neighborhood of 𝐱. 
    The  can thus be defined as an additive explanation modeling g_𝐱, given by:
    
    
    g_𝐱(𝐳^') = ϕ_0 + ∑_i=1^nϕ_i z^'_i

    
    where ϕ_0=𝔼[f(𝐗)] represents the expected prediction value, and ϕ_i = ∂f(𝐱)/∂ x_i.
    The prediction expected value is a statistical value that is not trivial to estimate for an arbitrary dataset.
    In practice, it is computed through the average model output across the training dataset 𝐗 when the feature values 𝐗_i are unknown.
    As a fundamental property of additive explanations, Equation <ref> approximates the original predicted value f(𝐱) locally by summing its feature importances <cit.>.
    
    The explanation model g_𝐱 is a local attribution method, i.e., there is a g_𝐱 for each 𝐱. 
    By definition, the  is an additive feature attribution method, as defined by <cit.>, meaning that the importance value attributed to each feature can reconstruct the model prediction by summating those importance values. 
    The coefficient ϕ_i indicates the feature attribution/importance of the i-th attribute to the prediction made by f in 𝐱. 
    In , the feature attribution ϕ_i has a simple and intuitive geometric interpretation, corresponding to the projection of ∇ f(𝐱) on the i-th feature axis. 
    Therefore, the more aligned the gradient ∇ f(𝐱) and the i-th axis of the feature space, the more important the i-th feature is to the decision made by f.




 §.§ T-Explainer Properties



    According to <cit.>, a “good” explanation method must hold three important properties, namely, Local Accuracy, Missingness, and Consistency. In the following, we show that the  approximates Local Accuracy while holding Missingness and Consistency.


    

  §.§.§ Local Accuracy

    

        The local accuracy property, as defined by <cit.>, states that if f(𝐱 + 𝐳^') = g_𝐱(𝐳^') = ϕ_0 + ∑_i=1^nϕ_i z^'_i, then g_𝐱 holds the local accuracy property. The  does not exactly satisfy this property but rather approximates it. By construction, we have:
        
        
    f(𝐱 + 𝐳^') ≈ g_𝐱(𝐳^') = ϕ_0 + ∑_i=1^nϕ_i z^'_i

        
        and, from the Taylor expansion remainder theorem <cit.>, there is an upper-bound to the approximation error given by:
        
        
    f(𝐱 + 𝐳^') - g_𝐱(𝐳^') = O(𝐳^'^2).



    

  §.§.§ Missingness

    

        The missingness property states that if a feature x_i has no impact on the model decision, then ϕ_i = 0 (see <cit.>). 
        In our context, a feature i having no impact in f means that f does not vary (increase or decrease) when only such i-th feature is changed (otherwise, the feature would impact the model decision). 
        In other words, f(x_1,…, x_i + z^'_i,…, x_n) - f(x_1,…, x_i,…, x_n) = 0, thus, there is no variation in the i-th direction and the partial derivative ϕ_i = ∂ f(𝐱)/∂ x_i = 0, ensuring that the  holds the missingness property.


    

  §.§.§ Consistency

    

        Let f and f̃ be two binary classification models. Let's use the notation 𝐱^'\ i to indicate that the i-th feature is disregarded in any perturbation of 𝐱 (z^'_i = 0 in any perturbation, so x^'_i \ i = x_i). An explanation method is consistent if (see <cit.>), fixing 𝐱, f̃(𝐱^') - f̃(𝐱^'\ i) > f(𝐱^') - f(𝐱^'\ i) implies ϕ_i(f̃) > ϕ_i(f).
        
        Suppose that f̃(𝐱^') - f̃(𝐱^'\ i) > f(𝐱^') - f(𝐱^'\ i) holds in a small neighborhood of 𝐱, in particular,
        
        
        
    f̃(x_1+z^'_1, …, x_i   +z^'_i, …, x_n+z^'_n) - 
       f̃(x_1+z^'_1, …, x_i, …, x_n+z^'_n) > 
    
                f(x_1+z^'_1, …,     x_i+z^'_i, …, x_n+z^'_n) - 
       f(x_1+z^'_1, …, x_i, …, x_n+z^'_n)

        
        for z^'_i∈ (-δ, 0) ∪ (0, δ).
        
        Define s̃(z^'_i) = f̃(𝐱^') - f̃(𝐱^'\ i)/z^'_i and s(z^'_i) = f(𝐱^') - f(𝐱^'\ i)/z^'_i, from Equation <ref> we know that s̃(z^'_i) > s(z^'_i) for z^'_i∈ (-δ, 0) ∪ (0, δ). Assuming that f̃ and f are differentiable in 𝐱, then lim_z^'_i→ 0s̃(z^'_i)=∂f̃(𝐱)/∂ x_i and lim_z^'_i→ 0s(z^'_i)=∂f(𝐱)/∂ x_i exist, thus, from the Limit Inequality Theorem:
        
        
    ϕ_i(f̃)=∂f̃(𝐱)/∂ x_i > ∂f(𝐱)/∂ x_i=ϕ_i(f)

        
        showing that the  holds the consistency property (the Limit Inequality Theorem ensures that, given two functions s̃, s : (a,c)∪(c,b) ⊂ IR→ IR, if s̃(x) > s(x) for all x ∈ (a,c)∪(c,b) and the limits lim_x→ cs̃(x)=A and lim_x→ cs(x)=B exist, then A > B).
        
        According to <cit.>, the Shapley-based explanation is the unique possible additive feature attribution model that (theoretically, see <cit.>) satisfies Local Accuracy, Missingness, and Consistency properties. As demonstrated above, the  approximates Local Accuracy while holding Missingness and Consistency. Therefore, the  is one of the few XAI methods that get close to SHAP regarding theoretical guarantees.


    

 §.§ T-Explainer: Computational Aspects

    

        
            
        Figure <ref> illustrates the step-by-step pipeline of  for feature attribution.
        Computing the gradient of a known real-valued function is (theoretically) simple, demanding to take the partial derivatives of the function. However, we need to calculate partial derivatives of an arbitrary black-box model f, which was previously trained and holds complex internal mechanisms. To that end, we perturb the instance 𝐱 attribute-wise and compute the respective change in the model's output, approximating the partial derivatives through centered finite differences <cit.>:
        
        
    FD_f(𝐱)=f(𝐱+𝐡)-f(𝐱-𝐡)/2𝐡.

        
        Finite differences are well-established approaches to approximate differential equations, replacing the derivatives with discrete approximations (such transformation results in computationally feasible systems of equations) <cit.>.
        
        Specifically, we rely on the centered finite difference because that approach simply averages two one-sided perturbations of each attribute, resulting in a second-order accurate approximation with an error proportional to 𝐡^2 <cit.>.  
        The centered finite difference approximation of the partial derivatives demands to set up the magnitude of the perturbation 𝐡. 
        The displacement 𝐡 must be small enough to generate a perturbation close to the input data 𝐱. 
        By definition, the derivatives of f are computed by making 𝐡→ 0 in Equation <ref>.
        In other words, we have to set 𝐡 to a small value.
        
        In practice, if 𝐡 is too small, it can generate significant round-off errors or singularity cases. 
        On the other hand, if 𝐡 is too large, it can lead to truncation errors and inappropriate approximations. 
        As far as we know, there is no closed solution to determine an optimum value to 𝐡.
        To solve this issue, we developed a 𝐡 optimizer method based on a binary search that minimizes a mean squared error (MSE) cost function.
        The method runs over the [h_min, h_max] interval, searching for an optimal 𝐡 to produce a good approximation of f(𝐱) from Equation <ref>. 
        We set h_min with the minimum distance between any two instances on the dataset, i.e., h_min=min_i,j=1^n||𝐱_i-𝐱_j||, ∀i≠j, 𝐱_i, 𝐱_j ∈𝐗.
        The optimization method is formulated as follows:
        
        
    ∇ f(𝐱) = 𝐡∈ [h_min, h_max]arg min ℒ(f,𝐡,ϵ_𝐱) + θ(∇ f_𝐱)

        
        where ℒ is the cost function (MSE in our case),
        ∇ f_𝐱 represents the approximated value of the gradient ∇ f(𝐱) in each iteration of the 𝐡 optimizer algorithm computing the method in Equation <ref> on Equation <ref>, ϵ_𝐱 is the cost threshold upper-bounded by h_min^2 <cit.>, and θ is a method that ensures the numerical stability of the optimization process by checking if 𝐡 is keeping the gradient (Jacobian matrix) ∇ f_𝐱 non-singular (or full-rank). 
        It is important to highlight that local perturbations must preserve the data's normalization range to avoid model extrapolations <cit.>.
        Further details about the optimization process are given in the [appendix]Appendix Section.
        This approach can find the gradient ∇ f(𝐱) of a binary-class model or even the entire Jacobian related to all the model's output probabilities. 
        Once the gradient is estimated in 𝐱, the importance of each attribute is computed as ϕ_i = ∂f(𝐱)/∂ x_i.
        
        
        The explanations must remain consistent with the model's behavior in the instance's locality to ensure meaningful interpretability.
        Through the 𝐡 optimization process, T-Explainer attributes feature importance using Taylor's expansion for each instance tailored to its local characteristics. 
        In other words, the T-Explainer is primarily designed as a local explainer.
        According to <cit.>, simultaneously achieving local and global fidelity in XAI is challenging because aggregating local explanations to estimate global feature importance might be ineffective due to local explanations being instance-specific and often inconsistent with global explanations.
        However, the adaptive 𝐡 optimization strategy of  is flexible enough to be extended and generate aggregated views while preserving local relationships, enhancing consistent and interpretable explanations locally and also at global levels.


    

  §.§.§ Handling Categorical Data

    

        All the considerations outlined above assume the attributes are continuous numerical data. However, most datasets are not limited to numerical data but also encompass categorical (nominal or qualitative) features. Handling categorical data is challenging, as many learning models cannot directly process nominal features, demanding numerical conversions. Different approaches can be applied to encode categorical values as numerical representations, including the well-known one-hot encoding <cit.>.

        Numerical encodings introduce challenges for XAI methods, particularly for the gradient-based ones. 
        Nominal values represented with one-hot encode become binary constant values (zeros and ones), thus being discontinuous attributes where partial derivatives can not be properly estimated, inducing the explainer to erroneously attribute null importance to features that may significantly impact the prediction.
        
        T-Explainer has a modular design that enhances flexible additions or improvements of functionalities. 
        To address the challenges of categorical features, we implemented a mechanism to handle one-hot encoded columns into the T-Explainer framework. 
        Once the user identifies the one-hot encoded categorical attributes, a procedure transforms them into intervals through continuous perturbations.
        Specifically, the 0 and 1 values (resulting from one-hot encoding) are uniformly perturbed with displacement in the interval δ∈ (-0.5, 0.5), creating a range of values around 0 and 1, simulating a continuous set of values around these two values. 
        
        The continuity induction procedure is performed over a copy of the training dataset, with the perturbed columns being normalized to the same interval of the numerical features (typically in the [0,1] range). After that, transfer learning is applied in a copy of the original model, fitting it with the perturbed training dataset (the categorical fitted model). Finally, the T-Explainer runs on the newly trained model.
        In summary, predictions of instances holding categorical features are explained using the T-Explainer's core implementation. However, we incorporated a preliminary layer in T-Explainer's pipeline to handle categorical data.

        The perturbation radius δ can impact the accuracy of the categorical fitted model, making it disagree with the original model. 
        However, the disagreement varies depending on the training data.
        In our experiments, the proposed transformation of categorical attributes to numerical ones does not significantly impact the accuracy of the categorical fitted model for perturbations into small intervals.
        We fixed δ= 0.1 as the perturbation radius, which ensured the accuracy preservation.




§ QUANTITATIVE METRICS



    In this Section, we describe the evaluation metrics integrated into the T-Explainer framework. Relative Input Stability (RIS) and Relative Output Stability (ROS) <cit.> are metrics used to evaluate the stability of local explanations to changes in input data and output prediction probabilities, respectively. 
    We followed the basic definitions in <cit.> but introduced improvements to address the issues described below.
    
    Given 𝒩_𝐱 a neighborhood of perturbed instances 𝐱^' around 𝐱, with e_𝐱 and e_𝐱^' representing the attribution vectors explaining 𝐱 and 𝐱^', and f(𝐱) and f(𝐱^') the output prediction probabilities of 𝐱 and 𝐱^', RIS and ROS metrics are formally defined as:
    
    
    RIS(𝐱,𝐱^',e_𝐱,e_𝐱^')= max_𝐱^'e_𝐱 - e_𝐱^'/e_𝐱_p/max(𝐱 - 𝐱^'/𝐱_p, ϵ_c)    and

    
    
    ROS(𝐱,𝐱^',e_𝐱,e_𝐱^')= max_𝐱^'e_𝐱 - e_𝐱^'/e_𝐱_p/max(f(𝐱) - f(𝐱^')/f(𝐱)_p, ϵ_c)

    
    ∀𝐱^'∈𝒩_𝐱, with p defining the l_p norm used to measure the changes and ϵ_c>0 as a clipping threshold to avoid zero division. 
    The larger the RIS or ROS values, the more unstable the method is related to input or output prediction perturbation.
    
    RIS and ROS handle values close to zero in the normalization processes. 
    However, the original metrics implemented in <cit.> applied a clip method that ignores significant negative values by handling any negative value as a small value. 
    Then, we designed a clip method that preserves significant values, both positive and negative, while discarding those close to zero. 
    The original implementations may also ignore instances near the model's decision boundaries. We solved that issue by sampling perturbations of each 𝐱, sorting the perturbed data based on the distance to 𝐱, and generating a neighborhood holding a minimum set of perturbed instances. 
    This way, we ensure coverage and avoid measurement omissions or potential crashes in the metrics. 
    Additionally, we extended RIS and ROS to evaluate the mean changes and the respective standard deviations, in addition to the original maximum change in explanations. 
    
    
    A novel metric, Run Explanation Stability (RES), was added to our framework to measure the local stability through multiple runs on non-perturbed inputs. 
    RES assesses the consistency of several explanations for the same instance under the same settings, with higher values indicating lower stability rates. 
    Given n explanations g_𝐱i,…,g_𝐱n of the same instance 𝐱, with each g_𝐱i as a scalar representing the prediction approximation (see Equation <ref>), let g̅_𝐱 be the mean explanation from those n explanations. We define the RES metric as:

    
    RES(g_𝐱,g̅_𝐱)= max_k=1^ng̅_𝐱-g_𝐱k,   ∀𝐱∈𝐗.

    
    The Reiteration Similarity metric inspired the rationale behind RES <cit.>; however, we simplified the formulation using standard deviation as the similarity measure.
    
    Another new addition is the Faithfulness of an Additive Explanator (FAE) metric, which assesses how an additive feature importance explainer preserves the primary property of local accuracy, i.e., the model prediction should be reconstructed by the summation of the importance values as in Equation Equation <ref> <cit.>. 
    Given an output prediction probability f(𝐱) and its explanation g_𝐱, we define the FAE metric as the frequency or ratio in which f(𝐱)-g_𝐱≥ϵ, ∀𝐱∈𝐗, with ϵ a tolerance threshold. 
    Aiming to analyze better each model's additiveness, the FAE metric also computes the mean values in which f(𝐱)-g_𝐱.
    In this case, the smaller the FAE mean, the closer the approximations between f(𝐱) and g_𝐱 will be from the threshold ϵ and, thus, the more “additive” the model is (the explainer is more faithful regarding the local accuracy property).

    RIS, ROS, RES, and FAE metrics are unitless quantifiers with no “ideal” desirable values. Reasonable values depend on the context of the application, meaning those metrics must be interpreted relatively by comparing their results across XAI methods <cit.>.





§ EXPERIMENTS



    This section presents the configurations and outcomes of the experiments undertaken to evaluate , employing a diverse set of datasets, models, and comparison metrics.
    In all experiments described below, we are evaluating local explanation tasks.


    

 §.§ Experimental Setup

    

        We trained Multi-Layer Perceptions (MLP) Neural Networks from scikit-learn (<https://scikit-learn.org/>) and Gradient-boosted Tree Ensemble classifiers (Random Forests-based) from the XGBoost gradient boosting library <cit.> as the black-box models used throughout the experiments. 
        Logistic Regressions and SVMs could also be viable alternatives, but we focused on Neural Networks and Random Forests due to their wide adoption in Machine Learning.
        The models were trained with a dataset split of 80% for training and 20% for testing. Such division was achieved using the train_test_split method from scikit-learn, with a consistent shuffling seed across all datasets. We conducted a Grid Search to determine the hyperparameters that optimize the models' performance.
        
        For the MLPs, we initialized the hyperparameters search using powers of 2 for the number of neurons in the hidden layers, following standard practices in this context <cit.>. 
        We employed the ReLU activation function, Stochastic Gradient Descent as the optimizer and the log-loss function.
        We evaluated alternative activation functions and optimizers, but they did not yield gains.
        The Tree Ensemble model's hyperparameters were defined by specifying ranges for the number of decision tree estimators and the maximum depth of each estimator, utilizing cross-entropy loss as the evaluation metric for classification.
        
        We selected three different MLP models from the hyperparameters tunning: a three and a five hidden layers neural network holding 64 neuron units per layer (3H-NN and 5H-64-NN, respectively) and a five-layer neural network with [64, 128, 128, 128, 64] neurons in each layer (5H-128-NN).
        All the neural network models use a learning rate of 0.01, alpha 0.0001, and maximum training epochs of 500.
        The selected neural networks achieved better performances considering our classification tasks.
        We based our architectures on previous works <cit.>, with extra neural units and additional layers significantly increasing the training time without noticeably increasing performance.
        
        Following our hyperparameters tunning, the Tree Ensemble classifiers (XRFC) have 500 estimators, a maximum depth of 6, a learning rate of 0.01, and a gamma equal to 1. 
        All the other hyperparameters are the libraries' default for Neural Networks and Tree Ensembles. 
        Those models are used as the base black boxes for comparing T-Explainer against SHAP <cit.>, LIME <cit.>, and three Gradient-based methods <cit.> such as Integrated Gradients, Input × Gradient, and DeepLIFT. 
        Specifically, we used the SHAP explainer for neural networks and the TreeSHAP explainer <cit.> for tree-based classifiers. 
        Although SHAP, LIME, and Gradient-based methods were proposed a few years back, we benchmark T-Explainer with them because they continue to be the most widely used feature attribution explainers in research and practice <cit.>.
        
        For each experiment requiring data perturbation, we used the NormalPerturbation method from OpenXAI <cit.> to generate perturbed neighborhoods with μ=0, σ^2=0.001, a flip percentage ε_p=0.0001, and the perturbation maximum distance of h_min/2, ensuring neighborhoods with small perturbations around each instance. We also specified the clipping threshold to handle values close to zero as ϵ_c=±10^-5 and the l_p norm as the Euclidean (p=2). 
        
        To avoid round-off issues and enhance readability, we use scientific notation to represent values larger than 10^5, while values smaller than 10^-10 will be taken as zero.


    

 §.§ Synthetic Data

    

        We generate two different synthetic datasets comprising 1000 instances each. The first is a 4-dimensional (4-FT) dataset where each instance 𝐱 is generated as follows. We distribute the target label 𝐲∈ [0, 1] equally across each dataset half; thus, each class has 500 instances. Conditioned to the value of 𝐲, we sample the instance 𝐱 as x_1:2∼𝒩(μ_y, Σ_y). We choose μ_0=[0,0]^T and μ_1=[-2,2]^T, Σ_0=[[1,1],[-1,1]]^T and Σ_1=𝐈, where μ_0, Σ_0 and μ_1, Σ_1 denote the means and covariance matrices of the Gaussian distributions associated with instances in classes 0 and 1 respectively. The features x_1:2 are called core_1 and core_2. Random values are assigned to the features x_3:4 (noise_1 and noise_2). Such configuration results in a dataset holding two predictive (important) and two random noise (non-important) features with a small mixture area between the important features to introduce a degree of complexity to the predictive process.
        
        The second synthetic dataset is more robust. It is a 20-dimensional (20-FT) dataset created using the OpenXAI synthetic data generation tool, whose algorithm is described in <cit.>. According to the authors, the algorithm ensures the creation of a dataset that encapsulates feature dependencies and clear local neighborhoods, key properties to guarantee the explanations derived from this synthetic dataset remain consistent with the behavior of the models trained on such data.
    
        We used the XRFC and 3H-NN models over the synthetic datasets experiments. The XRFC classifier achieved 96% accuracy on the 4-FT data and 83.5% accuracy on the 20-FT synthetic dataset, while the 3H-NN model achieved 97.5% accuracy on the 4-FT data and 83.5% accuracy on the 20-FT dataset.
        Note that we are not basing our benchmark experiments on synthetic datasets with massive amounts of instances. We know it is necessary to use a reasonable amount of data to train and test machine learning models. According to <cit.>, well-known feature importance methods become unstable in tasks with more than ten dimensions. In this sense, data dimensionality is more critical to assessing the stability of feature importance methods than the number of instances. Thus, we generated synthetic datasets with enough instances (1000 for each dataset) to train our models and assess the XAI methods.
        
        Figures <ref> and <ref> present explanations generated by TreeSHAP and T-Explainer for the same instance predicted with the XRFC model. 
        As expected, TreeSHAP attributed the most significant importance to feature core_1 (followed by core_2). 
        However, TreeSHAP attributed a negative signal to core_1, pushing the additive reconstruction (see Equation <ref>) of TreeSHAP to -0.013, while the true prediction for this instance is 0.0134. 
        Thus, the TreeSHAP explanation indicates that the instance belongs to the opposite class, disagreeing with the model prediction (and also the instance label) and violating the Local Accuracy property. 
        T-Explainer also points to core_1 (and core_2) as the most important feature but with a correct positive signal. 
        
        Table <ref> provides a broad view of the scenario illustrated in Figure <ref>. We used the FAE metric (considering 0.01 as the tolerance threshold) to assess Local Accuracy preservation by T-Explainer, SHAP, and TreeSHAP when applied to the XRFC model on the 4-FT dataset. TreeSHAP, the model-specific version of SHAP, presented a faithful additivity rate of 0.507 of its explanations. T-Explainer preserved the additivity property with a 0.425 rate, slightly lower than TreeSHAP. However, the T-Explainer was far better than the SHAP model-agnostic version of the SHAP explainer framework. 
        In contrast, Table <ref> shows that the T-Explainer outperforms all the other additive methods regarding Local Accuracy preservation on the 20-FT dataset holding a 0.862 preservation rate. 
        
        
    
        
        
        
        
        
        
        
        
        
        Table <ref> shows the RIS, ROS, and RES stability metrics for T-Explainer, TreeSHAP, and LIME, explaining the XRFC model on the 4-FT data. Notice that TreeSHAP has the best RIS, ROS, and RES results.
        The good performance of TreeSHAP is expected, as the 4-FT is a low-dimensional dataset, and TreeSHAP takes advantage of it by relying on a deterministic version of Shapley values computation <cit.>. 
        Table <ref> shows the same metrics for the 3H-NN model on the 4-FT dataset. The T-Explainer performed considerably better than the other XAI methods in terms of RIS (7× better than DeepLIFT), ROS, and also the RES metric.
        
        
        
        
        
        
        
        
        
    
        Tables <ref> and <ref> depict the results from the XRFC and 3H-NN models on the 20-FT dataset.
        From Table <ref>, we can see that T-Explainer is superior to TreeSHAP and LIME in the RIS and ROS metrics for both maximum and mean values. 
        TreeSHAP reached a close performance regarding maximum ROS, but T-Explainer is considerably better on the average ROS. 
        Similar results can be observed in Table <ref>, where T-Explainer beat all the other explainers in terms of RIS (3× better than Integrated Gradients), with slightly better performance than Integrated Gradients in the mean ROS but outperforming all the other explainers in maximum ROS. 
        SHAP was the most unstable method, which can be justified in the context of the 20-FT dataset because, in high-dimensional spaces, SHAP uses a random sampling algorithm rather than the deterministic one, leading to unstable explanations <cit.>. Moreover, SHAP is also prone to suffer from extrapolations <cit.>.
        
        
        
        
        
        
        
        
        
        
        In general, Tables <ref>, <ref>, <ref>, and <ref> show that T-Explainer is robust regarding different stability metrics, being among the best performance methods, especially when data dimensionality is high.
    
        The T-Explainer's performance when dealing with the XRFC model, which is a non-differentiable model, is also remarkable. Therefore, although not theoretically supported, the T-Explainer might perform well even when applied to generate explanations for non-differentiable machine learning models.


    

 §.§ Real Data

    

        This Section extends the evaluations and comparisons by applying real data from different domains. Specifically, we run experiments using four well-known real datasets with distinct properties regarding dimensionality, the presence of categorical attributes, and size. 
        
        The Banknote Authentication <cit.> is a 4-dimensional dataset containing 1,372 instances with measurements of genuine and forged banknote specimens. 
        The German Credit <cit.> comprises 9 features (numerical and categorical) covering financial, demographic, and personal information from 1,000 credit applicants, each categorized into good or bad risk. 
        
        The Home Equity Line of Credit (HELOC) dataset provided by FICO <cit.> consists of financial attributes from anonymized applications for home equity lines of credit submitted by 9,871 real homeowners. The task in the HELOC dataset is to predict whether an applicant has a good or bad risk of repaying their HELOC account within two years. 
        The largest dataset in our study is HIGGS <cit.>, which contains 28 features about simulated collision events to distinguish between Higgs bosons signals and a background process. The original HIGGS dataset contains 11 million instances, but we used the 98,050 instances version available at OpenML <cit.>. 
        Table <ref> summarizes the real datasets.
    
        
    
        The experiments with real data have been conducted using only the neural network models, as some of the explanation models with which T-Explainer is compared are specifically designed for neural networks. Moreover, the neural network models are differentiable, thus meeting the theoretical requirements that support the T-Explainer technique.
        We further discuss tree-based models in Section <ref>.
     
        For the experiments with Banknote Authentication and German Credit datasets, we selected the 3H-NN model.
        From Table <ref>, one can see that T-Explainer is less stable than Integrated Gradients, but it is the second-best method on average for RIS and ROS (closely tied with Integrated Gradients for RES). 
        Table <ref> presents the stability tests using the German Credit data. 
        The original version of the dataset has 20 numerical and categorical attributes. Still, it is practically impossible to directly apply it in a machine learning task due to its complex categorization system. 
        
        We pre-processed the German Credit data to clean it, resulting in a reduced version holding nine features (4 numerical and 5 categorical features, see Table <ref>). 
        As shown in Table <ref>, T-Explainer performed as the most stable explainer regarding RIS and maximum ROS perturbations, being the second best for the mean ROS. 
        
        
        
        
        
        
        
        
        
    
        Tables <ref> and <ref> indicate that gradient-based methods are more stable to input/output perturbations than SHAP and, in some cases, also than LIME. As one can notice, T-Explainer competes quite well with other gradient-based methods.
    
        HELOC and HIGGS are more robust datasets in terms of dimensionality and size. We selected the 3H-NN and the five-layer neural network models to compare T-Explainer with the other explainers on those datasets. Specifically, we trained the 3H-NN and 5H-128-NN classifiers on HELOC, achieving 71.34% and 73.27% accuracy, respectively. Despite the accuracy values being lower than the ones we achieved before, those performances are in line with the results reported in the literature <cit.>.
        
        Table <ref> shows that Integrated Gradients is the most stable explainer for almost all metrics (behind LIME only for mean RIS but with very close numbers). However, we highlight the performance of T-Explainer, especially regarding the metrics' means. Only Integrated Gradients, LIME, and T-Explainer kept the mean RIS under ten units, which can be taken as virtually the same mean stability to input perturbations. Similar results are observed in mean ROS, where Integrated Gradients, LIME, and T-Explainer achieved the smallest values, being T-Explainer the second best. 
        Table <ref> shows the explainers' stability when applied to the five-layer neural network. In such case, T-Explainer is the most stable method, with Integrated Gradients being the second best for mean RIS and LIME as the second best for mean ROS. Only T-Explainer and Integrated Gradients matched RES with the highest levels of stability. 
    
        
        
        
        
        
        
        
        
    
        We trained the 3H-NN and 5H-64-NN classifiers on the HIGGS data, which achieved 69.58% and 66.83% accuracy, respectively, close to the values reported in previous works <cit.>. We included a set of benchmarks using a five-layer neural network here to keep some similarity with the architectures proposed in <cit.>, which explored the use of deep networks on HIGGS. 
        Tables <ref> and <ref> show the good stability performances of gradient-based feature importance explainers, with T-Explainer outperforming them regarding RIS perturbations while being quite competitive regarding ROS and RES metrics. Those results demonstrate T-Explainer's ability to generate consistent explanations through different levels of model complexity and data dimensionality. 
        Note that SHAP is more unstable than LIME, with SHAP's claimed advantageous performance predominantly seen in low-dimensional datasets <cit.>.
    
        
        
        
        
        
        
        
        
        
        Finally, the experiments above show that T-Explainer generally performs well, clearly outperforming well-known model-agnostic methods such as SHAP (and LIME for most tests). 
        Our method presented competitive results in setups differing from Neural Networks, proving its agnostic capability.
        Moreover, T-Explainer also turned out to be quite competitive with model-specific techniques such as the gradient-based ones, thus being a new and valuable alternative method to explain black-box models' predictions.





§ COMPUTATIONAL PERFORMANCE



    Another challenge that XAI methods have to face is related to computational performance. Shapley-based approaches like SHAP apply sampling approximations because the exact version of the method is an NP-hard problem with exponential computing time regarding the number of features <cit.>. SHAP is a leading method in feature attribution tasks due to its axiomatic properties, with a range of explainers based on different algorithms, from the exact version to optimized approaches. However, according to its documentation, the most precise algorithm is only feasible for modelings that are nearly limited to 15 features[<https://shap.readthedocs.io/en/latest/generated/shap.ExactExplainer.html>].

    For a computational comparison of T-Explainer's performance, we generated a synthetic dataset with 16 features (16-FT) using OpenXAI, similar to the 20-FT dataset we used before (see the Synthetic Data Section). 
    The 3H-NN model was trained with the 16-FT dataset according to the experimental setup defined in Section <ref>. 
    We then defined ten explanation tasks, increasing the number of explanations by ten instances from the 16-FT data for each task, ranging from ten to one hundred explanations, to compare T-Explainer with three implementations of SHAP – the optimized explainer (the same method used in the stability experiments of Section <ref>), KernelSHAP <cit.>, the exact explainer based on standard Shapley values computation. 
    Figure <ref> presents the computational performance of T-Explainer and SHAP.
    
    

    SHAP explainer was the fastest. However, the method was the most unstable, as we demonstrated in the stability assessments. 
    The T-Explainer's performance is close to KernelSHAP, while the SHAP exact explainer running time has grown exponentially. In such a performance test, we used a reduced dataset instead of the 20-FT data because applying the SHAP exact explainer in tasks with more than 16 features is impossible. 
    Most of the Machine Learning problems consider high-dimensional data. For example, the HIGGS is a 28-dimensional dataset with over 98 thousand instances. With that dataset, it is impossible to apply the exact version of SHAP, and the optimized version of SHAP performs very poorly. 
    Something similar could be said about the HELOC data, which recently motivated a challenge by FICO <cit.>. 
    In this sense, T-Explainer is placed as a competitive XAI approach regarding computational resources.





§ DISCUSSION, LIMITATIONS, AND FUTURE WORK



    T-Explainer is backed by a clearly defined deterministic optimization process for calculating partial derivatives. 
    This new approach gives T-Explainer more robustness, as demonstrated in our results.

    Our experiments have focused on binary classification models, which are known to perform well in supervised learning <cit.>. 
    However, there is no constraint in applying T-Explainer to regression problems or more complex models, such as deep learning models.
    In particular, the T-Explainer naturally supports regression or multi-class classification with minor adaptations, which we are currently working on. 
    
    Although T-Explainer has demonstrated competitive results when applied to tree-based models on synthetic data, tree-based architectures impose extra challenges on XAI. 
    Tree classifiers have non-continuous architectures in which constant values are stored in leaf nodes, rendering gradient-based methods inappropriate. 
    T-Explainer's current version is not yet fully developed to support tree-based models. We are currently designing a mechanism that enables the computation of gradients in tree-based models, extending T-Explainer to operate in a more general context. 
    
    The present implementation of the T-Explainer can handle categorical attributes through an approach that discretizes categorical data into intervals, using continuous perturbations, enabling the computation of partial derivatives. 
    However, the approach requires a model retraining to fit the continuous intervals induced in the columns containing one-hot encoded categorical attributes. 
    Retraining introduces additional computational complexity. 
    Getting around the retraining issue is another improvement we are currently working on. 
    One alternative approach we are considering in this context is to apply the target encoding transformer <cit.>, which converts each nominal value of a categorical attribute into its corresponding expected value.

    We conducted experiments and comparisons using tabular data to create classification models for simplicity and because it is a typical setup for machine learning problems in academia and industry <cit.>. 
    We highlight that our experimental setup followed the assessment practices in recent literature <cit.>, focusing on Neural Networks as black boxes <cit.> and including datasets where leading XAI approaches have stability and applicability difficulties.
    However, we designed the T-Explainer considering more complex data representations, such as 2D images, videos, or semantic segmentation.
    We are extending our approach to encompass simplification masking approaches, a strategy widely used by many XAI methods <cit.>.
    
    Another aspect under improvement is the 𝐡 optimization module. As far as we know, there is no closed solution to determine an optimum value to 𝐡 in this context.
    During our investigations, we observed that the finite difference computation presents a certain instability for instances near the model's decision boundaries due to discontinuities imposed by the decision boundaries. 
    The literature on numerical methods brings a number of alternatives to deal with discontinuities when approximating derivatives through finite differences <cit.>. 
    As part of the T-Explainer's core, we are investigating alternatives to refine the 𝐡 optimization process while maintaining computational efficiency.
    
    A comprehensive assessment of a local explanation technique requires extensive quantitative <cit.> and qualitative <cit.> evaluations, including insights from human analysts <cit.>. 
    We prioritized quantitative metrics in this work, particularly those concerning stability, but we acknowledge the value of humans in the loop assessment.
    Thus, we are committed to comprehensively validating the T-Explainer using metrics beyond those discussed here.
    
    When carefully developed and applied, explainability contributes by adding new trustworthy perspectives to the broad horizon of Machine Learning, enriching the next generation of transparent  applications <cit.>.
    As an evolving project, T-Explainer will continue to be expanded and updated, incorporating additional functionalities and refinements. Our goal is to provide a complete XAI suite in Python based on implementations of T-Explainer and its functionalities in a well-documented and user-friendly package.





§ CONCLUSION



    In this paper, we presented the T-Explainer, a Taylor expansion-based XAI technique. 
    T-Explainer is a deterministic local feature attribution method built upon a solid mathematical foundation that grants it relevant properties such as local accuracy, missingness, and consistency. 
    Moreover, T-Explainer is designed to be a model-agnostic method able to generate explanations for a wide range of machine learning models, as it relies only on the models' outputs without accounting for their internal structure or partial results. 
    The provided experiments and comparisons demonstrate that T-Explainer is quite stable and comparable to model-specific techniques, thus being a valuable explanation alternative. 





    This study was financed in part by the Coordenação de Aperfeiçoamento de Pessoal de Nível Superior - Brasil (CAPES) - Finance Code 001, and in part by the São Paulo Research Foundation (FAPESP) – Finance Code #2022/09091-8.
    The views expressed are those of the authors and do not reflect the official policy or position of the sponsors.










§ APPENDIX



    Our 𝐡 optimizer was designed to find a reasonable estimate of the displacement parameter 𝐡 when running the centered finite difference method (FD) to compute the partial derivatives required by T-Explainer. 
    The optimizer is based on a binary search that minimizes a mean squared error (MSE) cost function.
    The optimum 𝐡 should be a small enough value but not too small to avoid round-off errors or singularity cases and should not be too large to avoid truncation errors.
    Algorithm <ref> provides high-level details about the optimization process to estimate the 𝐡 parameter.
    If 𝐡 leads to a singular or rank-deficient Jacobian matrix, the final ∇f_𝐱 will lead T-Explainer to attribute misleading null values to potentially important features. 
    Then, θ is a function that keeps the numerical stability by checking if the gradient of f comes from a non-singular (or full-rank) matrix.
    
    
    


