# Generating Efficiently Realistic Counterfactual
Explanations

Victor Guyomard, Françoise Fessant, Tassadit Bouadi, Thomas Guyet

► To cite this version:

Victor Guyomard, Françoise Fessant, Tassadit Bouadi, Thomas Guyet. Generating Efficiently Realistic Counterfactual Explanations. Machine Learning, 2026, 115 (2), pp.27. 10.1007/s10994-025-06947-2. hal-05472901

HAL Id: hal-05472901

https://inria.hal.science/hal-05472901v1

Submitted on 23 Jan 2026

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons CC BY 4.0 - Attribution - International License
# Generating efficiently realistic counterfactual
explanations*

Victor Guyomard<fnref n="1" />,<fnref n="2" />, Françoise Fessant<fnref n="2" />*, Tassadit Bouadi<fnref n="1" />*,
Thomas Guyet<fnref n="3" />*

*Corresponding author(s). E-mail(s): francoise.fessant@orange.com; tassadit.bouadi@irisa.fr; thomas.guyet@inria.fr;

## Abstract

This article introduces **VCNet** – Variational CounterNet – a method for generating realistic counterfactuals, and its extension **ImmutableVCNet**. VCNet aims to generate counterfactuals that are representative of their predicted classes in the context of tabular data. Moreover, it aims to overcome the limitations related to the post-hoc character and optimization procedure of the state-of-the-art approaches, by reducing the computing time of the counterfactual generation and reaching high levels of validity. However, state-of-the-art methods that succeed in overcoming the aforementioned limitations suffer from a lack of realism with regard to the counterfactuals generated. VCNet addresses this concern by adding realism constraints to the counterfactual generation process. Our approach is based on a conditional variational autoencoder (cVAE) to model the distributions for every class at once. Thus, generated counterfactuals not only belong to the data distribution but belong to the data distribution of a given class. The **ImmutableVCNet** extends VCNet to overcome the limitation of handling immutable features.

We conducted several ablation studies to investigate the impact of the different choices within the VCNet architecture. Furthermore, we conducted empirical studies that demonstrate the significant benefits of our approach in generating realistic counterfactuals. We evaluate VCNet against ImmutableVCNet and also ImmutableVCNet against a variety of state-of-the-art counterfactual methods.

**Keywords:** explainability, conditional generative model, tabular data

<footnote n="1">¹Orange-Research, Orange, Lannion, France.</footnote>

<footnote n="2">²IRISA, Rennes University, Rennes, France.</footnote>

<footnote n="3">³AIstroSight, Inria, Hospices Civils de Lyon, Université Claude Bernard Lyon 1, 56 Bld Niels Bohr, Villeurbanne, 69003, France.</footnote>

<footnote>*Citation: Guyomard, V., Fessant, F., Bouadi, T. et al. Generating Efficiently Realistic Counterfactual Explanations. Mach Learn 115, 27 (2026) https://doi.org/10.1007/s10994-025-06947-2</footnote>
# 1 Introduction

Recent advances in machine learning for decision systems have driven the adoption of predictive models in sensitive domains such as healthcare, credit scoring, and criminal justice. The high-stakes nature of these applications, combined with the black-box behavior of many algorithms, has motivated the development of approaches that can explain why a particular decision was made. For instance, when a loan application is denied by an automated model, both the applicant and the institution must understand the underlying reasons and, ideally, what changes could lead to a different outcome (Lipton, 2017; Wachter, Mittelstadt, & Russell, 2018).

Counterfactual explanations address this need by identifying minimal and plausible changes to an input instance that would alter the model's decision. In the credit example, a counterfactual explanation might suggest that increasing income or reducing existing debt would lead to loan approval. Rooted in psychology and philosophy (Byrne, 2016; Lewis, 1973), counterfactual reasoning has become a key paradigm in Explainable Artificial Intelligence (XAI), providing both interpretability and actionable recourse. A meaningful counterfactual must therefore be both *valid*, as it changes the prediction, and *realistic*, as it remains plausible and feasible with respect to the data distribution.

However, existing counterfactual generation techniques often rely on post-hoc optimization over fixed, pre-trained models (Molnar, 2022). These methods can be computationally expensive, unstable, and prone to generating unrealistic counterfactuals (Molnar, 2022; Mothilal, Sharma, & Tan, 2020; Poyiadzi, Sokol, Santos-Rodriguez, De Bie, & Flach, 2020). Moreover, separating the predictor from the explanation mechanism may result in incoherent or unfaithful explanations (Guo, Nguyen, & Yadav, 2021; Rudin, 2019). To overcome these limitations, VCNet was introduced as a *self-explaining architecture* that unifies prediction and counterfactual generation in a single model. VCNet couples a classifier with a counterfactual generator based on a *conditional variational autoencoder* (cVAE), jointly trained through a single, efficient back-propagation procedure.

The conceptual novelty of VCNet lies in the introduction of a *conditioning and disentanglement trick* within the cVAE to generate realistic counterfactuals efficiently. Our approach, based on the control and tricking of the generative model's latent space, is inspired from John et al. work about learning disentangled latent spaces in the context of text style transfer (John, Mou, Bahuleyan, & Vechtomova, 2019). Although architecturally simple, this design offers an original and powerful use of conditional generative modeling. It enables counterfactuals to be generated in constant time once the model is trained, ensuring computational scalability. By construction, the cVAE enforces plausibility, as generated counterfactuals lie within the learned class-conditioned data distribution (Pawelczyk, Broelemann, & Kasneci, 2020). At the same time, the model naturally encourages sparse and feasible changes, which enhances the actionability of counterfactual recourses. Finally, the disentanglement principle simplifies training into a single gradient descent process, avoiding the complex and unstable bi-level optimization procedures that characterize models such as CounterNet (Guo et al., 2021). Altogether, these properties make VCNet a wholesome
and efficient framework for counterfactual reasoning, combining realism, feasibility, and practicality within a unified generative approach.

Building on this conceptual foundation, the present work proposes a generalized formulation of the VCNet framework, further demonstrating its flexibility and expressive power. The proposed model pushes the realism and applicability of counterfactual reasoning by integrating additional functionalities: it handles mixed-type data, seamlessly combining numerical and categorical variables within a single generative process, and it incorporates actionability constraints, distinguishing between mutable and immutable variables to ensure that generated counterfactuals remain feasible and domain-compliant. These capabilities are natural consequences of the VCNet conditioning principle, which provides a unified probabilistic mechanism for generating realistic and constrained counterfactuals across diverse application contexts.

VCNet emerges as a flexible and general framework for realistic counterfactual reasoning. It unifies prediction, generation, and constraint handling within a single trainable and interpretable architecture. Extensive experiments on synthetic and real-world datasets confirm that this generalized VCNet achieves state-of-the-art performance in validity, plausibility, and computational efficiency, demonstrating its potential as a robust and adaptable model for interpretable decision systems.

## 2 Counterfactual Explanations

Let $\mathcal{Y}$ be a finite set of $m$ classes and $f: \mathbb{R}^p \to \mathcal{Y}$ be a classification model which assign a class $c \in \mathcal{Y}$ to a vectorial example $x$.

A counterfactual explanation is seen as a minimal modification of the input that leads to a different prediction with respect to the machine learning model $f$ (Wachter et al., 2018). An example of such a counterfactual explanation is “if your monthly income had been 500€ higher, then your credit would have been accepted”. In this scenario, the classification model accepts or denies a credit to a client based on some features, including his salary. For an individual $x \in \mathbb{R}^p$, the explanation produces a new virtual individual $x_{cf} \in \mathbb{R}^p$ who has the original individual features but with an increase of 500€ income salary. This new example is called a counterfactual example or more succinctly a counterfactual.

A counterfactual is expected to hold at least the two following properties:

* proximity property: the counterfactual has to be similar to the example to explain.

* validity property: the counterfactual has a different prediction from the one of the example to explain.

In practice, the generation of counterfactuals is an optimization problem (see eq. 1). It is formulated as the minimization of a proximity function, $d(\cdot, \cdot)$, which encodes the desirable proximity property of the counterfactual instance under the constraint that the counterfactual is predicted with a different class. For a proximity property, the function to optimize is, for instance, the squared error.

$$x_{cf} = \underset{x' \in \mathbb{R}^p}{\operatorname{argmin}} \quad \begin{array}{l} d(x, x') \\ \text{s.t.} \quad f(x') \neq f(x) \end{array} \qquad (1)$$
Wachter et al. (2018) proposed a relaxed form of this problem: $x_{cf}$ is generated by minimizing the distance between the instance to be explained and the counterfactual while pushing the new prediction toward an alternative class, $y_{cf} \in \mathcal{Y}$.

$$x_{cf} = \underset{x' \in \mathbb{R}^p}{\operatorname{argmin}} \max_{\lambda \in \mathbb{R}_+} \lambda \cdot \underbrace{d_{\mathcal{Y}}(f(x'), y_{cf})}_{\text{validity}} + \underbrace{d(x, x')}_{\text{proximity}} \quad (2)$$

In this setting, the alternative class, $y_{cf} \in \mathcal{Y}$, is provided by the analyst and must be different from the originally predicted class $f(x)$. $d_{\mathcal{Y}}(\cdot, \cdot)$ is a metric in the domain of $f$. In practice, $f$ is usually a probabilistic classifier that outputs a probability vector of dimension $m$. Then, a $L_1$ or $L_2$ metric is used to encourage the validity of a counterfactual. Finally, as this optimization problem is difficult, the $\lambda$ value is fixed and becomes an hyperparameter of the counterfactual generation.

## 2.1 Expected Properties of Counterfactuals

The two properties, mentioned above, are fundamental to the definition of a counterfactual example. However, there is no consensus on what constitutes a good counterfactual. The concept of proximity is subject to debate, largely due to the absence of a universal method for defining distance. This lack of standardization makes selecting an appropriate distance both complex and challenging, especially when the goal is to produce meaningful and plausible counterfactuals. According to Wachter et al. (2018), the proximity is evaluated by a $L_1$ distance. Poyiadzi et al. (2020) consider a path between the example to explain and the counterfactual. On the other hand, other properties are considered of importance to improve the quality of generated counterfactuals. More specifically:

* actionability (Ustun, Spangher, & Liu, 2019): a counterfactual must differ from the example only on actionable features;

* diversity (Mothilal et al., 2020; Russell, 2019): a generation method must be able to generate a set of diverse counterfactuals to let the user select the best one;

* realism (Van Looveren & Klaise, 2021): A counterfactual has to be both achievable and likely to occur in real-world contexts.

To improve these aspects, different approaches have been proposed to find a counterfactual that optimizes a tradeoff between them. These approaches consist in adding terms in the objective function to constraint the generation of counterfactuals.

In this work, we consider that realism is a primary property for a trustworthy generation of counterfactuals. Recent advances combine generative models and classifiers to generate CF explanations, with enhanced techniques focusing on realism and validity (Ghandeharioun et al., 2021; Haselhoff, Trelenberg, Küppers, & Schneider, 2024; Hvilshøj, Iosifidis, & Assent, 2021; Lang et al., 2021), especially for visual counterfactuals. Realism of tabular counterfactuals is also desirable. For instance, generating counterfactual of clients with negative income salary or having a PhD degree at age 18 would confuse an analyst. Nonetheless, realism is more than preventing to generate spurious examples. A broader view of realism is the plausibility of counterfactuals,
meaning that a generated counterfactual has to be plausible regarding the known dis-
tribution of examples. We expect generating counterfactuals in dense region of the
example space. Recently, Dandl et al. (2024) leverage a generative modeling technique
named adversarial random forests to efficiently generate plausible counterfactuals. An
alternative view for realism lies in the explicit modeling of causality between features
of the dataset with the similar objective to prevent counterfactuals that would be obvi-
ously unrealistic due to inconsistent feature values. For instance, Mahajan, Tan, and
Sharma (2019) proposed to integrate causality constraints in counterfactuals through
a causal proximity regularizer. The main limitation with such approach is the need
for a structural causal model, that does not necessarily exist in a practical case.

In addition, Stevens, Ouyang, De Smedt, and Moreira (2024) clarify this notion of
realism by distinguishing between plausibility and feasibility. According to Bhan, Vit-
taut, Chesneau, and Lesot (2023) the plausibility encompasses a set of characteristics
to ensure that the counterfactual explanation is not out-of-distribution, while feasibil-
ity (Poyiadzi et al., 2020) is a harder constraint that ensures the possibility to make
the change from the example to the counterfactual. An immutable variable is a prac-
tical constraint example that defines *infeasible* counterfactuals. In a tabular dataset,
the values of some features (such as a birthdate) can not change. Then, the variable
is said to be immutable and a counterfactual that would suggest changing a birthdate
would be *infeasible*. This later case should be avoided.

## 2.2 Learning Generators of Counterfactuals

All aforementioned techniques search for counterfactual examples by solving a separate
optimization problem for each instance to be explained. This optimization problem
is computationally intensive, making it impractical for large amounts of instances.
In addition, generating multiple counterfactuals for the same example can result in
different outcomes, which may undermine the user's trust.

To address this issue, the general idea is to see the generation of a counterfactual as
a deterministic generative model. A generative counterfactual model is a function that
yields a counterfactual from its example (or perturbations of an example that indirectly
define a counterfactual). More formally, it is a function $g_f : \mathbb{R}^p \to \mathbb{R}^p$ that generates
counterfactuals, i.e. $f_{pred}(g_f(x)) \neq f_{pred}(x)$ and $\|g_f(x) - x\|^2$ is small for all $x \in \mathbb{R}^p$.
For the sake of simplicity, we simply note $g$, the counterfactual generator assuming
that there is no ambiguity on the fact that it depends on the decision function.

The problem of defining such a function can be seen as a machine learning prob-
lem. Knowing some examples, the learning problem consists in finding a parameterized
function $g_\theta$ that yields valid counterfactuals for these examples. With a suitable
set of examples and a generalizing class of functions, $g_\theta$ is assumed to yield valid
counterfactuals for new examples.

Several approaches have been proposed to learn a counterfactual generator. While
some methods use Generative Adversarial Networks (GANs) (Nemirovsky, Thiebaut,
Xu, & Gupta, 2020), the majority prefer to use the latent space of variational autoen-
coder models which capture the underlying structure of data by learning a smooth,
regularized, and semantically meaningful latent space. This allows for controlled, plau-
sible generation of counterfactuals that vary along interpretable dimensions, stay close
to the data manifold, and retain realism. This can be done with linear interpolation (Barr, Harrington, Sharpe, & Bruss, 2021), latent feature selection (Downs, Chu, Yacoby, Doshi-Velez, & Pan, 2020), perturbation (Panagiotou, Heurich, Landgraf, & Ntoutsi, 2024; Pawelczyk et al., 2020) or incorporation of the target class in the latent space (Nangi, Chhaya, Khosla, Kaushik, & Nyati, 2021)).

All the counterfactual generation techniques enumerated in the previous paragraph are *post-hoc*. They assume that the explaining task is addressed after the decision model has been trained. In such case, the decision model (and its decision boundary) can not be adapted anymore. Some of these generation methods does not need access to the internal decision mechanisms, and some require access to the gradients of the model to train a counterfactual generator (Nemirovsky et al., 2020; Panagiotou et al., 2024). In any case, post-hoc counterfactual generation is poorly informed about the decision process. This is indeed the only option for already-trained models, but it is a strong constraint on the counterfactual generation problem.

An alternative to post-hoc are joint learning models. In such models, the generation of both the decision and its explanation are trained during a unique learning process (Alvarez Melis & Jaakkola, 2018). In the context of counterfactual explanations, such a strategy has been proposed by Guo et al. (2021) with CounterNet, a framework in which prediction and explanation are jointly learned. Optimizing counterfactual example generation alongside the predictive model in a single step enables better alignment between predictions and counterfactual explanations. This leads to explanations of better quality and significantly reduces the generation process time.

Our architecture is inspired by theirs but we have chosen to use a conditional variational autoencoder as a generative model of counterfactuals. Unlike variational autoencoders, conditional variational autoencoders make it possible to condition the generation of counterfactual explanations on a target class which makes the search for counterfactuals more controllable allowing us to exploit text style-transfer techniques (John et al., 2019; Nangi et al., 2021).

For an extended state-of-the-art of counterfactual generation, we suggest reading the survey of Guidotti (2024).

# 3 VCNet: a Joint-Training Model

VCNet is a self-explainable model through counterfactual generation. Inspired by CounterNet (Guo et al., 2021), the VCNet model is made of a predictor, $f_{pred}: \mathbb{R}^p \to \mathcal{Y}$, and a counterfactual generator, $g: \mathbb{R}^p \to \mathbb{R}^p$, that are jointly trained. In inference phase, each part can be used on demand: on the one side, to get the prediction $f_{pred}(x)$ for some new example $x$ and, on the other side, to generate its counterfactual $g(x)$. VCNet can be used as a self-explainable model and generates ($f_{pred}(x), g(x)$), i.e., the couple of the prediction and its counterfactual.

The trick of VCNet is to not train directly a counterfactual generator, but a conditional autoencoder, i.e., a cVAE that aims to model the conditional distribution of examples. And we use the disentanglement capability of a trained cVAE to yield counterfactuals. The cVAE is trained as an autoencoder and it is used as a counterfactual generator at inference. This trick enables to have a learning problem that is stable
<figure><img src="image_2.png" /><figcaption>**Fig. 1** VCNet architecture is composed of three blocks: shared layers that transform the input into a latent representation (blue dotted square), a predictor that outputs the prediction (orange dotted square), and a conditional variational autoencoder that acts as a counterfactual generator during testing (red dotted square).</figcaption></figure>

and easy to set up, compare to most of the approaches of the literature that are facing
hard and instable optimization problems with saddle point.

In the remainder of this section, we start by presenting the architecture of our
network, then we detail the training problem by defining the loss which is optimized
and finally, we detail how VCNet is used to generate counterfactuals at inference.

**3.1 Core Architecture of VCNet**

VCNet is a neural network architecture. Figure 1 illustrates the core architecture of
the model made of three main blocks:

1. Shared layers, $s_\beta$, that transform the input into a dense latent representation. We use fully connected layers with ELU activation functions. These layers generate a latent representation of an example that is shared between the predictors and the cVAE.

2. A predictor network, $f_\alpha$, that takes the shared latent representation and returns a probability vector corresponding to the probabilistic prediction. We use fully connected layers with ELU activation functions.

3. A conditional variational autoencoder that takes as input the shared latent representation and also the probability vector given by the predictor. The cVAE reconstructs examples and integrates additional layers to handle categorical features (see details below).

An example $x_i \in \mathbb{R}^p$ is passed through the shared layers to generate a dense latent representation $h_i = s_\beta(x_i)$. This representation is then shared with both the predictor network and the autoencoder. On the one hand, $h_i$ is passed through the predictor
$f_\alpha$ in order to obtain the probability vector $\hat{p}_i$. Then, the prediction of an example $x_i$ is obtained by the function $f_{pred}(x_i) = f_\alpha \circ s_\beta(x_i)$. On the other hand, $h_i$ is passed through the cVAE. It is first concatenated with $\hat{p}_i$ and then is passed through the encoder of the cVAE and samples a latent vector $z_i$. This latent vector concatenated with $\hat{p}_i$ is passed through the decoder, so as to obtain a reconstructed example $\hat{x}_i$.

It can be noticed that the cVAE used here slightly differs from the original cVAE (Sohn, Lee, & Yan, 2015). Indeed, formally, the encoder of an end-to-end cVAE includes the shared layer, $s_\beta$. In our architecture, the condition is introduced at an intermediary latent representation of the examples. The idea behind this architecture is to enforce the dense latent representation to be as independent of the class as possible, i.e. to have a disentanglement between the notion of class and the notion of characteristics of an example.

## 3.2 Training Procedure and Loss Function

In the given context, the objective of the training procedure is to jointly fit the predictor and the cVAE, ensuring that both components work together to model the data effectively. The loss function consists of two main terms: a reconstruction term that encourages accurate data generation and a KL divergence term that regularizes the latent space. It is worth noting that the architecture will not be trained to generate counterfactuals but to accurately model the data, conditionally to their class. The generation of counterfactual will be explained in next section. The predictor provides additional information that conditions both the encoder and decoder, influencing the learned representations. This conditioning helps the model better capture the underlying structure of the data, improving both reconstruction quality and latent space organization. Through this joint training process, the model learns to balance data fidelity and latent space regularization, leading to more meaningful and structured representations.

Then, the loss function to minimize on the training set ($D_{train}$) is defined as follows:

$$ \mathcal{L}(\theta, \alpha, \beta, \phi; D_{train}) = \sum_{i=1}^{n} \mathcal{L}_{cVAE}(\theta, \phi, \beta; x_i) + \lambda \sum_{i=1}^{n} \mathcal{L}_{pred}(\alpha, \beta; x_i, y_i) \quad (3) $$

This loss function consists of two terms, expressed as a weighted sum of the losses from Eq. 5 and Eq. 4.

The first term is derived from the loss of a cVAE (see Appendix 7.2 for details about the cVAE model). In our case, the cVAE is conditioned by the probability vector obtained at the output of the predictor. Then we can re-write the objective function as:

$$ \mathcal{L}_{cVAE}(\theta, \phi, \beta; x_i) = -\lambda_{Rec} \mathbb{E}_{q_{\phi}(z_i|s_{\beta}(x_i), \hat{p}_i)}[\log(p_{\theta}(x_i | z_i, \hat{p}_i))] \\ + \lambda_{kl} D_{KL} [q_{\phi}(z_i | s_{\beta}(x_i), \hat{p}_i) \| p(z_i)] \quad (4) $$

$\lambda_1$ and $\lambda_{KL}$ are weights to control the impact of each term during the training phase, and $D_{KL}$ is the *Kullback-Leibler* divergence.
The second term enables to learn the predictor. We use cross-entropy as classification loss between the output of the predictor $f_{pred}(x_i) = f_\alpha \circ s_\beta(x_i)$ and the true label $y_i$:

$$ \mathcal{L}_{pred}(\alpha, \beta; x_i, y_i) = \sum_{k=1}^{l} -\mathbb{1}_{[y_i=k]} \log (|f_{pred}(x_i)|_k) \quad (5) $$

where $[f_{pred}(x_i)]_k$ denotes the predicted probability that $x_i$ belongs to the k-th class.

As mentioned at the beginning of this section, it is worth noting that our problem is not to learn to generate counterfactuals. During the training phase, we expect from a cVAE to learn a latent space that models accurately the data distribution conditionally to the classes' information. Then, contrary to CounterNet, which employs a double-backpropagation procedure due to divergent objectives, we employ a single backpropagation procedure for minimizing the loss function $\mathcal{L}$.

However, in practice, the training of a conditional Variational Autoencoder (cVAE) can be challenging due to the balance required between the reconstruction and regularization terms in the loss function. To address this issue, we employ a monotonic annealing strategy (Bowman et al., 2016). The idea is to start with $\lambda_{kl} = 0$ and gradually increase its value over each epoch during training. More specifically, $\lambda_{kl}$ is increased by a step named $K_{step}$ for each epoch until it reaches a maximum value named $K_{max}$. Note that $\lambda$, $\lambda_{Rec}$, $\lambda_{kl}$ as well as $K_{step}$ and $K_{max}$ are hyperparameters.

## 3.3 Counterfactual Generation at Inference

The fitted model can not be used directly to generate counterfactuals. The principle of VCNet is to tweak it at inference for deriving this capability from its fitted blocks, more specifically from the cVAE.

The overall idea is to modify the conditioning of the cVAE to change its class, keeping the same shape of examples. At inference, an example $x_i$ is passed through the prediction network to obtain both its predicted probability vector ($\hat{p}_i$) and its dense vector representation ($h_i$). This dense vector representation ($h_i$) and the predicted probability vector ($\hat{p}_i$) are given to the encoder of the cVAE to produce a latent vector $z_i$. Then, the decoder of the cVAE plays the role of a counterfactual generator. Since we want to generate an example with a different predicted class we need a probability vector $p_{cf}$ such that the class with maximum probability is different from the one of the prediction, i.e., $\argmax(\hat{p}_i) \neq \argmax(p_{cf})$. Finally, the vector $p_{cf}$ and the latent vector $z_i$ are passed through the cVAE decoder in order to infer a new predicted class to obtain a counterfactual $x_{cf}$. The intuition is to benefit from the disentanglement of the latent space of a cVAE: $z_i$ contains non-class-specific information about $x_i$, and $p_{cf}$ encodes information for the desired class. As such, the decoder generates a new example $x_{cf}$ that is similar to $x_i$ and that belongs to a different class. Appendix 7.2 provides more details to support this intuition. Section 5.1.1 provides an experiment to illustrate the notion of disentanglement.

There are several ways to define the probability vector, $p_{cf} \in [0, 1]^m$, representing a class that differs from the predicted one. In a binary-classification problem, we decided to define $p_{cf}$ as a one-hot vector where the probability is 0 for the predicted class of $x_i$ and 1 for the opposite class. The reason for this choice is that we want to
generate counterfactuals where the confidence in the predicted class is the highest for the predictor. In the case of a multi-class classification problem, we propose to select the class with the second-highest probability in $\hat{p}_i$ and to switch the values with the predicted class. For example, if we obtain a probability vector $\hat{p}_i = [0.6, 0.3, 0.1]$ then $p_{cf} = [0.3, 0.6, 0.1]$. These alternative are not investigated in this article. There are alternative solutions that could be used in practice, for instance, to let the user select the class for which he/she is interested in having a counterfactual.

# 4 Extensions of VCNet

In this section, we introduce three extensions of the core architectures of VCNet.

The first extension consists in enhancing the core architecture with categorical features and taking into account the precision of the numerical attributes to generate more realistic values.

The second extension addresses the problem of immutable variables, i.e. variables that can not be modified in a recourse (e.g., changing an age is not actionable easily and if the counterfactual may suggest another change, it would be better). While the use of a cVAE enables to generate plausible counterfactuals, the capability of handling immutable features improves their feasibility.

The third one proposes a post-hoc version of VCNet, which can be used on any kind of trained classifier. Indeed, Borisov et al. (2022) shown that basic classification deep learning architectures do not always perform well on tabular datasets. A post-hoc version of VCNet may offer a practical solution when real-world datasets require more complex architectures to provide accurate predictions. Then, our post-hoc version of VCNet can be plugged on it, whatever the prediction model (including non-differentiable ones).

## 4.1 Improving Realism for Tabular Data

For practical use on tabular dataset, it is necessary to handle categorical features. We adopt the same preprocessing as Guo et al. (2021): At the input of the network, each categorical feature is encoded with a one-hot encoding. At the output of the cVAE, we add a softmax activation function for each one-hot categorical feature in order to obtain a one-hot encoding format by taking the argmax. Thus, the generated counterfactuals looks similar to a true example.

We also propose two pre-/post-processings to enhance the realism of numerical features by making changes more sparse.

In fact, counterfactuals generated by VCNet may introduce small changes to numerical features. Small changes may confuse users when it appears to be meaningless (Besnard, Guyet, & Masson, 2019). For instance, consider the scenario where a counterfactual suggests changing the value of a feature “Salary” from 2,300€ to 2,300.02€. This change may first appear unnecessary as the change seems meaningless. In this case, canceling the change of the feature Amount would yield a sparser counterfactual that would be likely valid.
The first post-processing enforces sparsity by ignoring two small changes. Let $x_0$ be an example to explain, and $x_{cf}$ a counterfactual, then for each numerical feature $j \in \{1, \dots, p\}$, $T$ is defined such as :

$$|x_{0j} - x_{cfj}| < \varepsilon_j \Rightarrow T(x_{cfj}) = x_{0j} \qquad (6)$$

The intuition behind this transformation, is that for a given numerical feature, a change lower than a certain threshold ($\varepsilon_j$) is equivalent to no change. It increases the sparsity of the solution, meaning that fewer features are changed with respect to the original example. The choice of the threshold can be related to the Sorite Paradox (Hyde, 2011) as it is not easy to decide when a difference is really meaningful for the user.

The second transformation consists in rounding the numerical features based on their initial precision in each dataset. This rounding process ensures consistency with the original dataset for the user. It prevents from generating examples that are obviously synthetics for the users because of an unusual figure precision. For instance, for age features, a value of 23.12 would be doubtful for the user. In practice, the rounding precision can automatically set to the maximum precision of the figure in the train set.

However, these transformations have to be used carefully as they may impact the validity of the counterfactuals, i.e., the counterfactual belongs to the same class as the original example. Continuing the example above, we can imagine that there is an implicit administrative rule on the salary feature that changes the class of an individual if the salary value goes strictly above 2,300€. The generation of counterfactual may recourse to a small change of the salary (from 2,300€ to 2,300.02€) to change the class with a small change. Unfortunately, the first transformation would cancel this change and would make the transformed counterfactual invalid (it is now in the same class as the example). Then, it is crucial to choose an appropriate value for $\varepsilon_i$ that does not compromise the validity of the counterfactuals. At least, some experiments are required on practical cases (see Section 5.1.3). Nonetheless, it is worth noting that these extensions of VCNet are post-processing that have no impact on the optimization process. More specifically, they can be deactivated or adjusted after the training of the core model and, in practice, the user of a VCNet model can change the $\varepsilon_j$ values at any moment (and make several attempts if necessary). By default, $\varepsilon_j$ and the rounding precision are not activated. A user who wants to enhance the realism of generated counterfactuals will have to manually set $\varepsilon_j$. The rounding precision can be defined manually or induced from the data by detecting the greatest number precision.

## 4.2 Handling Immutable Variables

As seen in Section 2, some features should remain unchanged by the counterfactual in order to be actionable. These features are called “immutable features”, in contrast to “mutable features” that can be altered by the counterfactual. For example, in a credit attribution problem, it is inappropriate to suggest modifying features such as “gender” or “race” to obtain a credit. Note that the identification of immutable features is context-specific and should be established a priori. It is worth noting that
this question is specific to tabular datasets, in contrast to image datasets.<fnref n="1" /> For tabular datasets, it is a practical constraint that must be handled for real-world usage.

Dealing with immutable features is challenging for realistic counterfactual generation. As seen above, the realism is based on a capability of modeling the distribution of examples. Correlations between mutable and immutable features make it challenging to generate realistic examples without modifying the immutable features

## Notations

Let $x_i \in \mathcal{X}$ be an example to explain, then $x_i^m$ and $x_i^{im}$ denote vectors that respectively contain mutable and immutable features values of $x_i$. Note that by concatenating $x_i^m$ and $x_i^{im}$ we obtained $x_i$, i.e. $x_i = [x_i^m, x_i^{im}]$.

ImmutableVCNet is a modification of the VCNet architecture to handle immutable features. This architecture, illustrated in Figure 2, is made of two main blocks:

1. A predictor that takes as input an example $x_i$ and returns a probability vector $\hat{p}_i$.

2. A cVAE that takes as input a mutable features vector $x_i^m$ and returns the reconstructed mutable features vector $\hat{x}_i^m$. Note that the same process used with VCNet is also applied to categorical features (see Section 3.1), however it is not indicated in Figure 2 for clarity reasons.

By comparison with VCNet, we firstly removed the shared layer block, allowing each block to have its own distinct latent representation. Specifically, the predictor now has a latent representation of the input vector $x$, while the cVAE block has a latent representation of the mutable feature vector, $x^m$. Intuitively, the idea is that the generation process should only impact the mutable features, since immutable features are fixed. On the other hand, the predictor should use all features to provide the most accurate prediction.

In our architecture, we adopt the approach of conditioning the decoder of the cVAE on immutable features, as inspired by Pawelczyk et al. (2020). The vector of immutable features, denoted as $x_i^{im}$, is concatenated with the probability vector and provided to the decoder. This architectural choice is beneficial because it allows the immutable features to influence the generation process. Intuitively, this can be particularly interesting when there is a correlation between an immutable and a mutable feature. For instance, consider the scenario where an immutable feature “age” is correlated with a mutable feature “education”. If the generation process is independent of the immutable features, it may be possible to generate an individual with a PhD who is only 14 years old, which would be critical regarding plausibility.

In this context, the predictor and the cVAE are still jointly learned. We use a single optimization procedure to train the two blocks and the loss function remains the same as the one used in the previous joint-training procedure.

The counterfactual generation process is basically similar to the ones of VCNet considering that it benefits from the disentanglement property of the cVAE. In practice,

<footnote n="1">¹One could also imagine that, for certain images, some predefined parts might be unchangeable. For instance, for medical images such as brain MRI, generating changes out of the brain region may be practically useless. Nevertheless, this seems to be a marginal application compared to the wide range of situations with tabular data with features that can not be changed.</footnote>
<figure><img src="image_3.png" /><figcaption>**Fig. 2** ImmutableVCNet architecture is composed of two blocks: a predictor block, that outputs the prediction (orange square) and a conditional variational autoencoder, where a mutable features vector is learned to be reconstructed conditionally to both predictions outputted by the predictor, and the immutable features. $x_i$ is the features vector obtained by concatenation of the mutable features vector and the immutable features vector, i.e. $x_i = [x_i^m, x_i^{im}]$</figcaption></figure>

an example $x_i$ is passed to the prediction network to obtain the predicted probability vector $\hat{p}_i$. A vector $p_c$ that maximizes the predicted probability for a different class, is passed to the decoder with the immutable feature vector $x_i^{im}$ to generate a counterfactual $x_{cf}^m$, with respect to the mutable feature values. Finally, the immutable and mutable feature values are concatenated to produce the final counterfactual: $x_{cf} = [x_{cf}^m, x_i^{im}]$.

## 4.3 Post-hoc Version of VCNet

We also adapted our architectures (VCNet or ImmutableVCNet) to a post-hoc version, i.e. an architecture of counterfactual generation that is trained on a classifier that has been fitted but whose architecture is unknown. This extension of the VCNet model is denoted by PhVCNet.

PhVCNet has the same general architecture made of a classifier and a cVAE. It also shares the same trick of learning a cVAE to reconstruct examples and to tweak it at inference. As the classifier is black-box, the machine learning problem turns out to train only the cVAE, conditioned by examples class (and immutable features if any). The architecture is similar to the one of the Figure 2, replacing the fixed black box predictor. More precisely, the predictor still takes examples as input and outputs probabilistic class predictions. The cVAE is composed of the same layers block as VCNet. For training, we optimize the similar loss of equation 3 without the $\mathcal{L}_{pred}$ term.

This model can be seen as a ImmutableVCNet for which we split the training procedure in two different parts: the training of the predictor and the training of the counterfactual generation.
<table><caption>**Table 1** Datasets characteristics for our experiments.</caption><thead><tr><th>Dataset</th><th>Size</th><th>Continuous</th><th>Categorical</th><th>Immutable variables</th><th>Classes</th></tr></thead><tbody><tr><td>Adult</td><td>32,561</td><td>2</td><td>6</td><td>[Age, Sex]</td><td>2</td></tr><tr><td>Breast-cancer</td><td>569</td><td>30</td><td>0</td><td>-</td><td>2</td></tr><tr><td>COMPAS</td><td>10,000</td><td>4</td><td>3</td><td>[Age, Race, Sex]</td><td>2</td></tr><tr><td>GMC</td><td>150,000</td><td>10</td><td>0</td><td>[Age]</td><td>2</td></tr><tr><td>HELOC</td><td>10,459</td><td>21</td><td>0</td><td>-</td><td>2</td></tr><tr><td>OULAD</td><td>32,593</td><td>23</td><td>8</td><td>-</td><td>2</td></tr><tr><td>Student</td><td>649</td><td>2</td><td>14</td><td>-</td><td>2</td></tr><tr><td>Titanic</td><td>891</td><td>2</td><td>24</td><td>-</td><td>2</td></tr><tr><td>Toy problem</td><td>300</td><td>2</td><td>0</td><td>-</td><td>3</td></tr></tbody></table>

It is worth noting that one strength of this architecture is to accept any probabilistic classifier as predictor: it can be shallow or deep, differentiable or not. More specifically, the post-hoc version of VCNet can also generate counterfactuals for classical machine learning models (e.g., random forest or XBGoost algorithms). This is a particular interest when the classification problems are difficult for a neural architecture. Indeed, the classification accuracies of shallow classifiers are often higher than the ones of neural network architectures (Borisov et al., 2022).

# 5 Experiments and Results

Our experiments are organized into three main steps: we first investigate the VCNet model and propose some analysis of its components. Then, we compare our different models VCNet, PhVCNet and ImmutableVCNet. Finally, we propose a comparison of our approaches with respect to state-of-the-art competitors.

Our experiments are based on the integration<fnref n="2" /> of VCNet into the Carla framework (Pawelczyk, Bielawski, van den Heuvel, Richter, & Kasneci, 2021) which integrates six binary-classification datasets from UCI (Adult, Student, Heloc, Titanic, Breast Cancer and Give me some credit) (GMC), 3 of which have immutable variables defined (Adult, COMPAS and GMC). A synthetic dataset has also been used in the first experiments to assess the disentanglement by the cVAE. Table 1 details the datasets characteristics. Depending on the experiments, we selected the most suitable sets of datasets. For all the experiments, the proportion of training, validation and testing sets were 60%, 20% and 20% respectively.

The quality of the counterfactual generation is evaluated using four metrics (mathematical details are provided in Appendix 9.2): two metrics (**Validity** and **Prediction gain**) provide information about the capability to generate counterfactuals in a different class than the class of the example; the **Proximity** (the lower, the better) provides information about the similarity of the counterfactual wrt the original example. This is required by the actionability principle of counterfactuals: good counterfactuals must involve few changes. The **Proximity score** is a plausibility metric which is based on the minimal distances of a counterfactual with the examples of its class.

<footnote n="2">²Source code of the integration of VCNet in the Carla framework is available here: https://github.com/Orange-OpenSource/carla_croco_vcnet. For a more practical use of our architecture, we also provide an easy to integrate implementation: https://gitlab.inria.fr/tguyet/vcnet.</footnote>
<figure><img src="image_4.png" /><figcaption>**Fig. 3** Comparison of the examples/counterfactuals distributions for synthetic data. All graphics represent the projection of the examples or counterfactuals on the first two dimensions of the examples space ($\mathbb{R}^8$). The graphic on the left represents the original dataset. The three other graphics represent counterfactuals generated from the examples of the test set belonging to each class. For these three rightest graphics, the same examples have been used to generate counterfactuals with the two other classes. The color/shape of the point represents class information: the class the example belongs to (graphic on the left) and the class requested for counterfactual generation (3 graphics on the right).</figcaption></figure>

Moreover, we used the predictor **Accuracy** to evaluate the quality of VCNet predictor, the **Time** at inference to generate counterfactuals and **Constraint violation**. This latter metric quantifies the number of times an immutable feature is altered in the generated counterfactual (feasibility). A null value indicates that no immutable features were changed.

## 5.1 Study of the VCNet Components

This section provides a detailed analysis of the ablation studies conducted on the VCNet architecture. The objective is to investigate the influence of removing specific components from the network on both the counterfactual quality and predictive accuracy. The experiments are divided into three sections, each focusing on different aspects. The first section investigates the influence of different conditioning possibilities in the cVAE component. The second section evaluates the effect of using a shared representation between the predictor and the cVAE block. Finally, the third section explores the effect of joint-training on counterfactual quality. By analyzing these ablation studies, we aim to gain valuable insights into the importance of the different components in the VCNet architecture.

### 5.1.1 cVAE for Counterfactual Generation: an Hypothesis Assessment

Our proposal relies on the ability of a cVAE to actually disentangle the class and its content, such that the decoder can be used to generate counterfactual examples by changing the class conditioning. This experiment attempts to support that the cVAE behaves as expected. A cVAE, i.e. a couple of an encoder and a decoder, denoted respectively $\varphi(x, c)$ and $\psi(z, c)$, is trained on labeled examples.

We generate a synthetic dataset of examples in $\mathbb{R}^8$ with three classes. Each class is distributed according to a multidimensional Gaussian distribution (see Figure 3 on the left).
<figure><img src="image_5.png" /><figcaption>**Fig. 4** Distance between $x$, an example of class $c$ to explain, and $x' = \psi(z + \delta, c')$, a counterfactual for class $c'$ perturbed in latent space by $\delta$. Each graphic illustrates this distance with respect to $\|\delta\|$ depending on the class $c$ and $c'$ (on the right: $c = 0$ and $c' = 1$; in the middle: $c = 0$ and $c' = 2$; on the left: $c = 1$ and $c' = 2$). The mean and variance are computed on 10 random $\delta$.</figcaption></figure>

Figure 3 illustrates the capability of a cVAE to generate plausible examples, so-called *counterfactuals*, in the context of VCNet, when changing the class that conditions the decoder. The figure on the left illustrates the dataset of examples. Each colored group of points corresponds to a class. The three figures on the right illustrate the collection of “counterfactuals” generated for each of the three classes. The principle is to generate an example $x'$ by changing the class of an example $x$ when decoding its latent representation. Let $x$ be an example from the test that belongs to class $c$ (original class), $x' = \psi(\varphi(x, c), c')$ where $c' \neq c$ is an alternative class. Each figure corresponds to one origin class, the color of the point correspond to the conditioning class ($c'$).

We observe that the positions and the spreads of counterfactuals are similar across the figures. This means that taking $\psi(\varphi(x, c), c')$ generates a counterfactual that looks similar to an example of class $c'$ whatever the origin class of $x$. Thus, it demonstrates that cVAE can be used to generate plausible counterfactuals.

Moreover, $x'$ is a good counterfactual if it is similar to $x$. The question is whether $z = \varphi(x, c)$ is a better choice to generate an example $\psi(z, c')$ than any other example $\psi(z', c')$ (which also likely belongs to $c'$). To assess this behavior, we randomly generate 10 latent representations $z' = z + \delta$ for each $x$, and compute the Euclidean distance between $x' = \psi(z', c')$ and $x$.

Figure 4 shows three graphs: one per couple of classes (the class of the example to explain and the class requested as counterfactual). Each graph illustrates the mean Euclidean distance between $x'$ and $x$ with respect to $\|\delta\|$. When $\|\delta\| = 0$, it uses the latent representation of $x$ as input of the cVAE decoder. Intuitively, we expect to have $\psi(\varphi(x, c), c')$ closer to $x$ than $\psi(\varphi(x, c)+\delta, c')$ and thus, that the higher $\|\delta\|$, the higher the mean distance to the original example. The two graphics on the right illustrate the expected behavior. In these cases, the latent representation of the example seems to generate a counterfactual that is the most similar among the examples of the opposite class. Nonetheless, we observe that it is not always the case. We can note that the distance decreases when perturbing the latent representation of examples in class 0 and regenerating counterfactual examples in class 1. This may be explained by the proximity between the two classes.
This experiment demonstrates the soundness of the VCNet approach by illustrating
that the tweaking the conditioning of a trained cVAE leads to generate examples
belonging.

5.1.2 Study of cVAE Conditioning Alternatives

During the training phase, the VCNet architecture incorporates conditioning of the cVAE component using the probability vector generated by the predictor. This conditioning takes place at both the input of the encoder and the input of the decoder. At inference time, a vector p_c is provided to the decoder to generate a counterfactual.

In this study, our objective is to explore various conditioning alternatives. We have
identified five distinct conditioning possibilities to investigate:

1. Conditioning at both the input of the encoder and the input of the decoder during training, and at inference:

(a) Pass $p_c$ to the encoder only ($T_{both\_I\_enc}$)

(b) Pass $p_c$ to the decoder only ($T_{both\_I\_dec}$) (default configuration of VCNet)

(c) Pass $p_c$ to both the encoder and decoder ($T_{both\_I\_both}$)

2. Conditioning at the input of the decoders during training, and pass the probability vector $p_c$ to the decoder at inference ($T_{dec\_I\_dec}$).

3. Conditioning at the input of the encoder during training, and pass $p_c$ to the encoder at inference ($T_{enc\_I\_enc}$).

For each study, we repeated 10 times (with different random seeds), the following protocol: 1) Train VCNet in a given conditioning configuration; 2) Compute a set of counterfactuals from a fixed set of test examples; 3) Compute counterfactual metrics and predictive accuracy.

Figure 5 illustrates the mean differences between the results obtained with the default configuration of VCNet and the ones with the four other configurations. We observe that all configurations where the decoder is conditioned during training and tweaked at inference time perform equally well across all metrics. However, when the decoder is not conditioned during training or not tweaked at inference, there is a significant drop in validity. This behavior is also observed in the prediction gain metric, which is logical considering that the counterfactual typically does not belong to a different class in most cases. However, these configurations produce better results for the proximity metric since the lower, the better for this metric.

In the alternative configurations, where the decoder is conditioned and tweaked
at inference, VCNet demonstrates equal performance across all metrics, except for
the *T_dec_I_dec* configuration where differences in accuracies appeared. Nonetheless,
these differences are less than 1% on average.

All of this suggests that conditioning at the input of the encoder is not necessary.
Consequently, this study suggests that the best and simplest setting, yielding equiva-
lent results, is achieved by conditioning solely at the input of the decoder. Henceforth,
in the following sections of this chapter, the term VCNet will specifically refer to this
architecture. Note that in Figure 5, there are no differences in terms of accuracies
regarding *T*_both_I_enc and *T*_both_I*_both* configurations. This result was expected
<figure><img src="image_6.png" /><figcaption>**Fig. 5** Metric value differences between an ablated model and the default configuration (T_both_I_dec). Each figure refers to a metric and color in the legend corresponds to the datasets.</figcaption></figure>

since no modifications was made before training, but rather only during the inference phase.

### 5.1.3 Impact of Post-Processing on Counterfactual Metrics

Section 4.1 introduced some transformations of the counterfactuals generated by VCNet in order to improve the realism of generated values. The purpose of this section is to study the impact of this transformation on counterfactual metrics, primarily on validity and sparsity. To evaluate the improvements regarding the sparsity of the counterfactuals, we introduce a sparsity metric that is defined as the number of features that have different values in both the example to explain and the counterfactual.

As a reminder, $\epsilon_i$ is defined as a threshold where the change between the example to explain and the counterfactual according to the feature *i* is equivalent to no change. For the sake of simplicity, and because the numerical variables are normalized into $[0, 1]$, we have chosen to fix the same value of $\epsilon$ for all features ($\epsilon_i = \epsilon$).

Figure 6 describes the evolution of counterfactual metrics for a threshold of $\epsilon$ ranging from 0 to 0.4 on the HELOC dataset. The counterfactuals are computed from the test set, and metrics are average for each example. We observe a drop in validity and prediction gain when $\epsilon$ is greater than 0.1. It seems reasonable because from a certain threshold there will be no more changes regarding the numerical features. In terms of proximity and sparsity, it decreases as $\epsilon$ increases (which was the expected behavior). The proximity score increases, which means that the distance of the counterfactuals to examples of the same predicted class increases. Indeed, increasing $\epsilon$ has the effect of moving the counterfactuals closer to examples to explain and therefore far from existing examples of the opposite predicted class.

Table 2 presented the variance of the counterfactual metrics for a threshold value below 0.1 and for each of the 6 datasets. We observe high variance values for the
<figure><img src="image_7.png" /><figcaption>**Fig. 6** Evolution of counterfactual metrics for a threshold of $\epsilon$ ranging from 0 to 0.4 on the HELOC dataset. Each plot represent a metric on the y-axis and values of $\epsilon$ in the x-axis. The metrics are (from left to right): validity, proximity, prediction gain, proximity score and sparsity.</figcaption></figure>

<table><caption>**Table 2** Variance of counterfactuals metrics for $\epsilon$ between 0 and 0.1.</caption><thead><tr><th rowspan="2">Datasets</th><th colspan="5">Variance wrt ε</th></tr><tr><th>Validity</th><th>Proximity</th><th>Prediction Gain</th><th>Proximity Score</th><th>Accuracy</th></tr></thead><tbody><tr><td>Adult</td><td>1.31e-3</td><td>0.15</td><td>6.37e-3</td><td>5.48e-3</td><td>3.72</td></tr><tr><td>OULAD</td><td>5e-4</td><td>8.87e-2</td><td>6.58e-3</td><td>1.08e-3</td><td>4.11</td></tr><tr><td>HELOC</td><td>1.39e-3</td><td>0.16</td><td>6.6e-3</td><td>5.5e-3</td><td>3.72</td></tr><tr><td>Student</td><td>8.33e-3</td><td>1.85e-1</td><td>1.13e-2</td><td>7.05e-3</td><td>0.31</td></tr><tr><td>Titanic</td><td>1.29e-2</td><td>1.17e-1</td><td>1.21e-2</td><td>1.77e-2</td><td>0.46</td></tr><tr><td>Breast-cancer</td><td>1e-6</td><td>0.16</td><td>1.12e-3</td><td>1.42e-2</td><td>3.01</td></tr></tbody></table>

sparsity when the datasets contain a high number of numerical features, justifying the positive impact of the post-hoc processing. The proximity holds also a high variance, which seems reasonable (the lower the sparsity, the lower the proximity). For other metrics, the results indicate low variance values. Based on these observations, we assume that a threshold of 0.1 is a good trade-off. Indeed, it allowed to increase the sparsity of the solution without decreasing too much the performances on other metrics.

## 5.2 Comparisons of VCNet Models

This section is dedicated to the comparison of different models. We start by comparing VCNet against PhVCNet and CounterNet, a method that inspired VCNet. Then, we compare our two main models VCNet and ImmutableVCNet.

### 5.2.1 Joint-Training (VCNet) vs Post-Hoc (PhVCNet)

The motivation of the original architecture of VCNet is to build coherent models for prediction and counterfactual generation to provide more accurate counterfactuals. VCNet achieves this objective by proposing a joint-training procedure, and an architecture with a block of layers shared by both the predictor and the cVAE components. The objective of this study is to examine the influence of these two aspects of VCNet.

In a first experiment, we investigate the effect of the shared layers. To this end, we compare the VCNet architecture (see Figure 1) with an equivalent architecture which separates the first layers of predictors and the cVAE while maintaining the joint learning of the components. In practice, this equivalent architecture is obtained with
<table><caption>**Table 3** Maximum absolute difference of metrics between VCNet and the “split-layers VCNet” (see details in the main text).</caption><thead><tr><th rowspan="2">Datasets</th><th colspan="5">Maximum absolute difference</th></tr><tr><th>Validity</th><th>Proximity</th><th>Prediction Gain</th><th>Proximity Score</th><th>Accuracy</th></tr></thead><tbody><tr><td>Adult</td><td>6.7e-3</td><td>0.53</td><td>0.06</td><td>0.01</td><td>2.58e-3</td></tr><tr><td>OULAD</td><td>7.36e-4</td><td>0.06</td><td>0.01</td><td>0.08</td><td>5.4e-3</td></tr><tr><td>HELOC</td><td>3.06e-3</td><td>0.27</td><td>0.01</td><td>0.04</td><td>2.68e-3</td></tr><tr><td>Student</td><td>3.07e-2</td><td>0.38</td><td>0.03</td><td>0.03</td><td>1.23e-2</td></tr><tr><td>Titanic</td><td>1.52e-1</td><td>2.16</td><td>0.14</td><td>0.08</td><td>1.79e-2</td></tr><tr><td>Breast-cancer</td><td>0.0</td><td>0.01</td><td>2.0e-3</td><td>1e-3</td><td>1.2e-4</td></tr></tbody></table>

the ImmutableVCNet architecture without immutable characteristics (see Figure 2). We follow the same experimental protocol as in the previous study, and we compare the two distinct models. Despite the apparent separation of the two networks layers, training the both at the same time, i.e., within the same optimization problem, implies information sharing across all layers.

Our intuition is that the joint training is more impactful on the quality metrics than sharing a layer in the architecture.

In this experiment, we performed several runs using the same set of parameters. Each run produced metric values that are summarized in Table 3 through the computation of the maximum absolute difference. A low maximum absolute difference indicates that the variation across runs is small. Nonetheless, these differences may be positive or negative (especially when the results are close), which is why we focus on the maximum absolute difference: it captures the magnitude of the discrepancy between methods, regardless of which one performs better.

We observe that the split-layers model performs equally well compared to VCNet on all metrics and datasets. Notably, we observe no significant validity drop. Our intuition is that passing the prediction vector $\hat{p}_i$ to the cVAE during training provides sufficient information about the decision boundary to generate valid counterfactuals.

Then, we compare VCNet with its post-hoc version (PhVCNet) in order to study the impact of joint-training on counterfactuals. Table 4 provides the results of the post-hoc version compared to those obtained previously with the joint-training approach. We observe a severe drop of validity for every dataset, which justifies that the joint-training approach allows a better alignment of the explanation task with the prediction task. We also observe a significant decrease in prediction gain for all datasets, which means less confidence in the class change of the counterfactual. Besides, proximity is higher on the six datasets. Thus, we can argue that this drop of prediction gain does not benefit to closer counterfactuals with respect to examples to explain. In terms of model accuracies, training the prediction model alone leads to comparable results, which indicates that the joint-training approach is not at the expense of a lower accuracy.

In conclusion, the cVAE conditioning study has demonstrated the importance of conditioning at the input of the decoder. Regarding the shared layers block study, it has been shown that establishing a shared representation between the predictor and the counterfactual generator blocks is unnecessary for achieving high validity levels. However, it is worth noting that including shared layers has no negative impact on validity and also reduces the model size. On the other hand, the joint-training approach
has proven to have a significant impact on performances. Particularly, it has notably
improved the alignment between the prediction and the explanation, compared to the
post-hoc version where a severe drop of validity was observed.

5.2.2 Comparisons between VCNet and ImmutableVCNet

In this experiment, we want to assess that adding hard constraints on immutable
features does not decrease the quality of the counterfactuals. We compare the quality
of counterfactuals generated by ImmutableVCNet against those generated by VCNet
on the three binary classification datasets for which we selected manually immutable
features (see dataset characteristics in Table 1).

Table 5 provides the mean and standard deviation values of our metrics for both VCNet and ImmutableVCNet.

Counterfactual Quality

We observe that both VCNet and ImmutableVCNet achieve 100% validity on the three
datasets. In terms of proximity, ImmutableVCNet outperforms VCNet on all three
datasets. This indicates that the counterfactuals generated by ImmutableVCNet are
closer to the examples being explained than those generated by VCNet. The additional
constraints on the changes seem imposing to find less distant counterfactuals.
In terms of prediction gain, ImmutableVCNet shows higher values for the Adult and
GMC datasets, but it is 9% lower for the GMC dataset. Proximity scores are rela-
tively similar for the COMPAS and Adult datasets, but significantly higher for the
GMC dataset. When considering the plausibility of the counterfactuals (prediction
gain and proximity score), we cannot conclusively state that ImmutableVCNet gen-
erates counterfactuals as plausible as those returned by VCNet, mainly due to the
proximity score's discrepancy with the GMC dataset. This shows that the two dimen-
sions of realism are orthogonal: increasing the feasibility through hard constraints in
immutable feature does not guaranty to improve the plausibility of counterfactuals.
For VCNet, the constraint violation metric shows values close to 1 for each dataset,
indicating that, on average, almost only a single immutable feature is modified. As
expected, ImmutableVCNet has no constraint violations.

Predictive Accuracy

The performances in accuracy of VCNet and ImmutableVCNet are similar for the *Adult* and *COMPAS* datasets. Regarding the *GMC* dataset, ImmutableVCNet achieves approximately 1% higher accuracy compared to VCNet. This confirms that training of a prediction model jointly with its counterfactual generator does not decrease its accuracy. This is still the case when integrating immutable features. In addition, the average time required for counterfactual generation are similar for VCNet and ImmutableVCNet.

In summary, the performance of ImmutableVCNet closely aligns with that of VCNet for most metrics. However, counterfactuals outputted by ImmutableVCNet are more proximate to their explained example compared to those generated by VCNet. In addition to the augmentation of realism, immutability constraints helps to generate sparser changes.
<figure><img src="image_8.png" /><figcaption>**Fig. 7** Illustration of a counterfactual generated for both CounterNet and ImmutableVCNet on the Adult dataset.</figcaption></figure>

## 5.3 Comparisons of ImmutableVCNet with Competitors

Now that we have shown that ImmutableVCNet is our best model, we compare it with
respect to state-of-the-art models.

### 5.3.1 Qualitative Comparison between ImmutableVCNet and CounterNet

This section illustrates the practical benefit of the enhancement of realism in counterfactual generation. Figure 7 depicts an example *x* from the Adult dataset along with the corresponding counterfactuals generated by both ImmutableVCNet and CounterNet (Guo et al., 2021). In this example, we used the first feature of ImmutableVCNet to add immutability on the Age and Gender attributes ... that is not possible to constraint with CounterNet. In addition, we activated the post-processing of ImmutableVCNet to round the numerical values to the nearest integer.

In this particular example, the predicted probability of earning more than 50k$ is 0.04 for both ImmutableVCNet and CounterNet. The counterfactual generated by CounterNet suggests changing the “marital status” and increasing the “education level”, “age” and “hours per week” features, resulting in a predicted probability of 0.90. However, this counterfactual breaks the age immutability constraint. Another subtle issue with the counterfactual in terms of realism is that the “occupation” feature remains unchanged. It is unrealistic to have a PhD while working as a Blue-collar, as it is a rare event. In fact, among the 413 individuals with a PhD in the dataset, only 5 are in this situation. Lastly, the numerical value advised for the number of hours per week is a bit confusing: will the income be greater than 50k$ in case the person works 43 hours?
<figure><img src="image_9.png" /><figcaption>Fig. 8 Generation time for each dataset, and post-hoc method, compared to ImmutableVCNet.</figcaption></figure>

On the other hand, the counterfactual generated by ImmutableVCNet satisfy by
design the immutability constraints and the value of the number of hour per week
is less confusing (but not necessary compliant with laws that apply). It proposes a
similar set of actions (same number of changes), suggesting an increase in “educa-
tion level” and a shift to a White-collar occupation, which seems more realistic.
Additionally, CounterNet generates 1,371 counterfactuals with PhD education and
Blue-collar occupation, while ImmutableVCNet generates only one. This observation
supports our intuition that ImmutableVCNet is able to generate more plausible and
feasible counterfactuals compared to CounterNet.

5.3.2 Quantitative Comparisons

Table 6 details the seven competitors against with we compare ImmutableVCNet. Out of the ten methods available in Carla and based on PyTorch framework, we did not succeed to run three of them. Note that the FACE (Poyiadzi et al., 2020) method includes three different versions. Among these versions, two of them, namely *FACE*<sub>knn</sub> and *FACE*<sub>eps</sub>, have been implemented within the framework. Methods that include a realism constraint are indicated by a cross in the realism constraint column. Wachter and GS are excluded from this category, as they only optimize the class-distance trade-off.

For this quantitative comparison with respects to state-of-the-art models, we uti-
lized the predictor component of ImmutableVCNet as input for the seven post-hoc
counterfactual generation methods. We used the 3 binary classification datasets and
selected all examples from the test set to generate counterfactuals for the COMPAS
and GMC datasets. For the Adult dataset, we selected a random sample of 400 exam-
ples in the test set, as the FACE implementation fails to run on a high number of
samples. We obtain 100% of validity for each method, and on each dataset. The results
are illustrated in Figures 8 to 11.

Figure 8 illustrates the average time required for counterfactual generation, this for different methods across various datasets. ImmutableVCNet has the lowest generation time among all methods across all datasets, and this while reaching 100% validity levels. This makes it the most scalable method for counterfactual generation.

As expected, ImmutableVCNet demonstrates no constraint violation (see Figure 9),
indicating that the immutable features remain unchanged by the counterfactual gen-
eration, unlike FACE, DiCE, and Wachter methods. Note that DiCE implementation
<figure><img src="image_10.png" /><figcaption>Fig. 9 Constraint violation for each dataset, and post-hoc method, compared to ImmutableVCNet.</figcaption></figure>

<figure><img src="image_11.png" /><figcaption>Fig. 10 Prediction gain for each dataset, and post-hoc method, compared to ImmutableVCNet.</figcaption></figure>

has an option to set up immutable features, but it has not been activated in our examples. With this option, DiCE would have no violation of immutability constraints.

Note that drawing conclusions about this property is challenging, as immutable feature's treatments were added to some methods in the framework. For instance, the original paper on the growing sphere (GS) method did not include treatments for immutable features, but one was included in the framework implementation.

Figure 10 presents the results for the prediction gain metric, where higher values indicate better performance. On the *Adult* dataset, *ImmutableVCNet* ranks within the top three methods, positioned between CRUDS and REVISE, which also employ generative models for counterfactual generation. As expected, GS and Wachter exhibit the lowest values, since they solely optimize a distance class trade-off. Surprisingly, CCH-VAE performs comparably to GS and Wachter methods despite incorporating a realism (plausibility) constraint through a variational autoencoder. On the *GMC* dataset, *ImmutableVCNet* ranks first. Conversely, DiCE and CHVAE exhibit the poorest performances, ranking before both GS and Wachter. Thus, we observe that regarding the prediction gain, *ImmutableVCNet* performs as well as the top-performing methods that include a realism constraint.

The results for the proximity score metric are presented in Figure 11, where lower values indicate better performance. Among all the datasets, FACE demonstrates the best performance. This can be attributed to the fact that the counterfactuals generated by FACE are existing examples. On the *Adult* and *COMPAS* datasets, it is observed that all methods, including *ImmutableVCNet*, demonstrate similar levels of
<figure><img src="image_12.png" /><figcaption>Fig. 11 Proximity score for each dataset, and post-hoc method, compared to ImmutableVCNet.</figcaption></figure>

<figure><img src="image_13.png" /><figcaption>Fig. 12 Proximity for each dataset, and post-hoc method, compared to ImmutableVCNet</figcaption></figure>

performance, except for CRUDS and DiCE, which achieve significantly higher values. However, when considering the *Adult* dataset, GS and Wachter also achieve proximity scores comparable to other methods that include a realism constraint which was not expected. Thus, we conclude that ImmutableVCNet achieves comparable levels of proximity score when compared to methods that incorporate a realism constraint, except on the *Adult* dataset.

The results for the proximity metric can be found in Figure 12, where lower values indicate better performance. For the *Adult* and *COMPAS* datasets, ImmutableVCNet performs as well as other methods. FACE achieves higher levels of proximity, which can be attributed to the fact that the counterfactuals generated by FACE are existing examples within the dataset, requiring more significant changes to obtain them. Conversely, CRUDS demonstrates lower performance compared to other methods. However, when it comes to the *GMC* dataset, ImmutableVCNet exhibits the poorest levels of proximity among the methods. Nonetheless, ImmutableVCNet proves to be competitive on two out of the three datasets.

# 6 Discussion and Conclusion

In conclusion, we presented VCNet, a self-explaining model designed to generate realistic counterfactuals, ie. plausible and feasible counterfactuals. The VCNet architecture is built upon a generative model, specifically a cVAE (conditional variational autoencoder), design to effectively produces plausible counterfactuals. It is enhanced
with the capability to handle categorical features and post-processing to generate counterfactuals with more intuitive numerical values for users.

To further align with our realism objectives, we extended **VCNet** to support immutable features, creating a version called **ImmutableVCNet**. This version addresses the problem of the feasibility of counterfactuals by proposing recourse rules that are more actionable in practice. The proposed model maintains the plausibility of the counterfactuals by integrating the immutable features in the modeling of data. Thus, the feature correlation is preserved.

Finally, we proposed a post-hoc version of **VCNet** that address the problem of generating counterfactuals from pre-trained models. This sets up a collection of methods based on the core-architecture of **VCNet** that cover most of the practical needs for realistic, efficient and valid counterfactual generation.

We conducted extensive evaluations, comparing the quality of the counterfactuals generated by our models and some competitors, including CounterNet. We presented experiments using the Carla framework (Pawelczyk et al., 2021), a Python library designed to compare various counterfactual generation methods. The framework has been successfully adapted to include the ImmutableVCNet method. This makes our models easy to compare with state-of-the-art and future approaches for counterfactual generation.

Our findings demonstrate that **VCNet** successfully generates valid and plausible counterfactuals. The **VCNet** counterfactuals are plausible in the sense that they are close to existing examples of the same predicted class and also the result of a high confidence in the class change. The use of post-processing to clean generated numerical values enhances the quality of counterfactuals, making them more realistic.

The realism of the generated counterfactuals is enhanced by handling immutable features, with ImmutableVCNet. In addition to the feasibility of counterfactuals, the experimental comparison between ImmutableVCNet and VCNet revealed that both methods exhibit similar levels of performance regarding counterfactual quality and predictive accuracy. When compared to other methods, ImmutableVCNet demonstrated comparable results with regard to methods that incorporate realism constraints. Notably, ImmutableVCNet achieves the lowest generation time among all methods while preserving 100% validity levels. Thus, we consider that ImmutableVCNet fits with the initial objectives, by generating realistic counterfactuals, plausible and feasible, in a scalable manner while treating immutable features. Then, ImmutableVCNet is a complete solution to generate counterfactual in real-world applications.

One can notice that the self-explainable nature of ImmutableVCNet is debatable. Indeed, no layers are commonly shared between the predictor and the cVAE of an ImmutableVCNet. As a consequence, the parameters of the predictor block are updated based on the prediction loss, while the parameters of the cVAE block are updated based on the cVAE loss. This differs from the shared representation approach (the default VCNet architecture), where the parameters of the shared layer block were updated using a weighted combination of both the prediction and cVAE loss. Thus, the self-explainable's character deserves to be discussed in the case of this architecture. In some self-explainable approaches, the explanation is the basis of the decision process, where differences in explanations result in differences in predictions. However,
in *ImmutableVCNet*, the prediction task is independent of the generation task. Consequently, the explanations generated in *ImmutableVCNet* may not faithfully reflect the decision process. Thus, while being a joint-training approach, it may not be considered as truly self-explainable. On the other hand, the default version of *VCNet* can be considered as self-explainable, since the predictor and the cVAE blocks are connected through the shared layer block, allowing the two tasks to be mutually connected. However, we agree with Elton (2020) and believe that further experiments should be conducted to rigorously evaluate how the two tasks are interconnected to be considered as truly self-explainable.

Another comment on the core architecture may be in the use of the predicted class of the predictor to condition the cVAE instead of the true-class of examples. The later solution would probably be simpler to train. Nonetheless, using the predicted class in important to enable the counterfactual generation to generate valid counterfactuals. Indeed, the objective of the cVAE is more to capture the decision boundaries of the classifier than the true separations in the data. When we tweak the cVAE, the objective is to generate an example belonging to specified class, according to the classifier itself. Then, the cVAE need to model the decision of the classifier to achieve this objective. As a consequence, the faithfulness of the explanation is possible only when the predictor approximate accurately the true decision boundary. In practice, we observed that a poor predictor would lead to a poor generator of counterfactuals. This is where the post-hoc version of *VCNet*, *PhVCNet*, may be useful in practical cases: the user can first fine-tune the predictor to achieve a good accuracy and then train a counterfactual generator.

An additional observation regarding the core architecture is about the use of the predicted class to condition the cVAE instead of the true class of examples. The latter solution would probably be simpler to train. Nonetheless, using the predicted class is important to enable the generation of valid counterfactuals. Indeed, the objective of the cVAE is more to capture the decision boundaries of the classifier than the true separations in the data. When we tweak the cVAE, the objective is to generate an example belonging to a specified class according to the classifier itself. Therefore, the cVAE needs to model the decision of the classifier to achieve a good validity. As a consequence, the faithfulness of the explanation is possible only when the predictor accurately approximates the true decision boundary. In practice, we observed that a poor predictor may lead to a poor generator of counterfactuals. This is where the post-hoc version of *VCNet*, *PhVCNet*, may be useful in practical cases: the user can first fine-tune the predictor to achieve good accuracy and then train a counterfactual generator. The experiments shown that *PhVCNet* has significantly lower validity than the joint learning version on some datasets. Nonetheless, for the dataset for which the predictor accuracy is not satisfying, it proposes an interesting and easy to set up solution for generating counterfactual explanation of a pre-trained models, including shallow models.

One limitation of the proposed model lies in the definition of immutable features at training time. The *VCNet* architecture requires specifying which features are immutable during the model design stage. Once the model is trained, this choice
cannot be modified. This may be limiting in real-world contexts where immutability
depends on the instance to be explained (or on the refinement of a previously gen-
erated explanation). This invites users to carefully impose immutability constraints
only on features that are genuinely immutable in their application domain.
For instance, when a dataset contains sensitive features (such as age, gender, or race),
users must consider issues of fairness, equity, and diversity in the decision-making pro-
cess. When generating decisions, one may be interested in imposing immutability on
sensitive features. At the same time, a practical objective of explainability can be to
evaluate decisions with respect to fairness, equity, and diversity. For such applications,
one would typically want to determine whether the predicted classification depends
on these variables. In this case, enforcing immutability would not be desirable, as it
may hide or prevent the detection of undesirable model behavior. The post-hoc version
of VCNet offers a good compromise in such situations, as the model itself is trained
to produce fair decisions, while a post-hoc counterfactual explainer can be trained to
assess their fairness.

A final comment is related to the local/global explanation dualism. VCNet is a
local explanation technique which could support users to better understand individual
decisions. Nonetheless, for some inquiries about automatic decisions, they could be
more interested in understanding general behaviors of a model. In this case, they are
looking for global explanations. At the time, VCNet does not addresses this question,
but some methods have been proposed to turn counterfactual generation as global
counterfactual explanations Ley, Mishra, and Magazzeni (2022); Sobieski and Biecek
(2024).

The first perspective of this work is to improve the modeling capability of the
datasets by replacing the cVAE block by alternative generative and conditional latent
space modeling. Indeed, Chadebec and Allassonnière (2022) demonstrate some mod-
eling limitations of a VAE that can be improved by geometric considerations. For
VCNet, the two useful features of the cVAE block are 1) the generation of exam-
ples from a structured latent space and 2) the disentanglement between the condition
and the example characteristics. There are alternative models that could replace
the cVAE. For instance, domain invariant auto-encoders, eg. DIVa (Ilse, Tomczak,
Louizos, & Welling, 2020), are statistical models to encode example conditionally to
a domain. They demonstrate better performances than cVAE and could be an alter-
native for VCNet by replacing domains by classes. TabDDPM models (Kotelnikov,
Baranchuk, Rubachev, & Babenko, 2023) based on diffusion models could also be a
good alternative in case of complex latent space that cVAE can not capture.

A second perspective is to integrate the counterfactual generation method into a
tool designed for users, in order to provide them with personalized, usable information
that enables them to understand, and possibly challenge or improve, automated deci-
sions. A preliminary version of such a tool has been presented in (Guyomard, Fessant,
Guyet, Bouadi, & Termier, 2023).
References

Alvarez Melis, D., & Jaakkola, T. (2018). Towards robust interpretability with self-explaining neural networks. *Proceedings of the conference on advances in neural information processing systems (nips)* (pp. 7786-7795).

Barr, B., Harrington, M.R., Sharpe, S., Bruss, C.B. (2021). *Counterfactual explanations via latent space projection and interpolation*. preprint arXiv:2112.00890.

Besnard, P., Guyet, T., Masson, V. (2019). Admissible generalizations of examples as rules. *Proceedings of the international conference on tools with artificial intelligence (ictai)* (pp. 1488-1493).

Bhan, M., Vittaut, J.-N., Chesneau, N., Lesot, M.-J. (2023). Tigtec: Token importance guided text counterfactuals. *Joint european conference on machine learning and knowledge discovery in databases* (pp. 496-512).

Borisov, V., Leemann, T., Seßler, K., Haug, J., Pawelczyk, M., Kasneci, G. (2022). Deep neural networks and tabular data: A survey. *IEEE transactions on neural networks and learning systems*,

Bowman, S., Vilnis, L., Vinyals, O., Dai, A., Jozefowicz, R., Bengio, S. (2016). Generating sentences from a continuous space. *Proceedings of the 20th signll conference on computational natural language learning* (pp. 10-21).

Byrne, R.M. (2016). Counterfactual thought. *Annual Review of Psychology*, 67, 135-157,

Chadebec, C., & Allassonnière, S. (2022). A geometric perspective on variational autoencoders. *Advances in neural information processing systems*, 35, 19618-19630,

Dandl, S., Blesch, K., Freiesleben, T., König, G., Kapar, J., Bischl, B., Wright, M.N. (2024). CountARFactuals – generating plausible model-agnostic counterfactual explanations with adversarial random forests. *Explainable artificial intelligence* (pp. 85-107).

Downs, M., Chu, J.L., Yacoby, Y., Doshi-Velez, F., Pan, W. (2020). Cruds: Counterfactual recourse using disentangled subspaces. *ICML Workshop on Human Interpretability in Machine Learning*, 2020, 1-23,

Elton, D. (2020). Self-explaining ai as an alternative to interpretable ai. *Artificial general intelligence: 13th international conference, agi 2020, st. petersburg, russia*,
september 16–19, 2020, *proceedings* (p. 95–106).

Ghandeharioun, A., Kim, B., Li, C.-L., Jou, B., Eoff, B., Picard, R.W. (2021). Dissect: Disentangled simultaneous explanations via concept traversals. *arXiv preprint arXiv:2105.15164*,,

Guidotti, R. (2024). Counterfactual explanations and how to find them: literature review and benchmarking. *Data Mining and Knowledge Discovery*, 2770-2824,

Guo, H., Nguyen, T., Yadav, A. (2021). *CounterNet: End-to-end training of counterfactual aware predictions*. *Icml workshop on algorithmic recourse*.

Guyomard, V., Fessant, F., Guyet, T., Bouadi, T., Termier, A. (2023). Interactive visualization of counterfactual explanations for tabular data. *Joint european conference on machine learning and knowledge discovery in databases* (pp. 330–334).

Haselhoff, A., Trelenberg, K., Küppers, F., Schneider, J. (2024). The gaussian discriminant variational autoencoder (GdVAE): A self-explainable model with counterfactual explanations. *Proceedings of the european conference on computer vision (eccv)*.

Hvilshøj, F., Iosifidis, A., Assent, I. (2021). Ecinn: efficient counterfactuals from invertible neural networks. *arXiv preprint arXiv:2103.13701*,

Hyde, D. (2011). The sorites paradox. *Vagueness: A guide* (pp. 1–17). Springer.

Ilse, M., Tomczak, J.M., Louizos, C., Welling, M. (2020). DIVa: Domain invariant variational autoencoders. *Medical imaging with deep learning* (pp. 322–348).

John, V., Mou, L., Bahuleyan, H., Vechtomova, O. (2019). Disentangled representation learning for non-parallel text style transfer. *Proceedings of the annual meeting of the association for computational linguistics (acl)* (pp. 424–434).

Joshi, S., Koyejo, O., Vijitbenjaronk, W., Kim, B., Ghosh, J. (2019). Towards realistic individual recourse and actionable explanations in black-box decision making systems. *ArXiv preprint arXiv:1907.09615*,,

Kingma, D.P., Mohamed, S., Jimenez Rezende, D., Welling, M. (2014). Semi-supervised learning with deep generative models. *Proceedings of international conference on neural information processing systems (nips)* (pp. 3581–3589).
Kingma, D.P., & Welling, M. (2014). Auto-encoding variational Bayes. *Proceedings of the international conference on learning representations (iclr)*.

Kotelnikov, A., Baranchuk, D., Rubachev, I., Babenko, A. (2023). TabDDPM: Modelling tabular data with diffusion models. *International conference on machine learning* (pp. 17564–17579).

Lang, O., Gandelsman, Y., Yarom, M., Wald, Y., Elidan, G., Hassidim, A., ... others (2021). Explaining in style: Training a gan to explain a classifier in stylespace. *Proceedings of the ieeecvf international conference on computer vision* (pp. 693–702).

Laugel, T., Lesot, M.-J., Marsala, C., Renard, X., Detyniecki, M. (2018). Inverse classification for comparison-based interpretability in machine learning. *Information processing and management of uncertainty in knowledge-based systems. theory and foundations* (p. 100-111).

Lewis, D. (1973). *Counterfactuals*.

Ley, D., Mishra, S., Magazzeni, D. (2022). Global counterfactual explanations: Investigations, implementations and improvements. *Workshop on privacy, accountability, interpretability, robustness, reasoning on structured data (@iclr)*.

Lipton, Z.C. (2017). The mythos of model interpretability. *Queue, 16*, 31–57,

Mahajan, D., Tan, C., Sharma, A. (2019). Preserving causal constraints in counterfactual explanations for machine learning classifiers. *arXiv preprint arXiv:1912.03277*,

Molnar, C. (2022). *Interpretable machine learning* (2nd ed.). C. Molnar. Retrieved from https://christophm.github.io/interpretable-ml-book

Mothilal, R.K., Sharma, A., Tan, C. (2020). Explaining machine learning classifiers through diverse counterfactual explanations. *Proceedings of the conference on fairness, accountability, and transparency (fat)* (pp. 607–617).

Nangi, S.R., Chhaya, N., Khosla, S., Kaushik, N., Nyati, H. (2021). Counterfactuals to control latent disentangled text representations for style transfer. *Proceedings of the annual meeting of the association for computational linguistics (acl)* (pp. 40–48).

Nemirovsky, D., Thiebaut, N., Xu, Y., Gupta, A. (2020). CounteRGAN: Generating realistic counterfactuals with residual generative adversarial nets. *Proceedings of the thirty-eighth conference on uncertainty in artificial intelligence* (pp. 1488–1497).
Panagiotou, E., Heurich, M., Landgraf, T., Ntoutsi, E. (2024). TABCF: Counterfactual explanations for tabular data using a transformer-based VAE. *Proceedings of the 5th acm international conference on ai in finance* (pp. 274–282).

Pawelczyk, M., Bielawski, S., van den Heuvel, J., Richter, T., Kasneci, G. (2021). CARLA: A python library to benchmark algorithmic recourse and counterfactual explanation algorithms. *Conference on neural information processing systems (neurips) – track on datasets and benchmarks* (p. 17).

Pawelczyk, M., Broelemann, K., Kasneci, G. (2020). Learning model-agnostic counterfactual explanations for tabular data. *Proceedings of the web conference (www'20)* (pp. 3126–3132).

Poyiadzi, R., Sokol, K., Santos-Rodriguez, R., De Bie, T., Flach, P. (2020). FACE: feasible and actionable counterfactual explanations. *Proceedings of the aaai/acm conference on ai, ethics, and society* (pp. 344–350).

Rudin, C. (2019). Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead. *Nature Machine Intelligence*, 1, 2522-5839.

Russell, C. (2019). Efficient search for diverse coherent explanations. *Proceedings of the conference on fairness, accountability, and transparency (fat)*. New York, NY, USA: Association for Computing Machinery.

Sobieski, B., & Biecek, P. (2024). Global counterfactual directions. *European conference on computer vision* (pp. 72–90).

Sohn, K., Lee, H., Yan, X. (2015). Learning structured output representation using deep conditional generative models. *Proceedings of the conference on advances in neural information processing systems (nips)* (pp. 3483–3491).

Stevens, A., Ouyang, C., De Smedt, J., Moreira, C. (2024). Generating feasible and plausible counterfactual explanations for outcome prediction of business processes. *arXiv preprint arXiv:2403.09232*,

Ustun, B., Spangher, A., Liu, Y. (2019). Actionable recourse in linear classification. *Proceedings of the conference on fairness, accountability, and transparency (fat)* (pp. 10–19).

Van Looveren, A., & Klaise, J. (2021). Interpretable counterfactual explanations guided by prototypes. *Proceedings of the european conference on machine learning and knowledge discovery in databases (ecml/pkdd)* (pp. 650–665).
Wachter, S., Mittelstadt, B.D., Russell, C. (2018). Counterfactual explanations without opening the black box: Automated decisions and the GDPR. *Harvard Journal of Law and Technology*, 31(2), 841–887,

# 7 Backgrounds on Conditional VAE

This section introduces the notion of VAE and cVAE on which our proposition relies on.

## 7.1 Variational autoencoder (VAE)

A variational autoencoder (VAE) is a type of autoencoder specifically designed for the generation of new examples (Kingma & Welling, 2014).

The VAE architecture is presented in part (1) of Figure 13. It consists of an encoder and a decoder. Given an input example $x$, the encoder produces two vectors, namely $\mu$ and $\sigma$. A latent vector $z$ is then sampled from $\mu$ and $\sigma$ and passed to the decoder. Unlike classical autoencoder architectures, the VAE’s encoder learns a latent distribution of parameters $\mu$ and $\sigma$, instead of a latent vector $z$. This means that each input example is mapped to a point sample into a distribution, rather than a specific point in a latent space. During training, the decoder learns to handle a range of variations of the encoding for the same input. This enables the decoder to not only associate a particular example with a single point in the latent space but also to recognize that all neighboring points are similar.

Let $z$ be a latent vector (drawn from the latent distribution) and $x$ an example, we denote by $q_{\phi}(z|x)$ the encoder distribution and by $p_{\theta}(x|z)$ the decoder distribution. Training a VAE is finding the parameters $\theta$ and $\phi$ that minimize the following objective function, i.e. the opposite of the Evidence Lower Bound (ELBO):

$$ \mathcal{L}_{\text{VAE}}(\theta, \phi) = -\mathbb{E}_{q_{\phi}(z|x)}[\log(p_{\theta}(x|z))] + D_{KL}[q_{\phi}(z|x) \| p(z)] \quad (7) $$

Generally, distributions are chosen to be Gaussian, meaning that $q_{\phi}(z|x) \sim N(\mu_{\phi}, \Sigma_{\phi})$ and $p_{\theta}(x|z) \sim N(x|\mu_{\theta}, \Sigma_{\theta})$ and distribution parameters are estimated thanks to back-propagation. The first term of Eq. 7 encourages the reconstruction of $x$ at the output of the decoder $x'$. The second term encourages the regularization of the latent space by pushing $q_{\phi}(z|x)$ to a Gaussian prior $p \sim N(0, I)$.

Having the reconstruction loss alone for training (first term of Equation 7), may result in latent distributions that are far from each other, which can be problematic for the generation of new examples. This, because it is possible to sample a point from an area where the autoencoder has never seen samples before, leading to poor generalization. However, by adding a regularization term (second term of Equation 7) to the training process, the latent distributions are pushed closer together, which improves the ability of the autoencoder to generalize to new data points (Kingma & Welling, 2014).
<figure><img src="image_14.png" /><figcaption>Fig. 13 (1) Variational autoencoder architecture (VAE) and (2) Conditional variational autoencoder architecture (cVAE). The encoder layers are in orange and the decoding layers in blue.</figcaption></figure>

## 7.2 Conditional Variational Autoencoder (cVAE)

A conditional variational autoencoder is a VAE where distributions are conditioned on a given variable c (Sohn et al., 2015). Part (2) of Figure 13 depicts the architecture, which is similar to that of a standard VAE but with a key modification: the input c is fed into both the encoder and the decoder. Then the objective function of Eq. 7 can be rewritten as:

$$ \mathcal{L}_{\text{cVAE}}(\theta, \phi) = -\mathbb{E}_{q_{\phi}(z|x, c)}[\log(p_{\theta}(x|z, c))] + D_{KL}[q_{\phi}(z|x, c) \| p(z)] \quad (8) $$

The encoder distribution becomes $q_{\phi}(z|x, c)$ and is pushed to the Gaussian prior $p \sim N(z | 0, I)$ by the regularization term regardless of the value of c. The decoder reconstructs x from the concatenation of z with c.

The initial objective of conditional variational autoencoder is to enrich the expressiveness of the model in supervised settings. In this article, we use a property of the cVAE to disentangle the class specification from the content of the data (Kingma, Mohamed, Jimenez Rezende, & Welling, 2014).<fnref n="3" /> Intuitively, the latent variable z does

<footnote n="3">³For Kingma et al. (2014), what we call the “content” in this paper is denoted the “style”. It refers to the writing style of digits in MNIST-like datasets.</footnote>
<figure><img src="image_15.png" /><figcaption>**Fig. 14** Experiment of Kingma et al. (2014) on the MNIST dataset. Each square of digits corresponds to different values of *z* with the same class condition *c*, both are passed at the input of a cVAE decoder.</figcaption></figure>

not need to model the example category, then it can focus on modeling the content of the examples, which is shared by all the categories.

To illustrate the effective disentanglement of category and content, Kingma et al. (2014) show that the decoder $p_θ(x|z, c)$ can be used to generate images with the same shared content by changing the class *c* and keeping the same random values for *z*. Figure 14 depicts this experiment in the case of the MNIST dataset. The figure is composed of three blocks, each comprising varying values of *z* for a fixed value of *c*. The red-framed digits are generated using identical values of *z* but different *c* values. We observe that although these digits share similarities in their handwriting (e.g., line thickness or orientation), they differ because they belong to different classes.

The same property has been applied to text style transfer (John et al., 2019). In this context, the style is the category, and the content is the wording. For tabular data, the notion of "content" and "style" can be illustrated in the context of credit approval. The "style" characterizes the categories of person's credit (accepted or rejected) and the "content" characterizes the other features. More specifically, the latter models correlations between features that are independent of the credit approvals.

In our proposal, we exploit the modeling properties of a cVAE to generate counterfactuals. Considering that the cVAE disentangles the category and the content, the decoder of a cVAE can be tweaked in a flexible way. For *z* the encoding of an example *x* of class *c*, $p_θ(x|z, c')$ generates examples of a category $c' \neq c$. In addition, $(z, c')$ is likely the element of class *c* that is the closest to $(z, c)$ in the latent space. As this space is regularized, $p_θ(x|z, c')$ generates examples that are similar to *x*, but belonging to a different class. This fits exactly the expectations of counterfactuals and will be assessed in Section 5.1.1.
<figure><img src="image_16.png" /><figcaption>**Fig. 15** The CounterNet architecture. It is composed of three components: an encoder, a predictor, and a counterfactual generator. The encoder layers are represented in blue, the predictor layers in yellow, and the decoder layers in red.</figcaption></figure>

# 8 CounterNet: A state-of-the-art model

This section presents CounterNet, a deep learning model introduced by Guo et al., which jointly learns the prediction and the counterfactual generation tasks (Guo et al., 2021). This section is organized as follows: First we describe the CounterNet architecture, then the training process, and finally we discuss the advantages and limitations of this approach.

## 8.1 Model architecture

The model architecture is depicted in Figure 15, and it consists of three components: an encoder, a predictor, and a counterfactual generator. An input example $x$ is first fed to the encoder, which maps it to a lower dimensional representation $z_x$. This representation is then passed to both the predictor and the counterfactual generator. The predictor component is trained to output a decision in the case of binary classification problem, forming a classification model with the encoder. The counterfactual generator, on the other hand, is trained to generate a counterfactual. It takes the output of the encoder ($z_x$) and the final representation of the predictor ($p_x$) as input and generates a counterfactual ($x_{cf}$). The intuition is that $p_x$ provides information about the decision boundary, while $z_x$ provides information about the example being explained, both being sufficient to generate a counterfactual.
## 8.2 Training

The goal is to jointly learn the two tasks, namely the prediction task and the counterfactual generation task. The loss function is composed of three terms:

$$ 
\begin{aligned}
L &= \lambda_1 \mathcal{L}_1 + \lambda_2 \mathcal{L}_2 + \lambda_3 \mathcal{L}_3 \\
&= \lambda_1 \underbrace{\frac{1}{N} \sum_{i=1}^{N} (y_{x_i} - \hat{y}_{x_i})^2}_{\text{Accuracy of the predictor}} + \lambda_2 \underbrace{\frac{1}{N} \sum_{i=1}^{N} (x_i - x_{cf}^i)^2}_{\text{Counterfactual proximity}} + \lambda_3 \underbrace{\frac{1}{N} \sum_{i=1}^{N} (\hat{y}_{x_{cf}^i} - (1 - \hat{y}_{x_i}))^2}_{\text{Counterfactual class}}
\end{aligned}
$$

The first term evaluates the mean squared error between the predicted labels and the corresponding true labels. This term is designed to incentivize the predictor to make accurate predictions for the class labels.

The second term evaluates the mean squared error between the input examples and the outputs of the counterfactual generator. This term encourages the generated counterfactuals to be close to the input examples.

Finally, the third term measures the mean squared error between the predicted labels for the counterfactual and the opposite predicted labels of the input examples. The purpose of this term is to encourage the generated counterfactuals to have the opposite predicted class.

The overall loss is the weighted sum of each term, where each weight is an hyperparameter.

Training a network with both $\mathcal{L}_1$ and $\mathcal{L}_3$ objectives is a challenging task, as these objectives are divergent. On one hand, the network is trained for accurately predicting the class of the input example, and on the other hand, it is trained for predicting the opposite class for the counterfactual. To address this challenge, Guo et al. (2021) proposed a double backpropagation procedure, which involves updating the network weights twice by computing gradients from different parts of the loss function. Namely, gradients of $\mathcal{L}_1$ first and then gradients of both $\mathcal{L}_2$ and $\mathcal{L}_3$. However, it is important to note that this training method is time expensive.

## 8.3 Benefits and limits

The CounterNet method offers several benefits that align with our motivations. Firstly, once the network is trained, generating counterfactuals is a simple matter of forwarding examples through the network. The result is a drastic reduction in computing time for counterfactual generation compared to post-hoc solutions, where a cost function was optimized for each new example to explain. Secondly, CounterNet eliminates the need to individually select hyperparameter values for each counterfactual, as they are defined once in the loss function for all counterfactuals to be generated. This simplifies the process and reduces the computing time. In addition, the joint-training approach employed by CounterNet results in high levels of validity for the counterfactuals.

Despite its benefits, CounterNet does not impose any constraints on the generation of realistic counterfactuals, which is one of our primary objectives. The loss function
only encodes properties that are relevant to the counterfactual's definition. To address this limitation, we introduce VCNet, which aims to preserve the benefits of CounterNet while also imposing constraints to ensure the generation of realistic counterfactuals.

# 9 Benchmark within the CARLA framework

The CARLA framework <fnref n="4" /> offers several advantages for our experiments. Notably, it provides a list of immutable features for each dataset, which is essential for training *ImmutableVCNet* as it relies on a predefined set of immutable features. Furthermore, the framework incorporates multiple counterfactual generation methods, allowing us to compare and analyze the performance of *ImmutableVCNet*. To begin, we provide a comprehensive overview of the CARLA framework, within the context of counterfactual evaluation. We then outline the necessary modifications made to both *VCNet* and *ImmutableVCNet* to integrate them into the CARLA framework for comparative evaluations. Following the integration process, we present a comparative analysis between *VCNet* and *ImmutableVCNet*, highlighting their respective strengths and weaknesses. Additionally, we present a comparison between *ImmutableVCNet* and seven distinct counterfactual generation methods.

## 9.1 The CARLA framework

CARLA is a Python library specifically developed to benchmark counterfactual explanation methods. It includes four datasets: *Adult*, *COMPAS*, *Give Me Some Credit* (GMC) and *HELOC*. Each dataset is accompanied by a set of immutable features and is partitioned into training and testing sets, with a split ratio of 60% for training, 20% for validating and 20% for testing. The library incorporates a total of 13 counterfactual generation methods. All of them are post-hoc and 10 of them are implemented in PyTorch. Table 1 provides detailed information about the datasets, the list of immutable features, and the implemented counterfactual methods. To ensure compatibility with a wide range of counterfactual methods, the CARLA framework incorporates several distinct features. Firstly, the framework is exclusively designed to generate counterfactuals for individuals that are negatively affected (that have a negative predicted class). This design choice aligns with the requirements of recourse methods. Secondly, categorical features are treated in a specific manner within the framework. For categorical features with more than two values, a binary transformation is applied. This transformation involves selecting the most frequent value as one modality, and a separate modality is created to encompass all the other values. For instance, consider the COMPAS dataset, where the feature “race” consists of three categories: “African-American”, “Caucasian” and “other”. To transform this feature into a binary form, it is converted into two modalities: “white” and “non-white”.

Regarding the evaluation metrics, a significant number of the metrics used in the previous chapters have already been incorporated into the framework. The only exceptions were the proximity score and the prediction gain metrics, which we have now included.

<footnote n="4">⁴https://github.com/carla-recourse/CARLA</footnote>
Additionally, the framework includes a metric related to immutable features, named constraint violation. This metric quantifies the number of times an immutable feature is altered in the generated counterfactual. A null value indicates that no immutable features were changed. The lower, the better.

## 9.2 Metrics

**Validity** A counterfactual is said to be valid if it achieves to obtain a different predicted class.

$$ Validity = \begin{cases} 0, & \text{if } \hat{y}_{cf} = \hat{y}_0 \\ 1, & \text{if } \hat{y}_{cf} \neq \hat{y}_0 \end{cases} $$

where $\hat{y}_{cf}$ denotes the predicted class for the counterfactual and $\hat{y}_0$ the predicted class for the example to explain. This metric is the most important, as it ensures that the solution obtained with a given method is indeed a counterfactual.

**Prediction gain** The prediction gain is given by the difference between the predicted probability of the counterfactual $x_{cf}$ and the predicted probability of the example to explain $x_0$, according to the counterfactual class.

$$ Prediction\ gain = [f_{pred}(x_{cf})]_{\hat{y}_{cf}} - [f_{pred}(x_0)]_{\hat{y}_{cf}} $$

where $\hat{y}_{cf}$ denotes the predicted class for the counterfactual. A higher prediction gain implies more confidence in the class change of the counterfactual regarding the machine learning model.

**Proximity** This metric is defined as the $L_1$ norm between the example to explain $x_0$ and the counterfactual $x_{cf}$. A low value indicates fewer feature changes to be made to obtain the counterfactual.

$$ Proximity = \|x_{cf} - x_0\|_1 $$

**Proximity score** This metric measures the distance of the counterfactual $x_{cf}$, to the closest existing example with the same predicted class in the data: $a_0$, scaled by the distance to the closest example of $a_0$ in the data with the same predicted class. The intuition is that a counterfactual is realistic because it looks like an existing example in the data.

$$ Proximity\ score = \frac{d(x_{cf}, a_0)}{\min_{x_j \in X^{pred}(x_{cf})} d(a_0, x_j)} $$

where: $X^{pred}(x_{cf})$ is a set of existing examples that have the same predicted class as $x_{cf}$ and $a_0 = \underset{x_j \in X^{pred}(x_{cf})}{\operatorname{argmin}} d(x_{cf}, x_j)$.

## 9.3 VCNet models compatibilites

In the default version of VCNet, each categorical feature was one-hot encoded, and softmax layers were utilized at the decoder's output to obtain a one-hot encoding format through the argmax operation (see Figure 1). However, when working with the CARLA framework, a categorical feature is represented by a single column containing
binary values (0 or 1), which leads to issues when using softmax functions as the network should output a binary value instead of a binary vector for each categorical feature. As an alternative, we used a sigmoid activation function for each categorical feature. To transform a decoded sample into a one-hot encoding format, the following decision function was used:

$$T(c_i) = \begin{cases} 1, & \text{if } c_i > 0.5 \\ 0, & \text{else} \end{cases} \qquad (9)$$

Here, $c_i$ represents a binary feature outputted by the decoder. The same process was applied to ImmutableVCNet.

Additionally, for compatibility reasons, only methods implemented with PyTorch were selected in the CARLA framework.
<table><caption>**Table 4** Comparison of quality metrics of counterfactuals and predictive accuracy for three methods: VCNet, CounterNet and Post-hoc VCNet. Bold items give the best metric values among the three methods. ↑ indicates that the higher the better, while the lower the better for ↓.</caption><thead><tr><th rowspan="2">Datasets</th><th rowspan="2">Metrics</th><th colspan="3">Methods</th></tr><tr><th>VCNet</th><th>CounterNet</th><th>Post-hoc VCNet</th></tr></thead><tbody><tr><td rowspan="5">Adult</td><td>Validity↑</td><td>1.0</td><td>0.99</td><td>0.81</td></tr><tr><td>Proximity↓</td><td>6.16 ± 2.26</td><td>7.16 ± 2.13</td><td>10.03 ± 2.06</td></tr><tr><td>Prediction gain↑</td><td>0.66 ± 0.15</td><td>0.61 ± 0.17</td><td>0.38 ± 0.26</td></tr><tr><td>Proximity score↓</td><td>0.02 ± 0.06</td><td>0.31 ± 0.28</td><td>0.67 ± 0.01</td></tr><tr><td>Time↓</td><td>2.95e-5</td><td>7.3e-4</td><td>2.02e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.83</td><td>0.83</td><td>0.83</td></tr><tr><td rowspan="5">OULAD</td><td>Validity↑</td><td>1.0</td><td>0.99</td><td>0.49</td></tr><tr><td>Proximity↓</td><td>1.65 ± 1.06</td><td>11.96 ± 2.40</td><td>14.29 ± 1.52</td></tr><tr><td>Prediction gain↑</td><td>0.85 ± 0.13</td><td>0.74 ± 0.13</td><td>0.52 ± 0.44</td></tr><tr><td>Proximity score↓</td><td>0.29 ± 0.18</td><td>0.79 ± 0.01</td><td>0.38 ± 0.18</td></tr><tr><td>Time↓</td><td>1.99e-5</td><td>8.4e-4</td><td>1.55e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.92</td><td>0.93</td><td>0.92</td></tr><tr><td rowspan="5">HELOC</td><td>Validity↑</td><td>1.0</td><td>0.99</td><td>0.92</td></tr><tr><td>Proximity↓</td><td>4.78 ± 1.77</td><td>4.41 ± 1.80</td><td>6.15 ± 2.29</td></tr><tr><td>Prediction gain↑</td><td>0.57 ± 0.15</td><td>0.56 ± 0.15</td><td>0.5 ± 0.24</td></tr><tr><td>Proximity score↓</td><td>0.23 ± 0.19</td><td>0.49 ± 0.35</td><td>0.42 ± 0.25</td></tr><tr><td>Time↓</td><td>1.89e-5</td><td>5.1e-4</td><td>1.37e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.71</td><td>0.72</td><td>0.71</td></tr><tr><td rowspan="5">Student</td><td>Validity↑</td><td>0.99</td><td>1.0</td><td>0.26</td></tr><tr><td>Proximity↓</td><td>12.11 ± 3.40</td><td>19.86 ± 2.78</td><td>20.17 ± 3.54</td></tr><tr><td>Prediction gain↑</td><td>0.89 ± 0.20</td><td>0.76 ± 0.05</td><td>0.27 ± 0.43</td></tr><tr><td>Proximity score↓</td><td>0.63 ± 0.08</td><td>0.73 ± 0.06</td><td>0.75 ± 0.08</td></tr><tr><td>Time↓</td><td>5.80e-5</td><td>1.4e-4</td><td>2.85e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.91</td><td>0.92</td><td>0.90</td></tr><tr><td rowspan="5">Titanic</td><td>Validity↑</td><td>0.95</td><td>0.99</td><td>0.28</td></tr><tr><td>Proximity↓</td><td>7.64 ± 2.93</td><td>15.15 ± 4.05</td><td>9.40 ± 4.96</td></tr><tr><td>Prediction gain↑</td><td>0.81 ± 0.25</td><td>0.66 ± 0.15</td><td>0.13 ± 0.31</td></tr><tr><td>Proximity score↓</td><td>0.24 ± 0.31</td><td>0.80 ± 0.16</td><td>0.80 ± 0.26</td></tr><tr><td>Time↓</td><td>7.35e-5</td><td>1.8e-4</td><td>2.75e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.82</td><td>0.83</td><td>0.82</td></tr><tr><td rowspan="5">Breast-cancer</td><td>Validity↑</td><td>1.0</td><td>1.0</td><td>0.59</td></tr><tr><td>Proximity↓</td><td>4.63 ± 1.64</td><td>1.51 ± 1.01</td><td>12.28 ± 1.27</td></tr><tr><td>Prediction gain↑</td><td>0.97 ± 0.13</td><td>0.69 ± 0.15</td><td>0.58 ± 0.45</td></tr><tr><td>Proximity score↓</td><td>0.31 ± 0.04</td><td>0.72 ± 0.48</td><td>2.42 ± 0.10</td></tr><tr><td>Time↓</td><td>7.77e-5</td><td>5.0e-4</td><td>1.72e-5</td></tr><tr><td></td><td>Accuracy↑</td><td>0.96</td><td>0.96</td><td>0.96</td></tr></tbody></table>
<table><caption>**Table 5** Comparison of quality metrics of counterfactuals and predictive accuracy for VCNet and ImmutableVCNet. Bold items give the best metric values among the three methods. ↑ indicates that the higher the better, while the lower the better for ↓.</caption><thead><tr><th rowspan="2">Datasets</th><th rowspan="2">Metrics</th><th colspan="2">Methods</th></tr><tr><th>VCNet</th><th>ImmutableVCNet</th></tr></thead><tbody><tr><td rowspan="7">Adult</td><td>Validity↑</td><td>1.0</td><td>1.0</td></tr><tr><td>Proximity↓</td><td>2.16 ± 1.20</td><td>1.65 ± 0.95</td></tr><tr><td>Prediction gain↑</td><td>0.80 ± 0.19</td><td>0.83 ± 0.17</td></tr><tr><td>Proximity score↓</td><td>0.21 ± 0.18</td><td>0.27 ± 0.21</td></tr><tr><td>Constraint violation↓</td><td>1.02 ± 0.27</td><td>0.0 ± 0.0</td></tr><tr><td>Time↓</td><td>1.28e-5</td><td>1.23e-5</td></tr><tr><td>Accuracy↑</td><td>0.84</td><td>0.84</td></tr><tr><td rowspan="7">Compas</td><td>Validity↑</td><td>1.0</td><td>1.0</td></tr><tr><td>Proximity↓</td><td>0.85 ± 0.54</td><td>0.59 ± 0.43</td></tr><tr><td>Prediction gain↑</td><td>0.58 ± 0.16</td><td>0.53 ± 0.19</td></tr><tr><td>Proximity score↓</td><td>0.09 ± 0.10</td><td>0.08 ± 0.10</td></tr><tr><td>Constraint violation↓</td><td>1.05 ± 0.32</td><td>0.0 ± 0.0</td></tr><tr><td>Time↓</td><td>1.98e-5</td><td>2.07e-5</td></tr><tr><td>Accuracy↑</td><td>0.86</td><td>0.86</td></tr><tr><td rowspan="7">GMC</td><td>Validity</td><td>1.0</td><td>1.0</td></tr><tr><td>Proximity↓</td><td>2.11 ± 0.49</td><td>2.02 ± 0.59</td></tr><tr><td>Prediction gain↑</td><td>0.58 ± 0.07</td><td>0.60 ± 0.09</td></tr><tr><td>Proximity score↓</td><td>0.03 ± 0.01</td><td>0.21 ± 0.07</td></tr><tr><td>Constraint violation↓</td><td>1.0 ± 0.0</td><td>0.0 ± 0.0</td></tr><tr><td>Time↓</td><td>1.50e-5</td><td>1.42e-5</td></tr><tr><td>Accuracy↑</td><td>0.93</td><td>0.94</td></tr></tbody></table>

<table><caption>**Table 6** List of methods that we successfully run in the CARLA framework, with references. The realism constraint column indicates if the method incorporate a realism constraint</caption><thead><tr><th>Methods</th><th>Fullname</th><th>Realism constraint</th><th>References</th></tr></thead><tbody><tr><td>CCHVAE</td><td>Counterfactual Conditional Heterogeneous Autoencoder</td><td>✓</td><td>Paweleczyk et al. (2020)</td></tr><tr><td>CRUDS</td><td>Counterfactual Recourse Using Disentangled Subspaces</td><td>✓</td><td>Downs et al. (2020)</td></tr><tr><td>DICE</td><td>Diverse Counterfactual Explanations</td><td>✓</td><td>Mothilal et al. (2020)</td></tr><tr><td>FACE<sub>knn</sub>/FACE<sub>ep</sub></td><td>Feasible and Actionable Counterfactual Explanations</td><td>✓</td><td>Poyiadzi et al. (2020)</td></tr><tr><td>GS</td><td>Growing Spheres</td><td></td><td>Laugel, Lesot, Marsala, Renard, and Detyniecki (2018)</td></tr><tr><td>REVISE</td><td>REVISE</td><td>✓</td><td>Joshi, Koyejo, Vijitbenjaronk, Kim, and Ghosh (2019)</td></tr><tr><td>Wachter</td><td>Wachter</td><td></td><td>Wachter et al. (2018)</td></tr></tbody></table>