Victor Guyomard
email: victor.guyomard@orange.com

Françoise Fessant

Thomas Guyet

Tassadit Bouadi

Alexandre Termier

VCNet: A self-explaining model for realistic counterfactual generation

Counterfactual explanation is a common class of methods to make local explanations of machine learning decisions. For a given instance, these methods aim to find the smallest modification of feature values that changes the predicted decision made by a machine learning model. One of the challenges of counterfactual explanation is the efficient generation of realistic counterfactuals. To address this challenge, we propose VCNet -Variational Counter Net -a model architecture that combines a predictor and a counterfactual generator that are jointly trained, for regression or classification tasks. VCNet is able to both generate predictions, and to generate counterfactual explanations without having to solve another minimisation problem. Our contribution is the generation of counterfactuals that are close to the distribution of the predicted class. This is done by learning a variational autoencoder conditionally to the output of the predictor in a join-training fashion. We present an empirical evaluation on tabular datasets and across several interpretability metrics. The results are competitive with the state-of-the-art method.

Introduction

Improvements of machine learning techniques for decision systems has led to the rise of applications in various domains such as healthcare, credit or justice. The eventual sensitivity of such domains, as well as the black-box nature of the algorithms, has motivated the need for methods that explain why some prediction was made. For example, if a person's loan is rejected as a result of a model decision, the bank must be able to explain why. In such a context, it might be interesting to provide an explanation of what that person should change to influence the model's decision. As suggested by Wachter et al. [27], one way to build this type of explanation is through the use of counterfactual explanations. A counterfactual is defined as the smallest modification of feature values that changes the prediction of a model to a given output. In addition, the explanation also provides important feedback to the user. In the context of a denied credit, a counterfactual is a close individual for whom his credit is accepted and the feature modifications suggested by a counterfactual acts as recourse for the user. For privacy reason or simply because there is no similar individual with an opposite decision, we aim to generate synthetic individuals as counterfactuals.

In order to provide a meaningful recourse, the counterfactual is expected to be realistic, i.e. close to the existing examples and respecting the observed correlation among features. Furthermore, in order to be representative of its predicted class, it is interesting to obtain a counterfactual close to the existing examples but relative to the counterfactual class. A counterfactual instance is usually found by iteratively perturbing the input characteristics of the original example until the desired prediction is achieved, which is like minimizing a loss function using an optimization algorithm. Many methods proceed in this way, but differ in their definition of the loss function and optimization method [START_REF] Molnar | Interpretable Machine Learning[END_REF]. These approaches appear to be computationally expensive. Indeed, for each instance to explain, a new optimisation problem has to be solved. Most of the counterfactual methods apply to already trained decision models and treat them as black boxes in the post-hoc paradigm. However, dissociating the prediction of the model from its explanation can lead to an explanation of poor quality [START_REF] Rudin | Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead[END_REF].

Self-explaining models which incorporate an explanation generation module into their architecture, such that they provide explanations for their own predictions, can be an alternative to the previous approaches. In general, the predictor and explanation generator are trained jointly, hence the presence of the explanation generator is influencing the training of the predictor [START_REF] Daniel | Self-explaining AI as an alternative to interpretable AI[END_REF]. In this spirit, Guo et al. [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF] propose CounterNet, a neural network based architecture for the prediction and counterfactual generation along with a novel variant of back propagation to ensure the stabilization of the training process. Compared to a post-hoc approach, they are able to produce counterfactuals with higher validity. A counterfactual is said to be valid if it succeeds in reaching a different prediction. A limitation of the CounterNet approach is that counterfactuals it generates may lack realism w.r.t. the data points of the class where they are positioned. The proposed approach, VCNet, tackles this issue: similarly to CounterNet, it combines a predictor and a counterfactual generator that are jointly trained. The difference lies in the counterfactual generator based on conditional variational autoencoder (cVAE) whose latent space can be controlled and tweaked to generate realistic counterfactuals. Our approach is inspired from John et al. work about learning disentangled latent spaces in the context of text style transfer [START_REF] John | Disentangled representation learning for non-parallel text style transfer[END_REF].

Our main contribution is the proposal of a cVAE for counterfactual generation in order to generate realistic counterfactuals. Our second contribution is a self-explainable architecture of a classifier that embeds a cVAE, used as a counterfactual generator. In this architecture, both the model and the cVAE, are jointly trained with an efficient single back-propagation procedure. After recalling the properties of the variational autoencoder models (Section 3) that interest us in the context of this paper, we describe our proposal (Section 4). Then we present extensive experimental studies on synthetic and real data (Section 5). We compare the quality of the counterfactuals produced with those of CounterNet on different datasets through state-of-the-art metrics. The focus is on tabular data but we also show that our architecture is interesting on images.

Related Work

Our work is concerned with the search for counterfactual explanation that is usually found by iteratively perturbing the input features of the instance of interest until the desired prediction is reached. In practice, the search of counterfactuals is usually posed as an optimization problem. It consists of minimizing an objective function which encodes desirable properties of the counterfactual instance with respect to the perturbations. Wachter et al. [27] propose the generation of counterfactual instances by minimizing the distance between the instance to be explained and the counterfactual while pushing the new prediction toward the desired class. Other algorithms optimize other aspects with additional terms in the objective function such as actionability [START_REF] Ustun | Actionable recourse in linear classification[END_REF], diversity [START_REF] Ramaravind | Explaining machine learning classifiers through diverse counterfactual explanations[END_REF][START_REF] Russell | Efficient search for diverse coherent explanations[END_REF], realism [START_REF] Van Looveren | Interpretable counterfactual explanations guided by prototypes[END_REF].

All aforementioned techniques search for counterfactual example by solving a separate optimization problem for each instance to be explained. This optimization problem is computationally intensive, making it impractical for large numbers of instances. To address this issue, several frameworks based on generative models have been proposed. A generative counterfactual model is trained to predict the counterfactual perturbations or instances directly. Many of these frameworks use the latent space of variational autoencoder models to generate counterfactuals with linear interpolation [START_REF] Barr | Counterfactual explanations via latent space projection and interpolation[END_REF], latent feature selection [START_REF] Downs | Cruds: Counterfactual recourse using disentangled subspaces[END_REF], perturbation [START_REF] Pawelczyk | Learning model-agnostic counterfactual explanations for tabular data[END_REF] or incorporation of the target class in the latent space [START_REF] Reddy Nangi | Counterfactuals to control latent disentangled text representations for style transfer[END_REF]).

All these counterfactual generation techniques are post-hoc as they assume that the explaining task is done after the decision task with a fixed black-box model. In this post-hoc paradigm, the counterfactual search process is completely uninformed from the decision process. Post-hoc explanations may be the only option for already-trained models.

Another approach is to design models that optimize both the decision and an explanation of that decision during the learning process [START_REF] Alvarez | Towards robust interpretability with self-explaining neural networks[END_REF]. In the context of counterfactual explanations, such a strategy has been recently proposed by Guo et al. [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF] with CounterNet, a framework in which prediction and explanation are jointly learned. The optimization of the counterfactual example generation only once together with the predictive model allows a 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 allowing us to exploit text style-transfer techniques [START_REF] John | Disentangled representation learning for non-parallel text style transfer[END_REF][START_REF] Reddy Nangi | Counterfactuals to control latent disentangled text representations for style transfer[END_REF].

Backgrounds

In this section, we introduce some notations, problematic and backgrounds necessary for the presentation of the VCNet architecture in the next section.

Let X ⊆ R p represents the p-dimensional feature space and l ≥ 2 a number of classes. A training dataset, denoted D = {(x i , y i )} n i=1 , is such that x i ∈ X and y i ∈ {1, . . . , l} for each i ∈ {1, . . . , n}. For a new example x, the prediction consists in deciding to which class ŷ the example x belongs. For more generality, we consider probabilistic prediction: the prediction is a probability vector, denoted p ∈ [0, 1] p . Then, the predicted class is the most likely class according to p. The counterfactual generation yields an example x which is close to x and whose prediction ŷ is different from ŷ in case the counterfactual is valid.

Our problem is both to learn from D an accurate predictor, denoted f , and a generator of counterfactual, denoted g. Now that we have presented our problem, we introduce the notion of VAE [START_REF] Diederik | Auto-encoding variational Bayes[END_REF] and cVAE [START_REF] Sohn | Learning structured output representation using deep conditional generative models[END_REF] which our proposal relies on.

Variational Autoencoder (VAE)

A variational autoencoder is a generative model where a latent parameterized distribution is learned. If samples are drawn in the latent space according to this distribution, the decoded samples are expected to be distributed according to the training data distribution (an approximate distribution of the training data distribution is learned) [START_REF] Diederik | Auto-encoding variational Bayes[END_REF]. Formally, let z be a latent vector (drawn from the latent distribution) and x be an example, we denote by q φ (z | x) the encoder distribution and by p θ (x | z) the decoder distribution. Training a VAE is finding the parameters θ and φ that minimize the following objective function, i.e. the opposite of the Evidence Lower Bound (ELBO):

L VAE (θ, φ) = -E q φ (z|x) [log(p θ (x | z))] + D KL q φ (z | x) p(z) (1)
Generally, distributions are chosen to be Gaussian, meaning that q φ (z | x) ∼ N (µ φ , Σ φ ) and p θ (x | z) ∼ N (x | µ θ , Σ θ ) and distribution parameters are estimated thanks to back-propagation. The first term of Eq. 1 encourages reconstructing x at the output of the decoder ( x). The second term encourages the regularization of the latent space by pushing q φ (z | x) to a Gaussian prior p ∼ N (0, I).

Conditional Variational Autoencoder (cVAE)

A conditional variational autoencoder is a VAE where distributions are conditioned on a given variable c [START_REF] Sohn | Learning structured output representation using deep conditional generative models[END_REF]. The architecture is the same as a standard VAE but c is given as input of the encoder and also as input of the decoder. Then the objective function of Eq. 1 can be rewritten as:

L cVAE (θ, φ) = -E q φ (z|x,c) [log(p θ (x | z, c))] + D KL q φ (z | x, c) p(z) (2)
The encoder distribution becomes q φ (z | x, c) and is pushed to the Gaussian prior p ∼ 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 [START_REF] Durk P Kingma | Semisupervised learning with deep generative models[END_REF]. 1 Intuitively, the latent variable z does 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. show that the decoder p θ (x | z, c) can be used to generate images of the ten digits with the same shared content (let say the handwriting) by changing the class c and keeping the same random values for z. The same property has been applied to text style transfer [START_REF] John | Disentangled representation learning for non-parallel text style transfer[END_REF]. 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 the loan decision. The "style" characterizes the category of people loan (accepted or rejected ) and the "content" characterizes the other features. More specifically, the later models correlations between variables that are independent from the loan decisions.

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 = 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.

A Join Training Model

VCNet is a self-explainable2 model through counterfactual generation. Inspired by CounterNet [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF], the VCNet model is made of a predictor, f (•), and a counterfactual generator, g(•, •), that are jointly trained. In the inference phase, each part can be used on demand: on the one side, to get the prediction f (x) for some new example x and, on the other side, to generate its counterfactual g(x, c) for another class c. VCNet can be used as a self-explainable model and generates (f (x) , g (x, c)), i.e. the couple of the prediction and its counterfactual.

The trick of VCNet is to not train a counterfactual generator, but a supervised autoencoder, i.e. a cVAE. The cVAE is trained as an autoencoder and used as a counterfactual generator in inference.

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 the trained model is used to generate counterfactuals.

VCNet Architecture

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

1. Shared layers, s β , that transform the input into a dense latent representation. We use fully connected layers with ELU activation functions.

2. A predictor network f α 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 variables (see details below).

During training, an example x i is passed through the shared layers to generate a dense latent representation h i = s β (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 α in order to obtain the probability vector pi . Then, the prediction of an example x i is obtained by the function

f α,β (x i ) = f α • s β (x i ).
On the other hand, h i is passed through the cVAE. It is first concatenated with pi and then is passed through the encoder of the cVAE and samples a latent vector z i . This latent vector concatenated with pi is passed through the decoder, so as to obtain a reconstructed example xi .

It can be noticed that the cVAE slightly differs from the original cVAE [START_REF] Sohn | Learning structured output representation using deep conditional generative models[END_REF]. Indeed, formally, the encoder of an end-to-end cVAE includes the shared layer, s β . 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.

In addition, we adopt the same preprocessing as Guo et al. [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF] to handle categorical variables. At the input of the network, each categorical variable is encoded with a one-hot. At the output of the cVAE, we add a softmax activation function for each one-hot categorical variable in order to obtain a one-hot encoding format by taking the argmax. Finally, continuous variables are scaled to have all variables in [0, 1].

Loss Function and Training Procedure

The objective of the training is to jointly learn the predictor and the cVAE. Then, the loss to minimize is made of two terms.

The first term is derived from the loss of a cVAE defined in Eq. 2. In our case, the cVAE is conditioned by the probability vector obtained at the output of the predictor. Then we can rewrite the objective function as:

L cV AE (θ, φ, β; x i ) = -λ 3 E q φ (zi|s β (xi), pi) [log(p θ (x i | z i , pi ))] + λ 1 D KL q φ (z i | s β (x i ) , pi ) p(z i ) (3)
λ 1 and λ 3 are weights to control the impact of each term during the training phase.

The second term enables us to learn the predictor. We use cross-entropy as classification loss between the output of the predictor pi = f α • s β (x i ) and the true label y i :

L pred (α, β; x i , y i ) = l k=1 -1 [yi=k] log [f α • s β (x i )] k (4)
where [f α • s β (x i )] k denotes the predicted probability that x i belongs to the k-th class.

Then, the loss function on the training set (D) is a weighted sum of the losses from Eq. 4 and

Eq. 3 as follows:

L (θ, α, β, φ; D) = n i=1 L cV AE (θ, φ, β; x i ) + λ 2 1 n n i=1 L pred (α, β; x i , y i )
As mentioned at the beginning of this section, it is worth noticing that our problem is not to learn to generate counterfactuals. Then, contrary to CounterNet that has divergent objectives to optimize, the minimization of L is a simple optimization problem solved by back-propagation.

Note that λ 1 ,λ 2 ,λ 3 are hyperparameters to tune for training.

Counterfactual Generation

Since our model does not directly produce counterfactuals, some modifications are needed for inference. An example x i is passed through the prediction network to obtain both its predicted probability vector ( pi ) and its dense vector representation (h i ). This dense vector representation (h i ) and the predicted probability vector ( pi ) 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.

Because we want to generate an example with a different predicted class we need a probability vector p c such that the class with maximum probability is different from the one of the prediction, i.e. arg max ( pi ) = arg max (p c ). In a binary-classification problem setup, we decided to use 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 for which 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 pi and to switch the values with the predicted class. For example, if we obtain a probability vector pi = [0.6, 0.3, 0.1] then p c = [0.3, 0.6, 0.1]. An alternative solution would be to let the user select the class for which he/she is interested in having a counterfactual. This vector p c and the dense latent representation z i are passed through the cVAE decoder in order to infer a new predicted class to obtain a counterfactual3 x c . As explained in Section 3.2, 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 c encodes information for the desired class. As such, the decoder generates a new example x c that is similar to x i and that belongs to a different class.

Experiments and Results

Our experiments are organized in four steps. Our main objective is to show that VCNet generates counterfactuals that are both valid (counterfactuals actually belong to another class) and realistic (counterfactuals are close to examples of the same class). In the first set of experiments, we present results of a cVAE on a synthetic dataset to confirm the actual disentanglement of the content and the class. These experiments also aim at providing some intuition about the reason why VCNet works. In the second set of experiments, we compare the results of VCNet with CounterNet, the state-of-the-art algorithm for self-explainable counterfactual generation. The reader interested in the results of more counterfactual generation systems may refer to the original article of Guo et al. [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF]. Our experiments use the same datasets and data preprocessing. In the third experiment, we evaluate the impact of join training on the quality of counterfactuals. We propose a post-hoc version of our framework and compare the results obtained with the jointly trained VCNet. Finally, we present some qualitative experiments on the MNIST dataset. We choose to present experiments on MNIST firstly because it has been widely used in the field of counterfactual generation and, secondly, because it illustrates that VCNet may be applied on different types of data (tabular, images, time series, ...).

The hyperparameters and architectures of the models used in these experiments are detailed in Supplementary material. The code to reproduce the results of this section is also provided in supplementary material.

cVAE for counterfactual generation

Our proposal is based on using a cVAE to generate counterfactuals. It relies on the capability 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.In this experiment, we generate a synthetic dataset of examples in R 8 with three classes. Each class is distributed according to a multidimensional Gaussian distribution (see Figure 2

on the left).

A cVAE, i.e. a couple of an encoder ϕ(x, c) and a decoder ψ(z, c), is trained on a set of 10k examples. The complete code of these experiments is available in supplementary material for the sake of reproducibility.

Figure 2 illustrates the capability of a cVAE to generate realistic examples when changing the class that conditions the decoder. The figure on the left illustrates the dataset. Each colored group of point corresponds to a class. The three figures on the right illustrate datasets that have been generated x = ψ(ϕ(x, c), c ) where x is an example from the test that belongs to class c (origin class). Each figure corresponds to one origin class, the colors of the point correspond to the conditioning class (c ). We observe that all figures look similar. This means that taking ψ(ϕ(x, c), c ) generates an example 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 realistic counterfactuals. Moreover, x is a good counterfactual if it is similar to x. The question is whether z = ϕ(x, c) is a better choice to generate an example ψ(z, c ) than any other example ψ(z , c ) (which also likely belongs to c ). To assess this behavior, we randomly generate 10 latent representations z = z + δ for each x, and compute the Euclidean distance between x = ψ(z , c ) and x. Figure 3 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 δ . When δ = 0, it uses the latent representation of x as input of the cVAE decoder. Intuitively, we expect to have ψ(ϕ(x, c), c ) closer to x than ψ(ϕ(x, c) + δ, c ) and thus, that the higher δ , the higher the mean distance to the original example. The two graphics on the right illustrates 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.

Comparison between VCNet and CounterNet

This section compares the quality of counterfactuals of VCNet against CounterNet. We conduct evaluations on six binary-classification datasets with various properties: Adult [START_REF] Kohavi | UCI machine learning repository: Adult data set[END_REF], HELOC [START_REF] Fico | Explainable machine learning challenge[END_REF], OULAD [START_REF] Kuzilek | Open university learning analytics dataset[END_REF], Breast Cancer Wisconsin [START_REF] Blake | UCI repository of machine learning databases[END_REF], Student performance [START_REF] Cortez | Using data mining to predict secondary school student performance[END_REF] and Titanic [START_REF] Kaggle | Titanic -machine learning from disaster[END_REF]. Some of these datasets contain only numerical variables but some others, such as Adult, contain both numerical and categorical variables. More details about the datasets can be found in the supplementary material of the article.

To evaluate the counterfactual quality, we used the following four metrics that are classical in the literature. Prediction gain: The prediction gain is given by the difference between the predicted probability of the counterfactual x and the predicted probability of the example x, according to the counterfactual class [START_REF] Nemirovsky | CounteRGAN: Generating realistic counterfactuals with residual generative adversarial nets[END_REF].

Gain = [f pred (x )] yi -[f pred (x)] yi
where y i denotes the predicted class for the counterfactual. A higher prediction gain means being more confident in the class change of the counterfactual.

Validity: A counterfactual is valid if it achieves to obtain a different predicted class [START_REF] Ramaravind | Explaining machine learning classifiers through diverse counterfactual explanations[END_REF][START_REF] Oliveira | A framework and benchmarking study for counterfactual generating methods on tabular data[END_REF]. Then:

Validity = 0, if y i = y 0 1, if y i = y 0
where y i denotes the predicted class for the counterfactual and y 0 the predicted class for the example to explain.

Proximity: The proximity is the L 1 distance between an example, x and its counterfactual, x [START_REF] Ramaravind | Explaining machine learning classifiers through diverse counterfactual explanations[END_REF]27].

Proximity = x -x 1 = δ 1
A low value indicates fewer changes of features to apply to the original example to obtain the counterfactual.

Proximity score: This metric is inspired from Laugel et al. [START_REF] Laugel | The dangers of post-hoc interpretability: Unjustified counterfactual explanations[END_REF] to quantify the distance of a counterfactual to examples of the same predicted class:

P s (x ) = d (x , a 0 ) 1 H ( H -1)/2 xi,xj ∈H d (x i , x j )
where d (x , a 0 ) is the Euclidean distance of the counterfactual to the closest example that has the same predicted class (a 0 ) and H is the set of existing examples that have the same predicted class as x . The insight behind this metric is that the counterfactual should be close to an existing example of the same predicted class relative to the rest of the data. Note that to be evaluated, this metric requires a set of m examples X ∈ R m×p .

For each dataset, we choose a random sample of size 25% for counterfactual generation. Then, we compute the mean and standard deviation of each metric for every selected random sample.

Table 1 provides results of VCNet and CounterNet [START_REF] Guo | CounterNet: End-to-end training of counterfactual aware predictions[END_REF]. More information on the reproducibility of CounterNet results is available in Supplementary material. It is worth noting that Table 1 contains additional results for post-hoc VCNet that will be discussed in Section 5.3.

Counterfactual quality: VCNet achieves perfect validity for 4 of the 6 datasets, and a lower validity of respectively 4.5% and 7.5% for the 2 other datasets (Student and Titanic) compared to CounterNet.

As far as prediction gain and proximity score are concerned, VCNet outperforms CounterNet for all the 6 datasets. The higher the prediction gain, the more confidence one can have in the prediction related to the class change of the counterfactual. At the same time, a low proximity score reflects the achievement of counterfactuals that are close to real examples belonging to the same class as predicted for the counterfactual.

For the last evaluated metric that is proximity, we observe that VCNet achieves higher values than CounterNet on 5 of the 6 datasets. A larger proximity value means that the counterfactuals are obtained at the cost of larger changes in the input space.

Predictive accuracy: Both CounterNet and VCNet are self-explainable models, and if the previous results show that VCNet generates better counterfactuals, it can not be at the expense of the prediction accuracy. Thus, Table 1 also presents model accuracies. We observe that VCNet achieved similar performances on 3 of the 6 datasets. On the other hand, the accuracies for the other datasets are lower by 0.4% (HELOC) to 2% (Student), which shows that our method still performs very well in terms of prediction.

Impact of join-training on counterfactual quality

We derived our architecture to a post-hoc version (see Figure 4). Its training procedure is the following: 1) we first train a prediction model. For our comparisons here, it is composed of the concatenation of the shared layers block and the predictor block of VCNet, but in practice it can be any machine learning model that outputs a probability score. Once the model is trained, we obtain a probability vector pi by forwarding an example x i to the model. 2) then we train a cVAE model conditionally to the probability vector ( pi ) output by the predictor learned during Step 1. The cVAE is composed of the same shared layers block than VCNet, but it is not shared with the predictor. We compare VCNet with its post-hoc version (Post-hoc VCNet) in order to study the impact of join-training on counterfactuals. Table 1 provides the results of the post-hoc version compared to those obtained previously with the join-training approach. We observe a drop of validity for every dataset, which justifies that the join-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 changes between an example to explain and its counterfactual. Besides, proximity is higher for 3 datasets (Adult, OULAD, Breast-cancer) and lower by respectively 9%, 1% and 0.8% on the remaining datasets (HELOC, Student, Titanic). Thus, we can argue that this drop of prediction gain does not benefit to closer counterfactuals w. indicates that the join-training approach is not at the cost of a lower accuracy.

Qualitative results on MNIST dataset

We evaluated VCNet on the MNIST dataset4 with metrics suggested in Section 5.2. This experiment illustrates that VCNet is adaptable to several types of data including image datasets. As CounterNet was not applied to image data in the original paper, we do not offer a comparison with this model here. This avoids a poor adaptation of CounterNet and an unfair comparison.

VCNet gives a mean validity of 0.99, a mean prediction gain of 0.98 and an accuracy of 0.98. The counterfactual quality metrics on MNIST show that VCNet is a good model to generate realistic and valid counterfactuals and, at the same time, to make accurate predictions. These results suggest that VCNet has also good capabilities to generate counterfactuals for images, and not only for tabular data. Figure 5 presents some examples to explain (in the first line) and corresponding counterfactuals generated with VCNet (second line). Each example to explain and its counterfactual is complemented by the predicted class, for instance E-7 means an example predicted class 7 and C-3 means a counterfactual predicted class 3. We first notice that each counterfactual "looks like" an example that matches the predicted class. Moreover, we observe that the orientation of the digits is often preserved, for example E-1 is converted in C-7 by keeping the orientation of E-1. C-6 is interesting as it shows that VCNet is able to provide a realistic counterfactual even if the class of the example to explain is not trivial.

Conclusion

In this article, we propose VCNet, a new architecture for self-explainable classification based on counterfactuals examples. Our architecture generates at the same time the decision and a counterfactual that can be used by the analyst to understand the algorithm decision. The first advantage of VCNet is to generate explanations and decisions in a simple feed forward pass of the examples. Contrary to post-hoc counterfactuals explanation, VCNet does not require expensive optimization to generate counterfactuals.

The main contribution of this article is the use of a cVAE as a counterfactual generator in our model. The choice of a cVAE yields realistic counterfactuals and it is simple to train jointly with the prediction model.

We extensively evaluated the quality of the counterfactuals and compared them to CounterNet. We conclude that VCNet generates valid and realistic counterfactuals. The VCNet counterfactuals are realistic in the sense that they are close to existing examples of the same predicted class (VCNet has better proximity scores than CounterNet) and also the result of a higher confidence in the class change (VCNet has better prediction gains than CounterNet).

Finally, VCNet is simple to train because the training procedure is not based on counterfactuals directly, but on the disentanglement of the class and the content of examples by the cVAE. It allows proposing a simple optimisation procedure which makes our approach easier to put in practice. This is illustrated by its successful application to a dataset of images. In addition, it is also assessed in terms of model accuracy. Our experiments show that our join-training approach keeps its competitive prediction performance against CounterNet. A future work is to compare VCNet performances against state-of-the-art post-hoc counterfactuals methods and also to include actionability constraints.

B Implementation Details B.1 VCNet Details

We choose a binary cross entropy loss as the reconstruction error for the cVAE part and a cross entropy loss for the predictor part. We apply a grid search to tune hyperparameters that are specific for each datasets, these values are report in Table 3. We used an Adam optimizer for every dataset. Table 4 describe the model architecture for every dataset. It contains the dimensions for each block of VCNet. For example, with the adult dataset, the shared encoding transforms an example x i of size 29 into a vector h i of size 15. Then the encoder of the cVAE part takes a concatenation of h i and the prediction vector pi to produce a vector of size 16. This vector is transform by the encoder to a lower representation of size 8 and finally a vector of size 5.

B.2 Post-hoc VCNet For Tabular Data

For the post-hoc version of VCNet, the architecture is the same as detailed in Table 4. Nonetheless, hyperparameters for training change.

B.3 Additional Information on CounterNet Reproducibility

We used the CounterNet code that was available at this link https://github.com/bkghz-orange-blue/ CounterNet. For fair comparison, we have computed counterfactuals from available trained models and used the same data processing for VCNet.

Figure 1 :

 1 Figure 1: VCNet architecture is composed of three blocks: Shared layers that transform the input into a latent representation (blue square), a predictor that outputs the prediction (brown square), and a conditional variational autoencoder that acts as a counterfactual generator during testing (red square).

Figure 2 :

 2 Figure 2: Comparison of the examples/counterfactuals distributions for synthetic data. All graphics represent the projection of the examples or counterfacturals on the first two dimensions of the examples space (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 this three rightmost graphics, the same examples have been used to generate counterfactuals with the two other classes. The color/shape of the point represents a class information: the class an example belongs to (graphic on the left) and the class requested for counterfactual generation (3 graphics on the right).

Figure 3 :

 3 Figure 3: Distance between x, an example of class c to explain, and x = ψ(z + δ, c ), a counterfactual for class c perturbed in latent space by δ. Each graphic illustrates this distance with respect to δ 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 δ.

Figure 4 :

 4 Figure 4: Post-hoc version of VCNet. (1) is the prediction model and (2) is the cVAE model.

Figure 5 :

 5 Figure 5: Counterfactuals obtained with VCNet for the MNIST dataset. The top line corresponds to the examples to explain, the bottom to the corresponding counterfactuals.

Table 1 :

 1 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.

	Datasets Metrics		Methods
			VCNet	CounterNet Post-hoc VCNet
	Adult	Validity	1.0	0.99	0.84
		Proximity	7.71 ± 2.11	7.16± 2.13	7.28± 2.23
		Prediction gain	0.76 ± 0.15 0.61±0.17	0.47±0.35
		Proximity score 0.04 ± 0.11 0.31± 0.28	0.06±0.14
		Accuracy	0.83	0.83	0.83
	OULAD Validity	1.0	0.99	0.74
		Proximity	11.66±2.46	11.96±2.40	11.22±2.54
		Prediction gain	0.93±0.12	0.74±0.13	0.66±0.44
		Proximity score 0.38±0.18	0.46±0.16	0.38±0.18
		Accuracy	0.93	0.93	0.93
	HELOC	Validity	1.0	0.99	0.77
		Proximity	5.60±2.11	4.41±1.80	5.09±1.71
		Prediction gain	0.64±0.13	0.56±0.15	0.24±0.25
		Proximity score 0.23±0.21	0.49±0.35	0.40±0.32
		Accuracy	0.71	0.72	0.71
	Student	Validity	0.96	1.0	0.46
		Proximity	19.90±3.21	19.86±2.78	19.68 ±3.03
		Prediction gain	0.86±0.27	0.76±0.05	0.41±0.46
		Proximity score 0.70±0.08	0.73±0.06	0.75±0.08
		Accuracy	0.90	0.92	0.90
	Titanic	Validity	0.92	0.99	0.38
		Proximity	15.43±3.79	15.15±4.05	15.56±5.23
		Prediction gain	0.69±0.31	0.66±0.15	0.26±0.36
		Proximity score 0.71±0.21	0.80± 0.16	1.21±0.26
		Accuracy	0.82	0.83	0.82
	Breast-	Validity	1.0	1.0	0.59
	cancer	Proximity	5.27±1.47	1.51±1.01	7.71±1.67
		Prediction gain	0.95 ± 0.11 0.69±0.15	0.60±0.45
		Proximity score 0.28±0.03	0.72±0.48	0.94± 0.07
		Accuracy	0.96	0.96	0.96

Table 2 :

 2 Datasets details Sandra Wachter, Brent Daniel Mittelstadt, and Chris Russell. Counterfactual explanations without opening the black box: Automated decisions and the GDPR. Harvard Journal of Law and Technology, 31(2):841-887, 2018.We used 6 binary-classification datasets for the comparison of VCNet with CounterNet. Table2describe the size of each dataset as well as the number of categorical and continuous variables.A.2 MNIST DatasetMNIST is composed of 60000 examples in train and 10000 examples in test. We used all of the test set for counterfactual generation.

	Dataset	Size	Continuous	Categorical
	Adult	32,561	2	6
	Student	649	2	14
	Titanic	891	2	24
	HELOC	10,459	21	2
	OULAD	32,593	23	8
	Breast Cancer 569	30	0
	[27] A Dataset Details
	A.1 Tabular Data

  Table 5 and 6 gives training hyperparameters for the cVAE model and prediction model respectively.

For Kingma et al[START_REF] Durk P Kingma | Semisupervised learning with deep generative models[END_REF], what we call the "content" in this paper is denoted the "style". It refers to the writing style of digits in MNIST-like datasets.

By Self-explainable model here we mean that the predictor is constrained by the counterfactual generator during training but the explanation is not directly used to produce model output as in[START_REF] Alvarez | Towards robust interpretability with self-explaining neural networks[END_REF].

Note that the quality of the generated counterfactual depends on the quality of the learned latent space.

http://yann.lecun.com/exdb/mnist/