Table of Contents
Fetching ...

GradCFA: A Hybrid Gradient-Based Counterfactual and Feature Attribution Explanation Algorithm for Local Interpretation of Neural Networks

Jacob Sanderson, Hua Mao, Wai Lok Woo

Abstract

Explainable Artificial Intelligence (XAI) is increasingly essential as AI systems are deployed in critical fields such as healthcare and finance, offering transparency into AI-driven decisions. Two major XAI paradigms, counterfactual explanations (CFX) and feature attribution (FA), serve distinct roles in model interpretability. This study introduces GradCFA, a hybrid framework combining CFX and FA to improve interpretability by explicitly optimizing feasibility, plausibility, and diversity - key qualities often unbalanced in existing methods. Unlike most CFX research focused on binary classification, GradCFA extends to multi-class scenarios, supporting a wider range of applications. We evaluate GradCFA's validity, proximity, sparsity, plausibility, and diversity against state-of-the-art methods, including Wachter, DiCE, CARE for CFX, and SHAP for FA. Results show GradCFA effectively generates feasible, plausible, and diverse counterfactuals while offering valuable FA insights. By identifying influential features and validating their impact, GradCFA advances AI interpretability. The code for implementation of this work can be found at: https://github.com/jacob-ws/GradCFs .

GradCFA: A Hybrid Gradient-Based Counterfactual and Feature Attribution Explanation Algorithm for Local Interpretation of Neural Networks

Abstract

Explainable Artificial Intelligence (XAI) is increasingly essential as AI systems are deployed in critical fields such as healthcare and finance, offering transparency into AI-driven decisions. Two major XAI paradigms, counterfactual explanations (CFX) and feature attribution (FA), serve distinct roles in model interpretability. This study introduces GradCFA, a hybrid framework combining CFX and FA to improve interpretability by explicitly optimizing feasibility, plausibility, and diversity - key qualities often unbalanced in existing methods. Unlike most CFX research focused on binary classification, GradCFA extends to multi-class scenarios, supporting a wider range of applications. We evaluate GradCFA's validity, proximity, sparsity, plausibility, and diversity against state-of-the-art methods, including Wachter, DiCE, CARE for CFX, and SHAP for FA. Results show GradCFA effectively generates feasible, plausible, and diverse counterfactuals while offering valuable FA insights. By identifying influential features and validating their impact, GradCFA advances AI interpretability. The code for implementation of this work can be found at: https://github.com/jacob-ws/GradCFs .
Paper Structure (30 sections, 15 equations, 5 figures, 8 tables, 1 algorithm)

This paper contains 30 sections, 15 equations, 5 figures, 8 tables, 1 algorithm.

Figures (5)

  • Figure 1: Overview of the GradCFA Pipeline: Beginning with a trained neural network, a query instance, and the observed dataset. The counterfactual set $X'$ is initialized with random values sampled from a normal distribution. Individual loss components are calculated and compared with user-defined thresholds $\tau_{char}$, where each loss component $L$ has its own threshold $\tau_{char}$. For proximity, sparsity, and plausibility $L$ within $\tau$ is true if $L \leq \tau_{char}$, and for diversity $L$ is considered within $\tau$ if $L \geq \tau_{char}$. If thresholds are not met, a penalty is applied. The total loss is computed based on user-defined weighting. User constraints are then applied, gradients are computed to attribute feature importance, and update $X'$. If the final loss after optimization does not meet the threshold, values are perturbed, and optimization is repeated until an acceptable loss is achieved or the maximum number of perturbation attempts is reached, after which the counterfactual set and FAs are returned.
  • Figure 2: Loss curves for (a) credit approval, (b) obesity levels, and (c) fetal health, with perturbation, where the grey dashed lines represent the points of perturbation. The curves demonstrate that after each perturbation the loss is driven further down, indicating the efficacy of the approach in improving the results.
  • Figure 3: Loss curves for (a) credit approval, (b) obesity levels, and (c) fetal health without perturbation.
  • Figure 4: FA computed with GradCFA for (a) credit approval, (b) obesity levels and (c) fetal health. The results highlight the critical role of prior default and income in credit approval, weight in obesity classification, and active vigilance and calm sleep in fetal health, while other features like age, years employed, dietary habits, and histogram statistics are less influential in generating plausible and feasible counterfactuals.
  • Figure 5: FA computed with SHAP for (a) credit approval, (b) obesity levels and (c) fetal health.