Table of Contents
Fetching ...

Counterfactual Maps: What They Are and How to Find Them

Awa Khouna, Julien Ferry, Thibaut Vidal

TL;DR

This work tackles the challenge of generating globally optimal counterfactual explanations for tree ensembles, whose predictions are piecewise constant over axis-aligned hyperrectangles. It introduces counterfactual maps, a global, preprocessable representation that reduces recourse to nearest-region search and yields optimal counterfactuals by projecting onto the nearest hyperrectangle with an alternative label, $y'$. The method has a one-time preprocessing stage that extracts a faithful hyperrectangle partition and builds per-target-class volumetric KD-trees, followed by a query-time certified nearest-region search with optimality guarantees. Experiments on real tabular datasets demonstrate millisecond-scale query latency and superior performance to both exact (OCEAN) and heuristic baselines, with scalable preprocessing. Overall, counterfactual maps enable scalable, trustworthy recourse in interactive deployments and point to extensions to other piecewise-constant models.

Abstract

Counterfactual explanations are a central tool in interpretable machine learning, yet computing them exactly for complex models remains challenging. For tree ensembles, predictions are piecewise constant over a large collection of axis-aligned hyperrectangles, implying that an optimal counterfactual for a point corresponds to its projection onto the nearest rectangle with an alternative label under a chosen metric. Existing methods largely overlook this geometric structure, relying either on heuristics with no optimality guarantees or on mixed-integer programming formulations that do not scale to interactive use. In this work, we revisit counterfactual generation through the lens of nearest-region search and introduce counterfactual maps, a global representation of recourse for tree ensembles. Leveraging the fact that any tree ensemble can be compressed into an equivalent partition of labeled hyperrectangles, we cast counterfactual search as the problem of identifying the generalized Voronoi cell associated with the nearest rectangle of an alternative label. This leads to an exact, amortized algorithm based on volumetric k-dimensional (KD) trees, which performs branch-and-bound nearest-region queries with explicit optimality certificates and sublinear average query time after a one-time preprocessing phase. Our experimental analyses on several real datasets drawn from high-stakes application domains show that this approach delivers globally optimal counterfactual explanations with millisecond-level latency, achieving query times that are orders of magnitude faster than existing exact, cold-start optimization methods.

Counterfactual Maps: What They Are and How to Find Them

TL;DR

This work tackles the challenge of generating globally optimal counterfactual explanations for tree ensembles, whose predictions are piecewise constant over axis-aligned hyperrectangles. It introduces counterfactual maps, a global, preprocessable representation that reduces recourse to nearest-region search and yields optimal counterfactuals by projecting onto the nearest hyperrectangle with an alternative label, . The method has a one-time preprocessing stage that extracts a faithful hyperrectangle partition and builds per-target-class volumetric KD-trees, followed by a query-time certified nearest-region search with optimality guarantees. Experiments on real tabular datasets demonstrate millisecond-scale query latency and superior performance to both exact (OCEAN) and heuristic baselines, with scalable preprocessing. Overall, counterfactual maps enable scalable, trustworthy recourse in interactive deployments and point to extensions to other piecewise-constant models.

Abstract

Counterfactual explanations are a central tool in interpretable machine learning, yet computing them exactly for complex models remains challenging. For tree ensembles, predictions are piecewise constant over a large collection of axis-aligned hyperrectangles, implying that an optimal counterfactual for a point corresponds to its projection onto the nearest rectangle with an alternative label under a chosen metric. Existing methods largely overlook this geometric structure, relying either on heuristics with no optimality guarantees or on mixed-integer programming formulations that do not scale to interactive use. In this work, we revisit counterfactual generation through the lens of nearest-region search and introduce counterfactual maps, a global representation of recourse for tree ensembles. Leveraging the fact that any tree ensemble can be compressed into an equivalent partition of labeled hyperrectangles, we cast counterfactual search as the problem of identifying the generalized Voronoi cell associated with the nearest rectangle of an alternative label. This leads to an exact, amortized algorithm based on volumetric k-dimensional (KD) trees, which performs branch-and-bound nearest-region queries with explicit optimality certificates and sublinear average query time after a one-time preprocessing phase. Our experimental analyses on several real datasets drawn from high-stakes application domains show that this approach delivers globally optimal counterfactual explanations with millisecond-level latency, achieving query times that are orders of magnitude faster than existing exact, cold-start optimization methods.
Paper Structure (22 sections, 7 theorems, 34 equations, 9 figures, 3 tables, 2 algorithms)

This paper contains 22 sections, 7 theorems, 34 equations, 9 figures, 3 tables, 2 algorithms.

Key Result

Proposition 2.2

For $p\in[1,\infty]$ and $\mathcal{H}_i\in \mathbb{H}_{y'}$, define the (closed) $p$-Voronoi region ${\mathcal{V}^{(p)}_i} \triangleq \{x\in\mathcal{X}:\ d_p(x,\mathcal{H}_i)\le d_p(x,\mathcal{H}_j)\ \forall\,\mathcal{H}_j\in\mathbb{H}_{y'}\},$ and for $\mathcal{H}_i,\mathcal{H}_j\in\mathbb{H}_{y'}$

Figures (9)

  • Figure 1: Counterfactual map for target class HTML]7F7F7F$y_2$. The map corresponds to the generalized Voronoi partition induced by the hyperrectangles of this class. For any input query, it identifies the closest hyperrectangle of this class; projecting the query onto that region yields a globally optimal counterfactual. This simple example uses a random forest with two depth-5 trees trained on the "blobs" dataset.
  • Figure 2: Two-stage workflow for counterfactual generation in tree-ensemble decision spaces. The Build pipeline (one-time) extracts the labeled rectangular partition $\mathbb{H}$ and constructs an exact counterfactual map using geometric search structures. The Query pipeline identifies the nearest opposing region and projects the query to produce a globally optimal counterfactual explanation.
  • Figure 3: Average query latency of CF-Maps after the one-time preprocessing step (i.e., time to generate a counterfactual explanation using Algorithm \ref{['alg:query']}), for three distance functions across all datasets, for random forests with 100 depth-5 trees.
  • Figure 4: Total runtime (including one-time preprocessing and counterfactual generation) as a function of the number of generated counterfactuals, for random forests with 100 depth-5 trees.
  • Figure 5: Total runtime (including one-time preprocessing and counterfactual generation) for generating 1000 counterfactuals, for random forests with varying numbers of depth-5 trees.
  • ...and 4 more figures

Theorems & Definitions (14)

  • Definition 2.1: Counterfactual map
  • Proposition 2.2
  • Theorem 3.1: Exact Nearest-Hyperrectangle Search
  • proof
  • Lemma 3.1: Distance monotonicity under inclusion
  • proof
  • Lemma 3.2: Bounding box as a lower bound
  • proof
  • Lemma 3.3: Best-so-far distance over visited rectangles
  • proof
  • ...and 4 more