Skip to main content
Back

Northumbria's GradCFA Merges AI Explainability and Decision Flipping Into One

A new explainability framework unifies counterfactuals and feature attribution in one gradient-based loop, and finally handles multi-class problems.

Pro

  • GradCFA merges counterfactual explanations and feature attribution into one gradient-based optimization loop.
  • Optimizes validity, proximity, sparsity, plausibility, and diversity jointly with tunable weights and thresholds.
  • First CFX algorithm explicitly extended to multi-class problems via cross-entropy validity loss.
  • Beats Wachter, DiCE, and CARE on balanced average score across three UCI datasets.
  • Attribution scores come free from accumulated gradients during counterfactual search, no separate SHAP needed.
  • Code available at github.com/jacob-ws/GradCFs; published in IEEE TAI.

Explainable AI has long been split into two camps that rarely talk to each other. Counterfactual explanations (CFX) tell you what would need to change for a model to flip its decision, while feature attribution (FA) methods like SHAP tell you which inputs mattered most. A new algorithm called GradCFA, published in IEEE Transactions on Artificial Intelligence, tries to fuse both into a single gradient-based procedure, and along the way it becomes one of the first counterfactual methods designed to handle multi-class classifiers directly.

The work comes from Jacob Sanderson, Hua Mao, and Wai Lok Woo at Northumbria University, and the code is available on GitHub.

The mess with existing counterfactuals

A good counterfactual should tick five boxes at once: validity (the alternate input actually gets the desired class), proximity (small change), sparsity (few features changed), plausibility (looks like real data), and diversity (multiple distinct options). Most CFX methods optimize only a subset of these qualities, often relying on user constraints for feasibility and plausibility, and genetic algorithms for diversity. The result is that classic tools each excel at one thing and fail at others. Wachter chases proximity, DiCE balances proximity and diversity, and CARE relies on genetic search.

There is also a coverage gap. Existing CFX studies are restricted to binary classification, making multi-class CFX underexplored, though essential, as many real-world applications involve complex multi-class decision boundaries. Credit tiers, cancer stages, and obesity levels are all multi-class problems that binary-only tools cannot serve well.

One loss to rule them all

GradCFA rolls every desirable property into a single weighted loss function with six components: validity, proximity, sparsity, plausibility, diversity, and a categorical regularizer that keeps one-hot encodings consistent. The counterfactual set is initialized from random noise and then optimized with Adam.

GradCFA pipeline diagram showing loss computation, optimization loop, perturbation, and feature attribution output

Two mechanisms make the optimization behave. First, each loss term gets a user-defined threshold, and if a term is not within its acceptable range, an extra penalty scales it up so the optimizer pushes harder on the lagging metric. Second, and more interesting, once the optimizer converges the algorithm checks the total loss against a target. If the result is subpar, the counterfactual features are perturbed with Gaussian noise and optimization restarts. This helps escape local optima that gradient descent alone would get stuck in.

For multi-class problems, the validity term becomes standard cross-entropy loss over the target class, which is the main change needed to move beyond binary decisions.

Free feature attribution as a byproduct

The clever part is that GradCFA does not run SHAP as a separate step. During optimization the algorithm already computes gradients of the model output with respect to the input features. It accumulates these gradients across every iteration, averages them, and takes their norm as the attribution score for each feature. In other words, FA falls out of the counterfactual search itself, and the scores describe which features actually drove the flip.

The authors validate the attribution scores by fixing each feature in turn and re-running the search. Features with high attribution should be essential, and indeed they are: fixing prior default in the credit dataset, weight in the obesity dataset, or the top vigilance features in the fetal health dataset makes counterfactual generation fail entirely within the iteration budget.

How it stacks up on real datasets

Evaluation runs on three UCI datasets: credit approval (14 features, binary), obesity levels (16 features, 7 classes), and fetal health (32 features, 3 classes). A two-hidden-layer fully connected network (64 then 32 neurons) is trained first, then GradCFA is applied post-hoc.

On credit approval, GradCFA loses to Wachter on raw proximity, which is expected because Wachter is specifically designed around that single metric. But it takes the best plausibility (0.37 vs 0.51 for DiCE), the best diversity (0.96 vs 0.84 for DiCE), and the highest validity confidence (0.78). The overall balance score of 0.81 beats DiCE (0.71) and CARE (0.63).

MethodProx.Spars.Plaus.Div.Conf.
Wachter0.030.100.560.350.56
DiCE0.120.280.510.840.64
CARE0.180.560.470.680.66
GradCFA0.150.180.370.960.78

An ablation confirms that removing the perturbation-restart trick or the penalty terms consistently degrades all metrics, and SHAP agrees with GradCFA on which single feature matters most in every dataset.

Where it fits and where it hurts

The diversity loss requires a determinantal point process over a pairwise distance matrix, which is O(n3) in the number of counterfactuals returned. That is fine for the small counterfactual sets that are actually useful to humans, but scaling n up will bite quickly. The authors also flag that hyperparameter tuning (weights, thresholds, scale factors) is a burden for non-expert users and that the method does not yet model causal relationships between features, which shows up in the credit dataset where debt and prior defaults sometimes rise in counterfactuals that improve approval odds.

Still, if you are working on tabular models in regulated domains, healthcare, credit, actuarial and need both actionable recourse and honest feature attribution without stitching together two libraries, GradCFA is one of the first tools that treats those two problems as one problem. The multi-class extension is the piece that really opens up new territory.