# CounterNet: End-to-End Training of Prediction Aware Counterfactual
Explanations

Hangzhi Guo  The Pennsylvania State UniversityUniversity ParkPAUSA
<EMAIL_ADDRESS>,  Thanh H. Nguyen  University of OregonEugeneORUSA
<EMAIL_ADDRESS>and  Amulya Yadav  The Pennsylvania State
UniversityUniversity ParkPAUSA<EMAIL_ADDRESS>
(2023)

###### Abstract.

This work presents _CounterNet_ , a novel _end-to-end_ learning framework
which integrates Machine Learning (ML) model training and the generation of
corresponding counterfactual (CF) explanations into a single end-to-end
pipeline. Counterfactual explanations offer a contrastive case, i.e., they
attempt to find the smallest modification to the feature values of an instance
that changes the prediction of the ML model on that instance to a predefined
output. Prior techniques for generating CF explanations suffer from two major
limitations: (i) all of them are _post-hoc methods_ designed for use with
proprietary ML models — as a result, their procedure for generating CF
explanations is uninformed by the training of the ML model, which leads to
misalignment between model predictions and explanations; and (ii) most of them
rely on solving separate time-intensive optimization problems to find CF
explanations for each input data point (which negatively impacts their
runtime). This work makes a novel departure from the prevalent post-hoc
paradigm (of generating CF explanations) by presenting _CounterNet_ , an _end-
to-end_ learning framework which integrates predictive model training and the
generation of counterfactual (CF) explanations into a single pipeline. Unlike
post-hoc methods, CounterNet enables the optimization of the CF explanation
generation only _once_ together with the predictive model. We adopt a block-
wise coordinate descent procedure which helps in effectively training
CounterNet’s network. Our extensive experiments on multiple real-world
datasets show that CounterNet generates high-quality predictions, and
consistently achieves 100% CF validity and low proximity scores (thereby
achieving a well-balanced cost-invalidity trade-off) for any new input
instance, and runs 3X faster than existing state-of-the-art baselines.

Counterfactual Explanation, Algorithmic Recourse, Explainable Artificial
Intelligence, Interpretability

††journalyear: 2023††copyright: acmlicensed††conference: Proceedings of the
29th ACM SIGKDD Conference on Knowledge Discovery and Data Mining; August
6–10, 2023; Long Beach, CA, USA††booktitle: Proceedings of the 29th ACM SIGKDD
Conference on Knowledge Discovery and Data Mining (KDD ’23), August 6–10,
2023, Long Beach, CA, USA††price: 15.00††doi: 10.1145/3580305.3599290††isbn:
979-8-4007-0103-0/23/08††ccs: Computing methodologies Machine learning

##  1\. Introduction

Most prior work in Explainable Artificial Intelligence (XAI) has been focused
on developing techniques to interpret decisions made by black-box machine
learning (ML) models. For example, widely known approaches rely on
attribution-based explanations for interpreting an ML model (e.g., LIME
(Ribeiro et al., 2016) and SHAP (Lundberg and Lee, 2017)). These approaches
can help computer scientists and ML experts understand why (and how) ML models
make certain predictions. However, end users (who generally have no ML
expertise) are often more interested in understanding actionable implications
of the ML model’s predictions (as it relates to them), rather than just
understanding how these models arrive at their predictions. For example, if a
person applies for a loan and gets rejected by a bank’s ML algorithm, he/she
might be more interested in knowing what they need to change in a future loan
application in order to successfully get a loan, rather than understanding how
the bank’s ML algorithm makes all of its decisions.

Thus, from an end-user perspective, counterfactual (CF) explanation techniques
111Counterfactual explanations are closely related to algorithmic recourse
(Ustun et al., 2019) and contrastive explanations (Dhurandhar et al., 2018).
Although these terms are proposed under different contexts, their differences
to CF explanations have been blurred (Verma et al., 2020; Stepin et al.,
2021), i.e. these terms are used interchangeably. Further, the literature on
counterfactual explanations is not directly linked to “counterfactuals” in
causal inference. (Wachter et al., 2017) may be more preferable. A CF
explanation offers a contrastive case — to explain the predictions made by an
ML model on data point $x$, CF explanation methods find a new _counterfactual_
point (or example) $x^{\prime}$, which is close to $x$ but gets a different
(or opposite) prediction from the ML model. CF explanations (or CF examples)
222We use _CF explanations_ and _CF examples_ interchangeably in the rest of
this paper. are useful because they can be used to offer recourse to
vulnerable groups. For example, when an ML model spots a student as being
vulnerable to dropping out from school, CF explanation techniques can suggest
corrective measures to teachers, who can intervene accordingly.

Generating high-quality CF explanations is a challenging problem because of
the need to balance the _cost-invalidity trade-off_ (Rawal et al., 2020)
between: (i) the _invalidity_ , i.e., the probability that a CF example is
invalid, or it does not achieve the desired (or opposite) prediction from the
ML model; and (ii) the _cost of change_ , i.e., the amount of modifications
required to convert input instance $x$ into CF example $x^{\prime}$ (as
measured by the distance between $x$ and $x^{\prime}$). Figure 1 illustrates
this trade-off by showing three different CF examples for an input instance
$x$. If _invalidity_ is ignored (and optimized only for _cost of change_), the
generated CF example can be trivially set to $x$ itself. Conversely, if _cost
of change_ is ignored (and optimized only for _invalidity_), the generated CF
example can be set to $x^{\prime}_{2}$ (or any sufficiently distanced instance
with different labels). More generally, CF examples with high (low)
invalidities usually imply low (high) _cost of change_. To optimally balance
this trade-off, it is critical for CF explanation methods to have access to
the decision boundary of the ML model, without which finding a near-optimal CF
explanation (i.e., $x^{\prime}_{1}$) is difficult. For example, it is
difficult to distinguish between $x^{\prime}_{1}$ (a valid CF example) and
$x^{\prime}_{0}$ (an invalid CF example) without prior knowledge of the
decision boundary.

Figure 1. Illustration of the cost-invalidity trade-off in CF explanations for
binary classification problems. This illustrates that balancing the _cost-
invalidity_ trade-off is key to generating high-quality CF explanations. For
example, both $x_{0}^{\prime}$ and $x_{2}^{\prime}$ do not properly balance
this trade-off (i.e., it is invalid/valid but has low/high cost,
respectively). On the other hand, $x_{1}^{\prime}$ is a near-optimal CF
explanation that balances this trade-off (i.e., it is valid with medium cost).
To optimally balance this trade-off, it is important to have access to the
decision boundary of the ML model.

Existing CF explanation methods suffer from three major limitations. First, to
our best knowledge, all prior methods belong to the _post-hoc_ explanation
paradigm, i.e., they assume a trained black-box ML model as input. This post-
hoc assumption has certain advantages, e.g., post-hoc explanation techniques
are often agnostic to the particulars of the ML model, and hence, they are
generalizable enough to interpret any _third-party_ proprietary ML model.
However, we argue that in many real-world scenarios, the model-agnostic
approach provided by post-hoc CF explanation methods is not desirable. With
the advent of data regulations that enshrine the ” _Right to Explanation_ ”
(e.g., EU-GDPR (Wachter et al., 2017)), service providers are required by law
to communicate both the decision outcome (i.e., the ML model’s prediction) and
its actionable implications (i.e., a CF explanation for this prediction) to an
end-user. In these scenarios, the post-hoc assumption is overly limiting, as
service providers can build specialized CF explanation techniques that can
leverage the knowledge of their particular ML model to generate higher-quality
CF explanations. Second, in the post-hoc CF explanation paradigm, the
optimization procedure that finds CF explanations is completely uninformed by
the ML model training procedure (and the resulting decision boundary).
Consequently, such a post-hoc procedure does not properly balance the cost-
invalidity trade-off (as explained above), causing shortcomings in the quality
of the generated CF explanations (as shown in Section 4). Finally, most CF
explanation methods are very slow — they search for CF examples by solving a
separate time-intensive optimization problem for each input instance (Wachter
et al., 2017; Mothilal et al., 2020; Karimi et al., 2021), which is not viable
in time-constrained environments, e.g., runtime is a critical factor when such
techniques are deployed to end-user facing devices such as smartphones (Zhao
et al., 2018; Arapakis et al., 2021).

Contributions. We make a novel departure from the prevalent post-hoc paradigm
of generating CF explanations by proposing _CounterNet_ , a learning framework
that combines the training of the ML model and the generation of corresponding
CF explanations into a single end-to-end pipeline (i.e., from input to
prediction to explanation). CounterNet has three contributions:

  * •

Unlike post-hoc approaches (where CF explanations are generated after the ML
model is trained), CounterNet uses a (neural network) model-based CF
generation method, enabling the joint training of its CF generator network and
its predictor network. At a high level, CounterNet’s CF generator network
takes as input the learned representations from its predictor network, which
is jointly trained along with the CF generator. This joint training is key to
achieving a well-balanced cost-invalidity trade-off (as we show in Section 4).

  * •

We theoretically analyze CounterNet’s objective function to show two key
challenges in training CounterNet: (i) poor convergence of learning; and (ii)
a lack of robustness against adversarial examples. To remedy these issues, we
propose a novel block-wise coordinate descent procedure.

  * •

We conduct extensive experiments which show that CounterNet generates CF
explanations with $\sim$100% validity and low cost of change ($\sim$9.8%
improvement to baselines), which shows that CounterNet balances the cost-
invalidity trade-off significantly better than baseline approaches. In
addition, this joint-training procedure does not sacrifice CounterNet’s
predictive accuracy and robustness. Finally, CounterNet runs orders of
magnitude ($\sim$3X) faster than baselines.

##  2\. Related Work

Broadly speaking, to ensure that models’ predictions are interpretable to end-
users, two distinct approaches have been proposed in prior work: (i) applying
“glass-box” ML models (e.g., decision trees, rule lists, etc.) that are
intrinsically interpretable (Rudin, 2019; Lou et al., 2013; Caruana et al.,
2015; Lakkaraju et al., 2016); and (ii) applying “black-box” ML models, and
explaining their predictions in a post-hoc manner (Ribeiro et al., 2016; Chen
et al., 2019; Wachter et al., 2017). Here, we focus our discussion on black-
box model approaches, as the interpretability of ”glass-box” models often
comes at the cost of decreased predictive accuracy (Agarwal, 2020), which
limits the real-world usability of these methods.

###  2.1. Explaining Black-Box Models

Attribution Based Explanation. There exists a lot of prior work on explanation
techniques for black-box ML models. One primary approach is to explain the
predictions made by an ML model by highlighting the importance of attributions
for each data instance. For example, Ribeiro et al. (2016) introduced LIME,
which generates local explanations by sampling data near the input instance,
and then uses a linear model to fit this data (which is then used to generate
the explanation via attribution). Similarly, Lundberg and Lee (2017)
introduced SHAP, a unified explanation framework to find locally faithful
explanations by using the Shapley value concept in game theory. Furthermore,
for interpreting predictions made by deep neural networks, gradient-based
saliency maps are often adopted to understand attribution importances
(Selvaraju et al., 2017; Sundararajan et al., 2017; Smilkov et al., 2017).

Case-Based Explanations. Another field in ML model interpretation is on _case-
based explanations_ which conveys model explanations by providing (similar)
data samples to the human end-user (Guidotti et al., 2018; Murdoch et al.,
2019; Molnar et al., 2020). For example, Chen et al. (2019) propose a novel
explanation style, “this looks like that”, to explain image classifications by
identifying similar images (and their regions) in the dataset. Koh and Liang
(2017) adopt influence functions to identify influential data points in the
training set that are used for generating predictions on test instances.
However, both attribution- and case-based methods are of limited utility to
average end-users, who are often more interested in understanding actionable
implications of these model predictions (as it relates to them), rather than
understanding decision rules used by ML models for generating predictions.

Counterfactual Explanations. Our work is most closely related to prior
literature on counterfactual explanation techniques, which focuses on
generating/finding new instances that lead to different predicted outcomes
(Wachter et al., 2017; Verma et al., 2020; Karimi et al., 2020; Stepin et al.,
2021). Counterfactual explanations are preferred by human end-users as these
explanations provide actionable recourse in many domains (Binns et al., 2018;
Miller, 2019; Bhatt et al., 2020). Almost all prior work in this area belongs
to the post-hoc CF explanation paradigm, which we categorize into _non-
parametric_ and _parametric_ methods:

  * •

Non-parametric methods. Non-parametric methods aim to find a counterfactual
explanation without the use of parameterized models. Wachter et al. (2017)
proposed _VanillaCF_ which generates CF explanations by minimizing the
distance between the input instance and the CF example, while pushing the new
prediction towards the desired class. Other algorithms, built on top of
_VanillaCF_ , optimize other aspects, such as recourse cost (Ustun et al.,
2019), fairness (Von Kügelgen et al., 2022), diversity (Mothilal et al.,
2020), closeness to the data manifold (Van Looveren and Klaise, 2019), causal
constraints (Karimi et al., 2021), uncertainty (Schut et al., 2021), and
robustness to model shift (Upadhyay et al., 2021). However, this line of work
is inherently post-hoc and relies on solving a separate optimization problem
for each input instance. Consequently, running them is time-consuming, and
their post-hoc nature leads to poor balancing of the cost-invalidity trade-
off.

  * •

Parametric methods. These methods use parametric models (e.g., a neural
network model) to generate CF explanations. For example, Pawelczyk et al.
(2020); Joshi et al. (2019) generate CF explanations by perturbing the latent
variable of a variational autoencoder (VAE) model. Similarly, Yang et al.
(2021); Singla et al. (2020); Nemirovsky et al. (2022), Mahajan et al. (2019);
Guyomard et al. (2022), and Rodríguez et al. (2021) train generative models
(GAN and VAE, respectively) to produce CF explanations for a trained ML model.
However, these methods are still post-hoc in nature, and thus, they also
suffer from poorly balanced cost-invalidity trade-offs. Contrastingly, we
depart from this post-hoc paradigm, which leads to a greater alignment between
CounterNet’s predictions and CF explanations. Note that Ross et al. (2021)
proposed a recourse-friendly ML model by integrating recourse training during
predictive model training. However, their work does not focus on generating CF
explanations. In contrast, we focus on generating predictions and CF
explanations simultaneously.

##  3\. The Proposed Framework: CounterNet

Unlike prior work, our proposed framework CounterNet relies on a novel
integrated architecture which combines predictive model training and
counterfactual explanation generation into a single optimization framework.
Through this integration, we can simultaneously optimize the accuracy of the
trained predictive model and the quality of the generated counterfactual
explanations.

Formally, given an input instance $x\in\mathbb{R}^{d}$, CounterNet aims to
generate two outputs: (i) the ML prediction component outputs a prediction
$\hat{y}_{x}$ for input instance $x$; and (ii) the CF explanation generation
component produces a CF example $x^{\prime}\in\mathbb{R}^{d}$ as an
explanation for input instance $x$. Ideally, the CF example $x^{\prime}$
should get a different (and often more preferable) prediction
$\hat{y}_{x^{\prime}}$, as compared to the prediction $\hat{y}_{x}$ on the
original input instance $x$ (i.e., $\hat{y}_{x^{\prime}}\neq\hat{y}_{x}$). In
particular, if the desired prediction output is binary-valued $(0,1)$, then
$\hat{y}_{x}$ and $\hat{y}_{x^{\prime}}$ should take on opposite values (i.e.,
$\hat{y}_{x}+\hat{y}_{x^{\prime}}=1$).

Figure 2. CounterNet contains three components: an encoder to transform the
input into a dense latent vector, a predictor network to output the
prediction, and a CF generator to produce explanations.

###  3.1. Network Architecture

Figure 2 illustrates CounterNet’s architecture which includes three
components: (i) an encoder network $h(\cdot)$; (ii) a predictor network
$f(\cdot)$; and (iii) a CF generator network $g(\cdot)$. During training, each
input instance $x\in\mathbb{R}^{d}$ is first passed through the encoder
network to generate a dense latent vector representation of $x$ (denoted by
$z_{x}=h(x)$). Then, this latent representation is passed through both the
predictor network and the CF generator network. The predictor network outputs
a softmax representation of the prediction $\hat{y}_{x}=f(z_{x})$. To generate
CF examples, the CF generator network takes two pieces of information: (i) the
final representation of the predictor network $p_{x}$ (before it is passed
through the softmax layer), and (ii) the latent vector $z_{x}$ (which contains
a dense representation of the input $x$). These two vectors are concatenated
to produce the final latent vector $z^{\prime}_{x}=p_{x}\oplus z_{x}$, which
is passed through the CF generator network to produce a CF example
$x^{\prime}=g(z^{\prime}_{x})$. Note that the final learned representation of
the predictor network $p_{x}$ (for input $x$) reveals useful information about
the decision boundary that is being learned by the predictor network
$f(\cdot)$. Therefore, passing the final representation $p_{x}$ as an input
into the CF generator network implicitly conveys some kind of information
about the decision boundary (that is being learned by the predictor network)
to the CF generation procedure, and this information is leveraged by the CF
generator network to find high-quality CF examples $x^{\prime}$ that achieve a
better balance on the cost-invalidity trade-off (we validate this in Section
4).

Furthermore, to ensure that the CF generator network outputs _valid_ CF
examples (i.e., $\hat{y}_{x}\neq\hat{y}_{x^{\prime}}$), the output of the CF
generator network $x^{\prime}$ is also passed back as an input through the
encoder and predictor networks when training CounterNet. This additional
feedback loop (from the output of CF generator network back into the encoder
and predictor networks) is necessary to optimize the _validity_ of generated
CF examples (intuitively speaking, in order to ensure that the predictions for
input $x$ and CF example $x^{\prime}$ are opposite, the CF example
$x^{\prime}$ generated by the CF generator network needs to be passed back
through the predictor network). As such, we can now train the entire network
in a way such that the predictor network outputs opposite predictions
$\hat{y}_{x}$ and $\hat{y}_{x^{\prime}}$ for the input instance $x$ and the CF
example $x^{\prime}$, respectively. Note that this “ _feedback loop_ ”
connection is only needed during training, and is removed at test time. This
design aims to achieve a better balance on the cost-invalidity tradeoff (as
shown in Section 4).

Design of Encoder, Predictor & CF Generator. All three components in
CounterNet’s architecture consist of a multi-layer perception (MLP)
333CounterNet can work with alternate neuronal blocks, e.g., convolution,
attention, although achieving state-of-the-art training and performance of
these neuronal blocks is a topic for future work (see Appendix H for
details).. The encoder network in CounterNet consists of two feed-forward
layers that down-sample to generate a latent vector $z\in\mathbb{R}^{k}$ (s.t.
$k<d$). The predictor network passes this latent vector $z$ through two feed-
forward layers to produce the predictor representation $p$. Finally, the
predictor network outputs the probability distribution over predictions with a
fully-connected layer followed by a softmax layer. On the other hand, the CF
generator network takes the final latent representation $z^{\prime}=z\oplus p$
as an input, and up-samples to produce CF examples
$x^{\prime}\in\mathbb{R}^{d}$.

Each feed-forward neural network layer inside CounterNet uses LeakyRelu
activation functions (Xu et al., 2015) followed by a dropout layer (Srivastava
et al., 2014) to avoid overfitting. Note that the number of feed-forward
layers, the choice of activation function, etc., were hyperparameters that
were optimized using grid search (See Appendix B.4).

Handling Categorical Features. To handle categorical features, we customize
CounterNet’s architecture for each dataset. First, we transform all
categorical features in each dataset into numeric features via one-hot
encoding. In addition, for each categorical feature, we add a softmax layer
after the final output layer in the CF generator network (Figure 2), which
ensures that the generated CF examples respect the one-hot encoding format (as
the output of the softmax layer will sum up to 1). Finally, we normalize all
continuous features to the $[0,1]$ range before training.

###  3.2. CounterNet Objective Function

We now describe the three-part loss function that is used to train the network
architecture outlined in Figure 2. Each part of our loss function corresponds
to a desirable objective in CounterNet’s output: (i) _predictive accuracy_ \-
the predictor network should output accurate predictions $\hat{y}_{x}$; (ii)
_counterfactual validity_ \- CF examples $x^{\prime}$ produced by the CF
generator network should be valid, i.e., they get opposite predictions from
the predictor network (e.g. $\hat{y}_{x}+\hat{y}_{x^{\prime}}=1$); and (iii)
minimizing cost of change \- minimal modifications should be required to
change input instance $x$ to CF example $x^{\prime}$. Thus, we formulate this
multi-objective minimization problem to optimize the parameter of overall
network $\theta$:

(1)
$\begin{split}\mathcal{L}_{1}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(y_{i}-\hat{y}_{x_{i}})^{2}\\\
\mathcal{L}_{2}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(\hat{y}_{x_{i}}-(1-\hat{y}_{x_{i}^{\prime}}))^{2}\\\
\mathcal{L}_{3}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(x_{i}-x^{\prime}_{i})^{2}\end{split}$

where $N$ denotes the number of instances in our dataset, the prediction loss
$\mathcal{L}_{1}$ denotes the mean squared error (MSE) between the actual and
the predicted labels ($y_{i}$ and $\hat{y}_{x_{i}}$ on instance $x_{i}$,
respectively), which aims to maximize predictive accuracy. Similarly, the
validity loss $\mathcal{L}_{2}$ denotes the MSE between the prediction on
instance $x_{i}$ (i.e., $\hat{y}_{x_{i}}$), and the opposite of the prediction
received by the corresponding CF example $x^{\prime}_{i}$ (i.e.,
$1-\hat{y}_{x^{\prime}_{i}}$). Intuitively, minimizing $\mathcal{L}_{2}$
maximizes the validity of the generated CF example $x^{\prime}_{i}$ by
ensuring that the predictions on $x^{\prime}_{i}$ and $x_{i}$ are different.
Finally, the proximity loss $\mathcal{L}_{3}$ represents the MSE distance
between input instance $x_{i}$ and the CF example $x^{\prime}_{i}$, which aims
to minimize proximity (or cost of change).

Note that we choose MSE loss (instead of the conventional choice of using
cross entropy) for $\mathcal{L}_{1}$ and $\mathcal{L}_{2}$ because our
experimental analysis suggests that this choice of loss functions is crucial
to CounterNet’s superior performance, as replacing $\mathcal{L}_{1}$ and
$\mathcal{L}_{2}$ with binary cross-entropy functions leads to degraded
performance (as we show in ablation experiments in Section 4). In fact, our
choice of MSE based loss functions is supported by similar findings in prior
research, which shows that MSE loss-based training seems to be less sensitive
to randomness in initialization (Hui and Belkin, 2021), more robust to noise
(Ghosh et al., 2017), and less prone to overfitting (Baena et al., 2022) on a
wide variety of learning tasks (as compared to cross-entropy loss).

Given these three loss components, we aim to optimize the parameter $\theta$
of the overall network, which can be formulated as the following minimization
problem:

(2)
$\operatorname*{argmin}_{\mathbf{\theta}}\;\lambda_{1}\cdot\mathcal{L}_{1}+\lambda_{2}\cdot\mathcal{L}_{2}+\lambda_{3}\cdot\mathcal{L}_{3}$

where ($\lambda_{1}$, $\lambda_{2}$, $\lambda_{3}$) are hyper-parameters to
balance the three loss components. Unfortunately, directly solving Eq. 2 as-is
(via gradient descent) leads to poor convergence and degraded adversarial
robustness. In the next section, we theoretically analyze the cause of these
challenges, and propose a blockwise coordinate descent procedure to remedy
these issues.

###  3.3. Training Procedure

The conventional way of solving the optimization problem in Eq. 2 is to use
gradient descent with backpropagation (BP). However, directly optimizing the
objective function (Eq. 2) results in two fundamental issues: (1) _poor
convergence in training_ (shown in Lemma 3.1), and (2) _proneness to
adversarial examples_ (shown in Lemma 3.2).

Issue I: Poor Convergence. Optimizing Eq. 2 as-is via BP leads to poor
convergence. This occurs because Eq. 2 contains two different loss objectives
with divergent gradients, as Lemma 3.1 shows the gradients of
$\mathcal{L}_{1}$ and $\mathcal{L}_{2}$ move in opposite directions.
Consequently, the accumulated gradient direction (i.e., gradient across all
three loss objectives) fluctuates drastically, which leads to poor convergence
of training (as we show in Table 5 in Section 4).

###### Lemma 3.1 (Divergent Gradient Problem).

Let $\mathcal{L}_{1}=\left\|{y}-\hat{y}_{x}\right\|_{2}$, and
$\mathcal{L}_{2}=\left\|\hat{y}_{x}-(1-\hat{y}_{x^{\prime}})\right\|_{2}$,
assuming that ${x}^{\prime}\to{x}$, $0<\hat{y}_{x}<1$, ${y}$ is a binary
label, and $|\hat{y}_{x}-y|<0.5$, then
$\nabla\mathcal{L}_{1}\cdot\nabla\mathcal{L}_{2}<0$. (See proof in Appendix
A.1)

Issue II: Adversarial Examples. Our training procedure should generate high-
quality CF examples $x^{\prime}$ for input instances $x$ without sacrificing
the adversarial robustness of the predictor network. Unfortunately, optimizing
Eq. 2 as-is is at odds with the goal of achieving adversarial robustness (we
show it empirically in Figure 4). Lemma 3.2 diagnoses the cause of poor
adversarial robustness - it shows that optimizing $\mathcal{L}_{2}$ with
respect to the predictive weights $\theta_{f}$ decreases the robustness of the
predictor $f(\cdot)$ (by increasing the Lipschitz constant of $f(\cdot)$,
which leads to an increased vulnerability to adversarial examples as found in
prior research (Hein and Andriushchenko, 2017; Sehwag et al., 2020; Wu et al.,
2021)).

###### Lemma 3.2 (Lipschitz Continuity).

Suppose $f$ is a locally Lipschitz continuous function parameterized by
$\theta_{f}$, then it satisfies
$|f_{\theta_{f}}(x)-f_{\theta_{f}}(x^{\prime})|\leq
K\left\|x-x^{\prime}\right\|_{2}$, where the Lipschitz constant of $f$ is
$K=\operatorname*{sup}_{x^{\prime}\in\mathbb{B}(x,\epsilon)}\\{\|\nabla
f_{\theta_{f}}(x^{\prime})\|_{2}\\}$. Let
$\mathcal{L}_{2}=\left\|f_{\theta_{f}}(x)-(1-f_{\theta_{f}}(x^{\prime})\right\|_{2}$,
assuming that $x^{\prime}\to x$, $0<f_{\theta_{f}}(\cdot)<1$,
$f_{\theta_{f}}(x)\to y$, and $y$ is a binary label, then minimizing
$\mathcal{L}_{2}$ w.r.t. $\theta_{f}$ increases the Lipschitz constant $K$.
(See proof in Appendix A.2)

Training Procedure. We propose a block-wise coordinate descent procedure to
remedy these two issues. This block-wise coordinate descent procedure divides
the problem of optimizing Eq. 2 into two parts: (i) optimizing predictive
accuracy (primarily influenced by $\mathcal{L}_{1}$); and (ii) optimizing the
validity and proximity of CF generation (primarily influenced by
$\mathcal{L}_{2}$ and $\mathcal{L}_{3}$). Specifically, for each mini-batch of
$m$ data points $\\{x^{(i)},y^{(i)}\\}^{m}$, we apply two gradient updates to
the network through backpropagation. For the first update, we compute
$\theta^{(1)}=\theta^{(0)}-\nabla_{\theta^{(0)}}(\lambda_{1}\cdot\mathcal{L}_{1})$,
and for the second update, we compute
$\theta^{(2)}_{g}=\theta^{(1)}_{g}-\nabla_{\theta^{(1)}_{g}}(\mathcal{\lambda}_{2}\cdot\mathcal{L}_{2}+\lambda_{3}\cdot\mathcal{L}_{3})$.

This block-wise coordinate descent procedure mitigates the aforementioned
issues as follows: (1) it _handles poor convergence in training_ by ensuring
that the gradient of $\mathcal{L}_{1}$ and $\mathcal{L}_{2}$ are calculated
separately. Because $\nabla\mathcal{L}_{1}$ and $\nabla\mathcal{L}_{2}$ are
back-propagated to the network at different stages, CounterNet does not suffer
from the divergent gradient problem (Lemma 3.1), and this procedure leads to
significantly better convergence of training. (2) Moreover, it _improves
adversarial robustness_ of our predictor network. During the second stage of
our coordinate descent procedure (when we optimize for
$(\lambda_{2}\cdot\mathcal{L}_{2}+\lambda_{3}\cdot\mathcal{L}_{3})$), we only
update the weights in the CF generator $\theta_{g}$ and freeze gradient
updates in both the encoder $\theta_{h}$ and predictor $\theta_{f}$ networks.
As shown in Lemma 3.2, when optimizing the predictor and CF generator
simultaneously, it will unwantedly increase the Lipschitz constant of the
predictor network. By separately updating the gradient of the encoder,
predictor, and CF generator, it ensures that the Lipschitz constant of the
predictor network does not increase, which in turn, improves the adversarial
robustness of the predictor network.

##  4\. Experimental Evaluation

We primarily focus our evaluation on heterogeneous tabular datasets for binary
classification problems (which is the most common and reasonable setting for
CF explanations (Verma et al., 2020; Stepin et al., 2021)). However,
CounterNet can be applied to multi-class classification settings, and it can
also be adapted to work with other modalities of data.

Baselines. We compare CounterNet against eight state-of-the-art CF explanation
methods:

  * •

_VanillaCF_ (Wachter et al., 2017) is a non-parametric post-hoc method which
generates CF examples by optimizing CF validity and proximity;

  * •

_DiverseCF_ (Mothilal et al., 2020), _ProtoCF_ (Van Looveren and Klaise,
2019), and _UncertainCF_ (Schut et al., 2021) are non-parametric methods which
optimize for diversity, consistency with prototypes, and uncertainty,
respectively;

  * •

_VAE-CF_ (Mahajan et al., 2019), _CounteRGAN_ (Nemirovsky et al., 2022), _C-
CHVAE_ (Pawelczyk et al., 2020), and _VCNet_ (Guyomard et al., 2022) are
parametric methods which use generative models (i.e., VAE or GAN) to generate
CF examples 444Note that Yang et al. (2021) propose another parametric post-
hoc method, but we exclude it in our baseline comparison because it achieves
comparable performance to C-CHVAE on benchmarked datasets (as reported in
(Yang et al., 2021))..

Unlike CounterNet, all of the post-hoc methods require a trained predictive
model as input. Thus, for each dataset, we train a neural network model and
use it as the target predictive model for all baselines. For a fair
comparison, we only keep the encoder and predictor network inside CounterNet’s
architecture (Figure 2), and optimize them for predictive accuracy alone
(i.e., $\mathcal{L}_{1}$). This combination of encoder and predictor networks
is then used as the black-box predictive model for our baselines.

Datasets. To remain consistent with prior work on CF explanations (Verma et
al., 2020), we evaluate CounterNet on four benchmarked real-world binary
classification datasets. Table 1 summarizes these four datasets.

  * •

_Adult_ (Kohavi and Becker, 1996) which aims to predict whether an
individual’s income reaches $50K (`Y=1`) or not (`Y=0`) using demographic
data;

  * •

_Credit_ (Yeh and Lien, 2009) which uses historical payments to predict the
default of payment (`Y=1`) or not (`Y=0`);

  * •

_HELOC_ (FICO, 2018) which predicts if a homeowner qualifies for a line of
credit (`Y=1`) or not (`Y=0`);

  * •

_OULAD_ (Kuzilek et al., 2017): which predicts whether MOOC students drop out
(`Y=1`) or not (`Y=0`), based on their online learning logs.

Table 1. Summary of Datasets used for Evaluation. Dataset | Size | #Continuous | #Categorical
---|---|---|---
Adult | 32,561 | 2 | 6
Credit | 30,000 | 20 | 3
HELOC | 10,459 | 21 | 2
OULAD | 32,593 | 23 | 8

Evaluation Metrics. For each input $x$, CF explanation methods generate two
outputs: (i) a prediction $\hat{y}_{x}$; and (ii) a CF example $x^{\prime}$.
We evaluate the quality of both these outputs using separate metrics. For
evaluating predictions, we use _predictive accuracy_ (as all four datasets are
fairly class-balanced). High _predictive accuracy_ is desirable as we do not
want to provide explanations for incorrect predictions from ML models.

For evaluating CF examples, we use five widely used metrics from prior
literature:

  * •

Validity is defined as the fraction of input instances on which CF explanation
techniques output valid counterfactual examples, i.e., the fraction of input
data points for which $\hat{y}_{x}+\hat{y}_{x^{\prime}}=1$. High validity is
desirable, as it implies the technique’s effectiveness at creating valid CF
examples. This is a widely-used metric in prior CF explanation literature
(Mothilal et al., 2020; Mahajan et al., 2019; Upadhyay et al., 2021).

  * •

_Proximity_ is defined as the $L_{1}$ norm distance between $x$ and
$x^{\prime}$ divided by the number of features. The _proximity_ metric
measures the quality of CF examples as it is desirable to have fewer
modifications in the input space to convert it into a valid CF example
(Wachter et al., 2017; Mothilal et al., 2020; Mahajan et al., 2019).

  * •

_Sparsity_ measures the number of feature changes (i.e., $L_{0}$ norm) between
$x$ and $x^{\prime}$. This metric stems from the motivation of sparse
explanations, i.e., CF explanations are more interpretable to end-users if
they require changes to fewer features (Wachter et al., 2017; Miller, 2019;
Poursabzi-Sangdeh et al., 2021). Both _proximity_ and _sparsity_ serve as
proxies for measuring the _cost of change_ of our CF explanation approach, as
it is desirable to have fewer modifications in the input space to convert it
into a valid CF example.

  * •

_Manifold distance_ is the $L_{1}$ distance to the $k$-nearest neighbor of
$x^{\prime}$ (we use $k=1$ to remain consistent with prior work (Verma et al.,
2022)). Low _manifold distance_ is desirable as closeness to the training data
manifold indicates realistic CF explanations (Van Looveren and Klaise, 2019;
Verma et al., 2022).

  * •

Finally, we also report the _runtime_ for generating CF examples.

###  4.1. Evaluation of CounterNet Performance

Table 2. Predictive accuracy of CounterNet. CounterNet achieves comparable predictive performance as base models. Dataset | Base Model | CounterNet
---|---|---
Adult | 0.831 | 0.828
Credit | 0.813 | 0.819
HELOC | 0.717 | 0.716
OULAD | 0.934 | 0.929

Predictive Accuracy. Table 2 compares CounterNet’s predictive accuracy against
the base prediction model used by baselines. This table shows that CounterNet
exhibits highly competitive predictive performance - it achieves marginally
better accuracy on the Credit dataset (row 2), and achieves marginally lower
accuracy on the remaining datasets. Across all four datasets, the difference
between the predictive accuracy of CounterNet and the base model is $\sim$
0.1%. Thus, the potential benefits achieved by CounterNet’s joint training of
predictor and CF generator networks do not come at a cost of reduced
predictive accuracy.

Table 3. Evaluation of CF explanations: CounterNet achieves perfect validity (i.e., Val.), and it incurs comparable (or lesser) cost of changes (i.e., Prox, Spar.) than baseline methods, with comparable manifold distance (i.e., Man.). Bold and italicized cells highlight the best and second-best performing methods, respectively. Method | Adult | Credit | HELOC | OULAD
---|---|---|---|---
| Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man.
VanillaCF | 0.76 | .202 | .556 | 0.57 | 0.92 | .123 | .841 | 0.59 | 1.00 | .154 | .883 | 0.71 | 1.00 | .101 | .762 | 1.30
DiverseCF | 0.54 | .276 | .662 | 1.16 | 1.00 | .264 | .918 | 1.68 | 0.90 | .149 | .434 | 1.34 | 0.68 | .117 | .565 | 2.51
ProtoCF | 0.59 | .250 | .648 | 0.62 | 0.92 | .197 | .855 | 0.82 | 1.00 | .168 | .805 | 0.56 | 1.00 | .107 | .754 | 1.46
UncertainCF | 0.36 | .307 | .713 | 1.23 | 0.62 | .155 | .217 | 0.80 | 0.55 | .130 | .161 | 0.94 | 0.59 | .098 | .734 | 2.23
C-CHVAE | 1.00 | .281 | .721 | 0.94 | 1.00 | .357 | .853 | 1.85 | 1.00 | .155 | .790 | 0.81 | 1.00 | .110 | .797 | 2.11
VAE-CF | 0.66 | .287 | .734 | 1.03 | 0.13 | .201 | .756 | 0.62 | 1.00 | .221 | .893 | 1.04 | 1.00 | .115 | .586 | 2.19
CounteRGAN | 0.78 | .327 | .698 | 2.21 | 0.39 | .260 | .687 | 2.03 | 1.00 | .271 | .509 | 2.23 | 0.43 | .087 | .587 | 2.15
VCNet | 1.00 | .291 | .755 | 0.19 | 1.00 | .162 | .939 | 0.16 | 1.00 | .154 | .786 | 0.39 | 1.00 | .095 | .903 | 1.33
CounterNet | 1.00 | .196 | .644 | 0.64 | 1.00 | .132 | .912 | 0.56 | 1.00 | .125 | .740 | 0.56 | 1.00 | .075 | .725 | 0.87

Counterfactual Validity. Table 3 compares the validity achieved by CounterNet
and baselines on all four datasets. We observe that CounterNet, C-CHVAE, and
VCNet are the only three methods with 100% validity on all datasets. With
respect to the other baselines, CounterNet achieves 8% and 12.3% higher
average validity (across all datasets) than VanillaCF and ProtoCF (our next
best baselines).

Figure 3. Illustration of the cost-invalidity trade-off across all four
datasets. Methods at the bottom left are preferable. On average, CounterNet
achieves the lowest invalidity and proximity (i.e., cost) across all four
datasets.

Proximity & Sparsity. Table 3 compares the proximity/sparsity achieved by all
CF explanation methods. CounterNet achieves at least 3% better proximity than
all other baselines on three out of four datasets (Adult, HELOC, and OULAD),
and it is the second best performing model on the Credit dataset (where it
achieves 7.3% poorer proximity than VanillaCF). In terms of sparsity,
CounterNet performs reasonably well; it is the second-best-performing model on
the Adult and HELOC datasets even though CounterNet does not explicitly
optimize for sparsity. _This shows that CounterNet outperforms all baselines
by generating CF examples with the highest validity and best proximity
scores_.

Cost-Invalidity Trade-off. We illustrate the cost-invalidity trade-off (Rawal
et al., 2020) for all methods. Figure 3 shows this trade-off by plotting their
average proximity/invalidity values. This figure shows that CounterNet lies on
the bottom left of this figure — it consistently achieves the lowest
invalidity and cost on all four datasets. In comparison, VCNet achieves the
same perfect validity, but at the expense of $\sim$34% higher cost than
CounterNet. Similarly, C-CHVAE demands $\sim$71% higher cost than CounterNet
to achieve perfect validity. On the other hand, VanillaCF achieves a
comparable cost to CounterNet (10% higher cost), but it achieves lower
validity by 8%. This result highlights that CounterNet’s joint training
enables it to properly balance the cost-invalidity trade-off.

Manifold Distance. Table 3 shows that CounterNet achieves the second-lowest
manifold distance on average (right below VCNet, which explicitly optimizes
for data manifold). In particular, CounterNet achieves the lowest manifold
distance in _OULAD_ , and is ranked second in _Credit_ and _HELOC_. This
result shows that CounterNet generates highly realistic CF examples that
adhere to the data manifold, despite not optimizing for the manifold distance.

Table 4. Runtime comparison (in milliseconds). CounterNet runs _faster_ than all of the baselines in all four datasets. Method | Adult | Credit | HELOC | OULAD
---|---|---|---|---
VanillaCF | 1432.09 | 1358.26 | 1340.42 | 1705.93
DiverseCF | 4685.39 | 3898.43 | 3921.72 | 5478.17
ProtoCF | 2348.21 | 2056.01 | 1956.71 | 2823.29
UncertainCF | 379.95 | 60.80 | 7.91 | 6.81
C-CHVAE | 3.28 | 568.28 | 2.68 | 4.79
VAE-CF | 1.72 | 1.28 | 1.48 | 1.84
CounteRGAN | 1.96 | 1.77 | 1.59 | 2.40
VCNet | 1.39 | 1.23 | 1.13 | 1.81
CounterNet | 0.64 | 0.39 | 0.44 | 0.79

Running Time. Table 4 shows the average runtime (in milliseconds) of different
methods to generate a CF example for a single data point. CounterNet
outperforms all eight baselines in every dataset. In particular, CounterNet
generates CF examples $\sim$3X faster than VAE-CF, CouneRGAN, and VCNet,
$\sim$5X faster than C-CHVAE, and three orders of magnitude (¿1000X) faster
than other baselines. This result shows that CounterNet is more usable for
adoption in time-constrained environments.

Table 5. Ablation analysis of CounterNet. Each ablation leads to degraded performance, which in turn, showcases the significance of various design choices in CounterNet. Ablation | Adult | Credit | HELOC | OULAD
---|---|---|---|---
| Val. | Prox. | Val. | Prox. | Val. | Prox. | Val. | Prox.
CounterNet-BCE | 0.86 | .238 | 0.96 | .210 | 0.86 | .238 | 0.95 | .101
CounterNet-SingleBP | 0.64 | .248 | 0.92 | .251 | 0.93 | .206 | 0.94 | .110
CounterNet-Separate | 0.96 | .257 | 0.99 | .265 | 0.91 | .161 | 0.94 | .097
CounterNet-NoPass-$p_{x}$ | 0.97 | .256 | 0.99 | .339 | 0.98 | .147 | 0.98 | .101
CounterNet-Posthoc | 1.00 | .276 | 1.00 | .247 | 1.00 | .153 | 0.99 | .099
CounterNet | 1.00 | .196 | 1.00 | .132 | 1.00 | .125 | 1.00 | .075

###  4.2. Further Analysis

Ablation Analysis. We analyze five ablations of CounterNet to underscore the
design choices inside CounterNet. First, we accentuate the importance of the
MSE loss functions used to optimize CounterNet (Eq. 2) by replacing the MSE
based $\mathcal{L}_{1}$ and $\mathcal{L}_{2}$ loss in Eq. 2 with binary cross
entropy loss (CounterNet-BCE). Second, we underscore the importance of
CounterNet’s two-stage coordinate descent procedure by using conventional one-
step BP optimization to train CounterNet instead (CounterNet-SingleBP). In
addition, we validate CounterNet’s architecture design by experimenting two
alternative designs: (i) we use a _separate_ predictor
$f:\mathcal{X}\to\mathcal{Y}$ and CF generator
$g:\mathcal{X}\to\mathcal{X}^{\prime}$, such that $f$ and $g$ share no
identical components (unlike in CounterNet, where $z_{x}$ are shared with both
$f$ and $g$; _CounterNet-Separate_); and (ii) we highlight the design choice
of passing $p_{x}$ to the CF generator by excluding passing $p_{x}$
(_CounterNet-NoPass- $p_{x}$_). Finally, we highlight the importance of the
joint-training of predictor and CF generator in CounterNet by training the
CounterNet in a post-hoc fashion (_CounterNet-Posthoc_), i.e., we first train
the predictor on the _entire_ training dataset, and optimize CF generator
while the trained predictor is frozen.

Table 5 compares the validity and proximity achieved by CounterNet and five
ablations. Importantly, each ablation leads to degraded performance as
compared to CounterNet, which demonstrates the importance of CounterNet’s
different design choices. _CounterNet-BCE_ and _CounterNet-SingleBP_ perform
poorly in comparison, which illustrates the importance of the MSE-based loss
function and block-wise coordinate descent procedure. Similarly, _CounterNet-
Separate_ and _CounterNet-NoPass- $p_{x}$_ achieve degraded validity and
proximity, which highlight the importance of CounterNet’s architecture design.
Finally, _CounterNet-Posthoc_ achieves comparable validity as CounterNet, but
fails to match the performance of proximity. This result demonstrates the
importance of the joint-training procedure of CounterNet in optimally
balancing the cost-invalidity trade-off.

Figure 4. Robustness of the predictor $f(\cdot)$ under the PGD attack on the
adult dataset (higher is better). CounterNet reaches the upper bound of
robustness (i.e., comparable to the base model). In comparison, _CounterNet-
NoFreeze_ achieves poorer robustness than CounterNet. This result illustrates
that, by freezing the encoder and predictor network, CounterNet suffers little
from adversarial robustness.

Adversarial Robustness. Next, we illustrate that CounterNet does not suffer
from decreased robustness of the predictor network resulting from optimizing
for the validity loss $\mathcal{L}_{2}$ (as shown in Lemma 3.2). We compare
the robustness of CounterNet’s predictor network $f(\cdot)$ against two
baselines: (i) the base predictive model described in Table 2; and (ii)
CounterNet without freezing the predictor at the second stage of our
coordinate descent optimization (_CounterNet-NoFreeze_).

Figure 4 illustrates the perturbation stability (Wu et al., 2021) of all three
CounterNet variants against adversarial examples (generated via projected
gradient descent (Madry et al., 2018)). CounterNet achieves comparable
perturbation stability as the base model, which indicates that CounterNet
reaches its robustness upper bound (i.e., the robustness of the base model).
Moreover, the empirical results in Figure 4 confirm Lemma 3.2 as _CounterNet-
NoFreeze_ achieves significantly poorer stability. We observe similar patterns
with different attack methods on other datasets (see Appendix C.1). These
results show that by freezing the predictor and encoder networks at the second
stage of our coordinate descent procedure, CounterNet suffers less from the
vulnerability issue created by the adversarial examples.

Table 6. Impact of the immutable feature constraints in CounterNet. CounterNet generates feasible CF explanations _without_ sacrificing validity and proximity. Dataset |  |  Val. Diff.
---
|  Prox. Diff.
---
Adult | 0.0 | .009
Credit | 0.0 | .005
OULAD | 0.0 | .004

Feasibility of CF Explanations. Finally, we show how CounterNet’s training
procedure can be adapted to ensure that the generated CF examples are
feasible. In particular, we attempt to use projected gradient descent during
the training of CounterNet and enforce hard constraints during the inference
stage in order to ensure that the generated CF examples satisfy immutable
feature constraints (e.g., gender should remain unchanged). At the training
stage, a CF example $x^{\prime}$ is first generated from $g(\cdot)$, and is
projected into its feasible space (i.e.,
$x^{\prime\prime}=\mathbbm{P}(x^{\prime})$). Next, we optimize CounterNet over
the prediction $\hat{y}_{x}$ and its projected CF example $x^{\prime\prime}$
(via our block-wise coordinate descent procedure). During inference, we
enforce that the set of immutable features remains unchanged.

Table 6 shows that enforcing immutable features (via projected gradient
descent) does not negatively impact the validity and proximity of the CF
examples. This result shows that CounterNet can produce CF examples that
respect feasibility constraints.

Figure 5. Training time of base MLP model and CounterNet for each epoch (in
seconds). The result is obtained on an NVIDIA V100 GPU machine with batch size
set to 128. CounterNet takes roughly 3X training time than the base model.

Training Time. Figure 5 compares the training time for the base model
(described in Table 9) and CounterNet, measured in seconds per epoch.
CounterNet requires approximately 3X longer to train when compared to the base
model, which is only optimized for prediction accuracy.

Note that although training time is a useful metric for evaluating the speed
of the model, this cost only occurs once, making it a secondary metric in
terms of evaluating the overall performance of the model. A more critical
metric to consider is the inference time for each data point, as a slow
inference time directly impacts the usability and deployability of CF
explanation techniques (inference time is shown as _runtime_ in Table 4).

##  5\. Discussion

Although our experiments exhibit CounterNet’s superior performance as compared
to post-hoc baselines, these two methods have somewhat different motivations.
While post-hoc methods are designed for generating CF explanations for trained
black-box ML models (whose training data and model weights might not be
available), CounterNet is most suitable for scenarios when the ML model
developers aspire to build prediction and explanation modules from scratch,
where the training data can be exploited to optimize the generation of CF
examples. Due to tighter government regulations (e.g., EU General Data
Protection Regulation which enforces the “right to explanation” (Wachter et
al., 2017)), it is becoming increasingly important for service providers to
provide explanations for any algorithm-mediated decisions. We anticipate
CounterNet to be valuable for service providers who wish to comply with GDPR-
style regulations without sacrificing their operational effectiveness (e.g.,
reduced predictive power). Importantly, CounterNet can still be used to
interpret proprietary ML models by forcing its predictor network to mimic that
proprietary model.

CounterNet has two limitations. (i) First, CounterNet does not consider other
desirable aspects in CF explanations, such as diversity (Mothilal et al.,
2020), recourse cost (Ustun et al., 2019), and causality (Karimi et al.,
2021). Further research is needed to address these issues. (ii) Secondly,
although CounterNet is suitable for real-time deployment given its superior
performance in its highly aligned CF explanations and speed, one must be aware
of the possible negative impacts of its CF explanations to human end-users. It
is important to ensure that generated CF examples do not amplify or provide
support to the narratives resulting from pre-existing race-based and gender-
based societal inequities (among others). One short-term workaround is to have
humans in the loop. We can provide CounterNet’s explanations as a decision-aid
to a well-trained human official, who is in charge of communicating the
decisions of ML models to human end-users in a respectful and humane manner.
In the long run, further qualitative and quantitative studies are needed to
understand the social impacts of CounterNet.

##  6\. Conclusion

This paper proposes _CounterNet_ , a novel learning framework that integrates
predictive model training and CF example generation into a single _end-to-end_
pipeline. Unlike prior work, CounterNet ensures that the objectives of
predictive model training and CF example generation are closely aligned. We
adopt a block-wise coordinate descent procedure to effectively train
CounterNet. Experimental results show that CounterNet outperforms state-of-
the-art baselines in validity, proximity, and runtime, and is highly
competitive in predictive accuracy, sparsity, and closeness to data manifold.
In a nutshell, this paper represents a first step towards developing end-to-
end counterfactual explanation systems.

## References

  * (1)
  * Agarwal (2020) Sushant Agarwal. 2020\.  Trade-Offs between Fairness and Interpretability in Machine Learning.  _Proc. 3rd International Workshop on AI for Social Good_ (2020).
  * Arapakis et al. (2021) Ioannis Arapakis, Souneil Park, and Martin Pielot. 2021\.  Impact of Response Latency on User Behaviour in Mobile Web Search. In _Proceedings of the 2021 Conference on Human Information Interaction and Retrieval_. 279–283.
  * Asuncion and Newman (2007) Arthur Asuncion and David Newman. 2007.  UCI machine learning repository.
  * Baena et al. (2022) Raphael Baena, Lucas Drumetz, and Vincent Gripon. 2022\.  Preserving Fine-Grain Feature Information in Classification via Entropic Regularization.  _arXiv preprint arXiv:2208.03684_ (2022).
  * Bhatt et al. (2020) Umang Bhatt, Alice Xiang, Shubham Sharma, Adrian Weller, Ankur Taly, Yunhan Jia, Joydeep Ghosh, Ruchir Puri, José M. F. Moura, and Peter Eckersley. 2020.  Explainable Machine Learning in Deployment. In _Proceedings of the 2020 Conference on Fairness, Accountability, and Transparency_ (Barcelona, Spain) _(FAT* ’20)_. Association for Computing Machinery, New York, NY, USA, 648–657.  https://doi.org/10.1145/3351095.3375624
  * Binns et al. (2018) Reuben Binns, Max Van Kleek, Michael Veale, Ulrik Lyngs, Jun Zhao, and Nigel Shadbolt. 2018\.  ’It’s Reducing a Human Being to a Percentage’ Perceptions of Justice in Algorithmic Decisions. In _Proceedings of the 2018 Chi conference on human factors in computing systems_. 1–14.
  * Blackard (1998) Jock Blackard. 1998\.  Covertype.  UCI Machine Learning Repository.
  * Blake (1998) Catherine Blake. 1998\.  UCI repository of machine learning databases.  _http://www. ics. uci. edu/~ mlearn/MLRepository. html_ (1998).
  * Caruana et al. (2015) Rich Caruana, Yin Lou, Johannes Gehrke, Paul Koch, Marc Sturm, and Noemie Elhadad. 2015\.  Intelligible models for healthcare: Predicting pneumonia risk and hospital 30-day readmission. In _Proceedings of the 21th ACM SIGKDD international conference on knowledge discovery and data mining_. 1721–1730.
  * Chen et al. (2019) Chaofan Chen, Oscar Li, Daniel Tao, Alina Barnett, Cynthia Rudin, and Jonathan K Su. 2019\.  This looks like that: deep learning for interpretable image recognition. In _Advances in neural information processing systems_. 8930–8941.
  * Cortez and Silva (2008) Paulo Cortez and Alice Maria Gonçalves Silva. 2008.  Using data mining to predict secondary school student performance.  (2008).
  * Dhurandhar et al. (2018) Amit Dhurandhar, Pin-Yu Chen, Ronny Luss, Chun-Chen Tu, Paishun Ting, Karthikeyan Shanmugam, and Payel Das. 2018.  Explanations Based on the Missing: Towards Contrastive Explanations with Pertinent Negatives. In _Proceedings of the 32nd International Conference on Neural Information Processing Systems_ (Montréal, Canada) _(NIPS’18)_. Curran Associates Inc., Red Hook, NY, USA, 590–601.
  * FICO (2018) FICO. 2018.  Explainable Machine Learning Challenge.  https://community.fico.com/s/explainable-machine-learning-challenge.
  * Ghosh et al. (2017) Aritra Ghosh, Himanshu Kumar, and P Shanti Sastry. 2017\.  Robust loss functions under label noise for deep neural networks. In _Proceedings of the AAAI conference on artificial intelligence_ , Vol. 31.
  * Goodfellow et al. (2015) Ian J. Goodfellow, Jonathon Shlens, and Christian Szegedy. 2015.  Explaining and Harnessing Adversarial Examples. In _3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings_ , Yoshua Bengio and Yann LeCun (Eds.).  http://arxiv.org/abs/1412.6572
  * Guidotti et al. (2018) Riccardo Guidotti, Anna Monreale, Salvatore Ruggieri, Franco Turini, Fosca Giannotti, and Dino Pedreschi. 2018.  A survey of methods for explaining black box models.  _ACM computing surveys (CSUR)_ 51, 5 (2018), 1–42.
  * Guyomard et al. (2022) Victor Guyomard, Françoise Fessant, Thomas Guyet, Tassadit Bouadi, and Alexandre Termier. 2022.  VCNet: A self-explaining model for realistic counterfactual generation. In _Proceedings of the European Conference on Machine Learning and Principles and Practice of Knowledge Discovery in Databases (ECML PKDD)_.
  * He et al. (2016) Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. 2016\.  Deep residual learning for image recognition. In _Proceedings of the IEEE conference on computer vision and pattern recognition_. 770–778.
  * Hein and Andriushchenko (2017) Matthias Hein and Maksym Andriushchenko. 2017.  Formal guarantees on the robustness of a classifier against adversarial manipulation.  _Advances in neural information processing systems_ 30 (2017).
  * Hui and Belkin (2021) Like Hui and Mikhail Belkin. 2021.  Evaluation of Neural Architectures Trained with Square Loss vs Cross-Entropy in Classification Tasks. In _International Conference on Learning Representations_.  https://openreview.net/forum?id=hsFN92eQEla
  * Joshi et al. (2019) Shalmali Joshi, Oluwasanmi Koyejo, Warut Vijitbenjaronk, Been Kim, and Joydeep Ghosh. 2019.  Towards realistic individual recourse and actionable explanations in black-box decision making systems.  _arXiv preprint arXiv:1907.09615_ (2019).
  * Kaggle (2018) Kaggle. 2018.  Titanic - Machine Learning from Disaster.  https://www.kaggle.com/c/titanic/overview.
  * Karimi et al. (2020) Amir-Hossein Karimi, Gilles Barthe, Bernhard Schölkopf, and Isabel Valera. 2020.  A survey of algorithmic recourse: definitions, formulations, solutions, and prospects.  _arXiv preprint arXiv:2010.04050_ (2020).
  * Karimi et al. (2021) Amir-Hossein Karimi, Bernhard Schölkopf, and Isabel Valera. 2021.  Algorithmic recourse: from counterfactual explanations to interventions. In _Proceedings of the 2021 ACM Conference on Fairness, Accountability, and Transparency_. 353–362.
  * Koh and Liang (2017) Pang Wei Koh and Percy Liang. 2017.  Understanding black-box predictions via influence functions. In _International Conference on Machine Learning_. PMLR, 1885–1894.
  * Kohavi and Becker (1996) R Kohavi and B Becker. 1996\.  UCI Machine Learning Repository: Adult Data Set.
  * Kuzilek et al. (2017) Jakub Kuzilek, Martin Hlosta, and Zdenek Zdrahal. 2017\.  Open university learning analytics dataset.  _Scientific data_ 4 (2017), 170171.
  * Lakkaraju et al. (2016) Himabindu Lakkaraju, Stephen H Bach, and Jure Leskovec. 2016\.  Interpretable decision sets: A joint framework for description and prediction. In _Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining_. 1675–1684.
  * Lou et al. (2013) Yin Lou, Rich Caruana, Johannes Gehrke, and Giles Hooker. 2013\.  Accurate intelligible models with pairwise interactions. In _Proceedings of the 19th ACM SIGKDD international conference on Knowledge discovery and data mining_. 623–631.
  * Lundberg and Lee (2017) Scott M Lundberg and Su-In Lee. 2017.  A unified approach to interpreting model predictions. In _Advances in neural information processing systems_. 4765–4774.
  * Madry et al. (2018) Aleksander Madry, Aleksandar Makelov, Ludwig Schmidt, Dimitris Tsipras, and Adrian Vladu. 2018\.  Towards Deep Learning Models Resistant to Adversarial Attacks. In _6th International Conference on Learning Representations, ICLR 2018, Vancouver, BC, Canada, April 30 - May 3, 2018, Conference Track Proceedings_. OpenReview.net.  https://openreview.net/forum?id=rJzIBfZAb
  * Mahajan et al. (2019) Divyat Mahajan, Chenhao Tan, and Amit Sharma. 2019.  Preserving causal constraints in counterfactual explanations for machine learning classifiers.  _arXiv preprint arXiv:1912.03277_ (2019).
  * Miller (2019) Tim Miller. 2019\.  Explanation in artificial intelligence: Insights from the social sciences.  _Artificial Intelligence_ 267 (2019), 1–38.
  * Molnar et al. (2020) Christoph Molnar, Giuseppe Casalicchio, and Bernd Bischl. 2020\.  Interpretable machine learning–a brief history, state-of-the-art and challenges. In _Joint European Conference on Machine Learning and Knowledge Discovery in Databases_. Springer, 417–431.
  * Mothilal et al. (2020) Ramaravind K Mothilal, Amit Sharma, and Chenhao Tan. 2020\.  Explaining machine learning classifiers through diverse counterfactual explanations. In _Proceedings of the 2020 Conference on Fairness, Accountability, and Transparency_. 607–617.
  * Murdoch et al. (2019) W James Murdoch, Chandan Singh, Karl Kumbier, Reza Abbasi-Asl, and Bin Yu. 2019.  Interpretable machine learning: definitions, methods, and applications.  _arXiv preprint arXiv:1901.04592_ (2019).
  * Nemirovsky et al. (2022) Daniel Nemirovsky, Nicolas Thiebaut, Ye Xu, and Abhishek Gupta. 2022\.  CounteRGAN: Generating counterfactuals for real-time recourse and interpretability using residual GANs. In _Uncertainty in Artificial Intelligence_. PMLR, 1488–1497.
  * Pawelczyk et al. (2020) Martin Pawelczyk, Klaus Broelemann, and Gjergji Kasneci. 2020\.  Learning model-agnostic counterfactual explanations for tabular data. In _Proceedings of The Web Conference 2020_. 3126–3132.
  * Poursabzi-Sangdeh et al. (2021) Forough Poursabzi-Sangdeh, Daniel G Goldstein, Jake M Hofman, Jennifer Wortman Wortman Vaughan, and Hanna Wallach. 2021.  _Manipulating and Measuring Model Interpretability_.  Association for Computing Machinery, New York, NY, USA.  https://doi.org/10.1145/3411764.3445315
  * Rawal et al. (2020) Kaivalya Rawal, Ece Kamar, and Himabindu Lakkaraju. 2020\.  Can I Still Trust You?: Understanding the Impact of Distribution Shifts on Algorithmic Recourses.  _arXiv preprint arXiv:2012.11788_ (2020).
  * Ribeiro et al. (2016) Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin. 2016\.  ” Why should I trust you?” Explaining the predictions of any classifier. In _Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining_. 1135–1144.
  * Rodríguez et al. (2021) Pau Rodríguez, Massimo Caccia, Alexandre Lacoste, Lee Zamparo, Issam Laradji, Laurent Charlin, and David Vazquez. 2021\.  Beyond trivial counterfactual explanations with diverse valuable explanations. In _Proceedings of the IEEE/CVF International Conference on Computer Vision_. 1056–1065.
  * Ross et al. (2021) Alexis Ross, Himabindu Lakkaraju, and Osbert Bastani. 2021\.  Learning Models for Actionable Recourse.  _Advances in Neural Information Processing Systems_ 34 (2021).
  * Rudin (2019) Cynthia Rudin. 2019\.  Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead.  _Nature Machine Intelligence_ 1, 5 (2019), 206–215.
  * Schut et al. (2021) Lisa Schut, Oscar Key, Rory Mc Grath, Luca Costabello, Bogdan Sacaleanu, Yarin Gal, et al. 2021\.  Generating interpretable counterfactual explanations by implicit minimisation of epistemic and aleatoric uncertainties. In _International Conference on Artificial Intelligence and Statistics_. PMLR, 1756–1764.
  * Sehwag et al. (2020) Vikash Sehwag, Shiqi Wang, Prateek Mittal, and Suman Jana. 2020\.  Hydra: Pruning adversarially robust neural networks.  _Advances in Neural Information Processing Systems_ 33 (2020), 19655–19666.
  * Selvaraju et al. (2017) Ramprasaath R Selvaraju, Michael Cogswell, Abhishek Das, Ramakrishna Vedantam, Devi Parikh, and Dhruv Batra. 2017.  Grad-cam: Visual explanations from deep networks via gradient-based localization. In _Proceedings of the IEEE international conference on computer vision_. 618–626.
  * Singla et al. (2020) Sumedha Singla, Brian Pollack, Junxiang Chen, and Kayhan Batmanghelich. 2020.  Explanation by Progressive Exaggeration. In _International Conference on Learning Representations_.  https://openreview.net/forum?id=H1xFWgrFPS
  * Smilkov et al. (2017) Daniel Smilkov, Nikhil Thorat, Been Kim, Fernanda Viégas, and Martin Wattenberg. 2017.  Smoothgrad: removing noise by adding noise.  _arXiv preprint arXiv:1706.03825_ (2017).
  * Srivastava et al. (2014) Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, and Ruslan Salakhutdinov. 2014.  Dropout: a simple way to prevent neural networks from overfitting.  _The journal of machine learning research_ 15, 1 (2014), 1929–1958.
  * Stepin et al. (2021) Ilia Stepin, Jose M Alonso, Alejandro Catala, and Martín Pereira-Fariña. 2021\.  A survey of contrastive and counterfactual explanation generation methods for explainable artificial intelligence.  _IEEE Access_ 9 (2021), 11974–12001.
  * Sundararajan et al. (2017) Mukund Sundararajan, Ankur Taly, and Qiqi Yan. 2017.  Axiomatic attribution for deep networks. In _International Conference on Machine Learning_. PMLR, 3319–3328.
  * Upadhyay et al. (2021) Sohini Upadhyay, Shalmali Joshi, and Himabindu Lakkaraju. 2021\.  Towards Robust and Reliable Algorithmic Recourse.  _Advances in Neural Information Processing Systems_ 34 (2021).
  * Ustun et al. (2019) Berk Ustun, Alexander Spangher, and Yang Liu. 2019\.  Actionable recourse in linear classification. In _Proceedings of the Conference on Fairness, Accountability, and Transparency_. 10–19.
  * Van Looveren and Klaise (2019) Arnaud Van Looveren and Janis Klaise. 2019.  Interpretable counterfactual explanations guided by prototypes.  _arXiv preprint arXiv:1907.02584_ (2019).
  * Verma et al. (2020) Sahil Verma, John Dickerson, and Keegan Hines. 2020\.  Counterfactual Explanations for Machine Learning: A Review.  _arXiv preprint arXiv:2010.10596_ (2020).
  * Verma et al. (2022) Sahil Verma, Keegan Hines, and John P Dickerson. 2022\.  Amortized generation of sequential algorithmic recourses for black-box models. In _Proceedings of the AAAI Conference on Artificial Intelligence_ , Vol. 36. 8512–8519.
  * Von Kügelgen et al. (2022) Julius Von Kügelgen, Amir-Hossein Karimi, Umang Bhatt, Isabel Valera, Adrian Weller, and Bernhard Schölkopf. 2022.  On the fairness of causal algorithmic recourse. In _Proceedings of the AAAI Conference on Artificial Intelligence_ , Vol. 36. 9584–9594.
  * Wachter et al. (2017) Sandra Wachter, Brent Mittelstadt, and Chris Russell. 2017\.  Counterfactual explanations without opening the black box: Automated decisions and the GDPR.  _Harv. JL & Tech._ 31 (2017), 841.
  * Wu et al. (2021) Boxi Wu, Jinghui Chen, Deng Cai, Xiaofei He, and Quanquan Gu. 2021.  Do Wider Neural Networks Really Help Adversarial Robustness?  _Advances in Neural Information Processing Systems_ 34 (2021).
  * Xu et al. (2015) Bing Xu, Naiyan Wang, Tianqi Chen, and Mu Li. 2015\.  Empirical evaluation of rectified activations in convolutional network.  _arXiv preprint arXiv:1505.00853_ (2015).
  * Yang et al. (2021) Fan Yang, Sahan Suresh Alva, Jiahao Chen, and Xia Hu. 2021\.  Model-Based Counterfactual Synthesizer for Interpretation. In _Proceedings of the 27th ACM SIGKDD Conference on Knowledge Discovery and Data Mining_ (Virtual Event, Singapore) _(KDD ’21)_. Association for Computing Machinery, New York, NY, USA, 1964–1974.  https://doi.org/10.1145/3447548.3467333
  * Yeh and Lien (2009) I-Cheng Yeh and Che-hui Lien. 2009.  The comparisons of data mining techniques for the predictive accuracy of probability of default of credit card clients.  _Expert Systems with Applications_ 36, 2 (2009), 2473–2480.
  * Zhao et al. (2018) Yixue Zhao, Marcelo Schmitt Laser, Yingjun Lyu, and Nenad Medvidovic. 2018.  Leveraging program analysis to reduce user-perceived latency in mobile applications. In _Proceedings of the 40th International Conference on Software Engineering_. 176–186.

##  Appendix A Supplemental Proof

###  A.1. Proof of Lemma 3.1

###### Proof.

$\nabla_{\theta}\mathcal{L}_{1}=\nabla_{\theta}\left\|y-\hat{y}_{x}\right\|_{2}$,
and
$\nabla_{\theta}\mathcal{L}_{2}=\nabla_{\theta}\left\|\left(1-\hat{y}_{x}\right)-\hat{y}_{x^{\prime}}\right\|_{2}$.
Then, we have

$\displaystyle\nabla_{\theta}\mathcal{L}_{1}$
$\displaystyle=\nabla_{\theta}y^{2}-2y\cdot\nabla_{\theta}\cdot\hat{y}_{x}+\nabla_{\theta}\hat{y}_{x}^{2}$
$\displaystyle=-2y\cdot\nabla_{\theta}\hat{y}_{x}+\nabla_{\theta}\hat{y}_{x}^{2}$
$\displaystyle=-2y\cdot\nabla_{\theta}\hat{y}_{x}+2\hat{y}_{x}\nabla_{\theta}\hat{y}_{x}$
$\displaystyle=2(\hat{y}_{x}-y)\cdot\nabla_{\theta}\hat{y}_{x}$

Since $x^{\prime}\to x$, as we expect CF example $x^{\prime}$ is closed to the
original instance x, we can replace $x^{\prime}$ to $x$ in $\mathcal{L}_{2}$.
Then, we have

$\displaystyle\nabla_{\theta}\mathcal{L}_{2}$
$\displaystyle=\nabla_{\theta}(1-2\hat{y}_{x})^{2}$
$\displaystyle=-4\cdot\nabla_{\theta}\hat{y}_{x}+4\cdot\nabla_{\theta}\hat{y}_{x}^{2}$
$\displaystyle=-4\cdot\nabla_{\theta}\hat{y}_{x}+4\cdot
2\cdot\hat{y}_{x}\cdot\nabla_{\theta}\hat{y}_{x}$
$\displaystyle=4\cdot(2\hat{y}_{x}-1)\nabla_{\theta}\hat{y}_{x}$

Hence,

$\displaystyle\nabla_{\theta}\mathcal{L}_{1}\cdot\nabla_{\theta}\mathcal{L}_{2}$
$\displaystyle=2\cdot(\hat{y}_{x}-y)\cdot\nabla_{\theta}\hat{y}_{x}\cdot
4\cdot(2\hat{y}_{x}-1)\nabla_{\theta}\hat{y}_{x}$
$\displaystyle=8\cdot(\hat{y}_{x}-y)\cdot(2\hat{y}_{x}-1)(\nabla_{\theta}\hat{y}_{x})^{2}$

Since $(\nabla_{\theta}\hat{y}_{x})^{2}>0$, we only need to prove whether
$(\hat{y}_{x}-y)\cdot(2\hat{y}_{x}-1)$ is positive or negative.

Given that $|\hat{y}_{x}-y|<0.5$,

  * •

if $y=1$, we have $0.5<\hat{y}_{x}<1$. Then, $(\hat{y}_{x}-y)<0$,
$(2\hat{y}_{x}-1)>0$.

  * •

if $y=0$, we have $0<\hat{y}_{x}<0.5$. Then, $(\hat{y}_{x}-y)>0$,
$(2\hat{y}_{x}-1)<0$.

Therefore, $(\hat{y}_{x}-y)\cdot(2\hat{y}_{x}-1)<0$. Hence,
$\nabla_{\theta}\mathcal{L}_{1}\cdot\nabla_{\theta}\mathcal{L}_{2}<0$.

∎

###  A.2. Proof of Lemma 3.2

###### Proof.

Assuming $f_{\theta}(x)\to y$ as we expect the predictor network produces
accurate predictions, and $y=\\{0,1\\}$, we can replace $f_{\theta}(x)$ to
$y$. Then, minimizing $\mathcal{L}_{2}$ (in Lemma 3.2) indicates minimizing
$\left\|y-(1-f_{\theta}(x^{\prime}))\right\|_{2}$. Since
$0<f_{\theta}(\cdot)<1$, we have

$\min\left\|y-(1-f_{\theta}(x^{\prime}))\right\|_{2}=\max\left\|y-f_{\theta}(x^{\prime})\right\|_{2}$

By replacing $y$ to $f_{\theta}(x)$, then minimizing $\mathcal{L}_{2}$
indicates maximizing
$\left\|f_{\theta}(x)-f_{\theta}(x^{\prime})\right\|_{2}$. By definition, the
lipschitz constant $K$ is

$K=\operatorname*{sup}_{x^{\prime}\in\mathbb{B}(x,\epsilon)}\\{\left\|\nabla
f_{\theta}(x^{\prime})\right\|_{2}=\operatorname*{sup}_{x^{\prime}\in\mathbb{B}(x,\epsilon)}\left\\{\frac{\left\|f_{\theta}(x)-f_{\theta}(x^{\prime})\right\|}{\left\|x-x^{\prime}\right\|}\right\\}$

where minimizing $\mathcal{L}_{2}$ increases
$\left\|f_{\theta}(x)-f_{\theta}(x^{\prime})\right\|_{2}$. Therefore, the
lipschitz constant $K$ increases.

∎

##  Appendix B Implementation Details

Here we provide implementation details of CounterNet and five baselines on
four datasets listed in Section 4. The code can be found in the supplemental
material.

###  B.1. Software and Hardware Specification

We use Python (v3.7) with Pytorch (v1.82), Pytorch Lightning (v1.10), numpy
(v1.19.3), pandas (1.1.1) and scikit-learn (0.23.2) for the implementations.
All our experiments were run on a Debian-10 Linux-based Deep Learning Image
with CUDA 11.0 on the Google Cloud Platform.

The CounterNet’ network is trained on NVIDIA Tesla V100 with an 8-core Intel
machine. CF generation of four baselines are run on a 16-core Intel machine
with 64 GB of RAM. The evaluation are generated from the same 16-core machine.

###  B.2. Datasets for Evaluation

Table 7. Summary of Datasets used for Evaluation Dataset | Size | #Continuous | #Categorical
---|---|---|---
Adult | 32,561 | 2 | 6
Credit | 30,000 | 20 | 3
HELOC | 10,459 | 21 | 2
OULAD | 32,593 | 23 | 8
Student | 649 | 2 | 14
Titanic | 891 | 2 | 24
Cancer | 569 | 30 | 0
German | 1,000 | 7 | 13

Here, we reiterate our used datasets for evaluations. Our evaluation is
conducted on eight widely-used tabular datasets. Our primary evaluation uses
four large-sized datasets (shown in Section 4), including _Adult_ , _Credit_ ,
_HELOC_ , and _OULAD_ , which contain at least 10k data instances. In
addition, we experiment with four small-sized datasets, including _Student_ ,
_Titanic_ , _Cancer_ , and _German_. Table 7 summarizes datasets used for
evaluations.

###  B.3. Evaluation Metrics

Here, we provide formal definitions of the evaluation metrics.

Predictive Accuracy is defined as the fraction of the correct predictions.

(3) $\texttt{Predictive-Accuracy}=\frac{\\#|f(x)=y|}{n}$

Validity is defined as the fraction of input instances on which CF explanation
methods output valid CF examples.

(4) $\texttt{Validity}=\frac{\\#|f(x^{\prime})=1-y|}{n}$

Proximity is defined as the $L_{1}$ norm distance between $x$ and $x^{\prime}$
divided by the number of features.

(5) $\texttt{Proximity}=\frac{1}{nd}\sum_{i=1}^{n}\sum_{j=1}^{d}\lVert
x_{i}^{(j)}-x^{\prime(j)}_{i}\rVert_{1}$

Sparsity is defined as the fraction of the number of feature changes between
$x$ and $x^{\prime}$.

(6) $\texttt{Sparsity}=\frac{1}{nd}\sum_{i=1}^{n}\sum_{j=1}^{d}\lVert
x_{i}^{(j)}-x^{\prime(j)}_{i}\rVert_{0}$

###  B.4. CounterNet Implementation Details

Across all six datasets, we apply the following same settings in training
CounterNet: We initialize the weights as in He et al. (2016). We adopt the
Adam with mini-batch size of 128. For each datasets, we trained the models for
up to $1\times 10^{3}$ iterations. To avoid gradient explosion, we apply
gradient clipping by setting the threshold to 0.5 to clip gradients with norm
above 0.5. We set dropout rate to 0.3 to prevent overfitting. For all six
datasets, we set $\lambda_{1}=1.0$, $\lambda_{2}=0.2$, $\lambda_{3}=0.1$ in
Equation 2.

The learning rate is the only hyper-parameter that varies across six datasets.
From our empirical study, we find the training to CounterNet is sensitive to
the learning rate, although a good choice of loss function (e.g. choosing MSE
over cross-entropy) can widen the range of an ”optimal” learning rate. We
apply grid search to tune the learning rate, and our choice is specified in
Table 8.

Additionally, we specify the architecture’s details (e.g. dimensions of each
layer in encoder, predictor and CF generator) in Table 8. The numbers in each
bracket represent the dimension of the transformed matrix. For example, the
encoder dimensions for adult dataset is [29, 50, 10], which means that the
dimension of input $x\in\mathbb{R}^{d}$ is 29 (e.g. $d=29$); the encoder first
transforms the input into a 50 dimension matrix, and then downsamples it to
generate the latent representation $z\in\mathbb{R}^{k}$ where $k=10$.

Table 8. Hyperparameters and architectures for each dataset. Dataset | Learning Rate | Encoder Dims | Predictor Dims | CF Generator Dims
---|---|---|---|---
Adult | 0.003 | [29, 50, 10] | [10, 10, 2] | [20, 50, 29]
Credit | 0.003 | [33, 50, 10] | [10, 10, 2] | [20, 50, 33]
HELOC | 0.005 | [35, 100, 10] | [10, 10, 2] | [20, 100, 35]
OULAD | 0.001 | [127, 200, 10] | [10, 10, 2] | [20, 200, 127]
Student | 0.01 | [85, 100, 10] | [10, 10, 2] | [20, 100, 85]
Titanic | 0.01 | [57, 100, 10] | [10, 10, 2] | [20, 100, 57]
Cancer | 0.001 | [30, 50, 10] | [10, 10, 2] | [20, 50, 30]
German | 0.003 | [61, 50, 10] | [10, 10, 2] | [20, 50, 61]

###  B.5. Hyper-parameters for Baselines

Table 9. Learning rate of the base predictive models on each dataset. Dataset |  | Learning Rate
---
Adult | 0.01
HELOC | 0.005
OULAD | 0.001
Student | 0.01
Titanic | 0.01
Cancer | 0.001

Next, we describe the implementation of baseline methods. For VanillaCF and
ProtoCF, we follow author’s instruction as much as we can, and implement them
in Pytorch. For VanillaCF, DiverseCF and ProtoCF, we run maximum $1\times
10^{3}$ steps. After CF generation, we convert the results to one-hot-encoding
format for each categorical feature. For training the VAE-CF, we follow
Mahajan et al. (2019)’s settings on running maximum 50 epoches and setting the
batch size to 1024. We use the same learning rate as in Table 8 for VAE
training.

For training predictive models for baseline algorithms, we apply grid search
for tuning the learning rate, which is specified in Table 9. Similar to
training the CounterNet, we adopt the Adam with mini-batch size of 128, and
set the dropout rate to 0.3. We train the model for up to 100 iterations with
early stopping to avoid overfittings.

##  Appendix C Additional Experimental Results

Here, we provide additional results of experiments in Section 4. These results
further demonstrate the effectiveness of CounteNet.

###  C.1. Additional Robustness Results

We provide supplementary results on evaluating the robustness of the predictor
network on three large datasets (i.e., Adult, HELOC and OULAD). In particular,
we implement FSGM (Goodfellow et al., 2015) and PGD (Madry et al., 2018)
attack for testing the robustness of the predictive models. Figure 6
illustrates that CounterNet achieves comparable perturbation stability (i.e.,
the robustness of the predictive model) as the base model. In addition, Figure
6 supports the findings in Lemma 3.2 since _CounterNet-NoFreeze_ consistently
achieves lower stability than base models and CounterNet.

(a) Robustness of $f(\cdot)$ under FSGM attack on the adult dataset.

(b) Robustness of $f(\cdot)$ under FSGM attack on the OULAD dataset.

(c) Robustness of $f(\cdot)$ under FSGM attack on the HELOC dataset.

(d) Robustness of $f(\cdot)$ under PGD attack on the adult dataset.

(e) Robustness of $f(\cdot)$ under PGD attack on the OULAD dataset.

(f) Robustness of $f(\cdot)$ under PGD attack on the HELOC dataset.

Figure 6. Robustness of $f(\cdot)$ under FSGM attack (6(a)-6(c)) (Goodfellow
et al., 2015) and PGD (6(d)-6(f)) (Madry et al., 2018) attack.

##  Appendix D Additional Ablation Study

###  D.1. CounterNet under the Black-box Assumptions

We illustrate how CounterNet can be adapted to the post-hoc black-box setting.
In this setting, CF explanation methods generate CF explanations for a
_trained_ black-box model (with access to the model’s output). CounterNet can
also be used in this post-hoc setting by forcing the predictor network to
surrogate the black-box model. Specifically, let a black-box model
$M:\mathcal{X}\to\mathcal{Y}$ outputs the predictions, our goal of training
the predictor is to ensure that the predictor model behaves like the black-box
model (i.e., $\mathcal{M}(x)=f(x)$). The training objective of CounterNet is

(7)
$\begin{split}\operatorname*{argmin}_{\mathbf{\theta}}\frac{1}{N}\sum\nolimits_{i=1}^{N}\bigg{[}&\lambda_{1}\cdot\\!\underbrace{\left(M(x_{i})-\hat{y}_{x_{i}}\right)^{2}}_{\text{Prediction
Loss}\ (\mathcal{L}_{1})}+\\\
&\;\lambda_{2}\cdot\;\;\underbrace{\left(\hat{y}_{x_{i}}-\left(1-\hat{y}_{x_{i}^{\prime}}\right)\right)^{2}}_{\text{Validity
Loss}\ (\mathcal{L}_{2})}\,+\\\
&\;\lambda_{3}\cdot\\!\\!\underbrace{\left(x_{i}-x^{\prime}_{i}\right)^{2}}_{\text{Proximity
Loss}\ (\mathcal{L}_{3})}\bigg{]}\end{split}$

Note that Eq. 7 looks identical to Eq. 2. The only difference is that $y_{i}$
in Eq. 2 is replaced to $M(x_{i})$.

Table 10 shows the performance of CounterNet under the black-box setting
(CFNet-BB). CFNet-BB degrades slightly in terms of validity, average $L_{1}$
to _CounterNet_. This is because approximating the black-box model leads to
degraded performance in the quality of generating CF explanations.

Table 10. Evaluation of CounterNet under the post-hoc setting. CFNet-BB represents the CounterNet evaluated under the _black-box_ setting. CFNet-PH represents the CounterNet trained via a _post-hoc_ fashion, which in turn, demonstrates the importance of joint-training procedure in CounterNet. Method | Adult | Credit | HELOC | OULAD
---|---|---|---|---
| Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man. | Val. | Prox. | Spar. | Man.
CFNet-BB | 0.99 | .217 | .716 | 0.73 | .99 | .138 | .861 | 0.64 | 0.98 | .158 | .758 | 0.58 | 0.99 | .073 | .641 | 0.96
CFNet-PH | 1.00 | .276 | .663 | 1.26 | 1.00 | .247 | .804 | 1.36 | 1.00 | .153 | .815 | 0.83 | 0.99 | .099 | .731 | 1.64
CounterNet | 1.00 | .196 | .644 | 0.64 | 1.00 | .132 | .912 | 0.56 | 1.00 | .125 | .740 | 0.56 | 1.00 | .075 | .725 | 0.87

###  D.2. Ablations on CounterNet’s Training

In addition, we provide supplementary results on ablation analysis of three
large datasets (Adult, HELOC, and OULAD) to understand the design choices of
the CounterNet training (shown in Figure 7). This figure shows that compared
to CounterNet’s learning curve for $\mathcal{L}_{2}$, CounterNet-BCE and
CounterNet-NoSmooth’s learning curves show significantly higher instability,
illustrating the importance of MSE-based loss functions and label smoothing
techniques. Moreover, CounterNet-SingleBP’s learning curve for
$\mathcal{L}_{2}$ performs poorly in comparison, which illustrates the
difficulty of optimizing three divergent objectives using a single BP
procedure. In turn, this also illustrates the effectiveness of our block-wise
coordinate descent optimization procedure in CounterNet’s training. These
results show that all design choices made in Section 3 contribute to training
the model effectively.

In addition, we experiment with alternative loss formulations. We replace the
MSE based $\mathcal{L}_{3}$ loss in Eq. 2 with $l_{1}$ norm
(CounterNet-$l_{1}$). Table 11 shows that replacing $\mathcal{L}_{3}$ with a
$l_{1}$ formulation leads to a degraded performance.

Table 11. Ablation analysis of CounterNet. Each ablation leads to degraded performance, which in turn, demonstrates the importance of different design choices inside CounterNet. Ablation | Adult | Credit | HELOC | OULAD
---|---|---|---|---
| Val. | Prox. | Val. | Prox. | Val. | Prox. | Val. | Prox.
CounterNet-$l_{1}$ | .98 | 0.25 | 0.99 | .163 | .99 | .155 | 0.99 | .094
CounterNet | 1.00 | .196 | 1.00 | .132 | 1.00 | .125 | 1.00 | .075

(a) Learning curves of model ablations on the Adult dataset.

(b) Learning curves of model ablations on the HELOC dataset.

(c) Learning curves of model ablations on the OULAD dataset.

Figure 7. Learning curves of $\mathcal{L}_{1}$ (left), $\mathcal{L}_{2}$
(mid), and $\mathcal{L}_{3}$ (right) of model ablations on the Adult (7(a)),
HELOC (7(b)), and OULAD (7(c)) dataset.

##  Appendix E Experimental Evaluation on Small-Sized Datasets

In addition to four large datasets in Section 4, we experiment with four
small-sized datasets: (i) _Breast Cancer Wisconsin_ (Blake, 1998) which
classifies malignant (`Y=1`) or benign (`Y=0`) tumors; (ii) _Student
Performance_ (Cortez and Silva, 2008) which predicts whether a student will
pass (`Y=1`) or fail (`Y=0`) the exam; (iii) _Titanic_ (Kaggle, 2018) which
predicts whether passengers survived (`Y=1`) the Titanic shipwreck or not
(`Y=0`); and (iv) _German Credit_ (Asuncion and Newman, 2007) which predicts
whether the credit score of a customer is good (`Y=1`) or bad (`Y=0`).

Table 12 compares the validity, average $L_{1}$ and sparsity achieved by
CounterNet and baselines. Similar to results in Table 3, CounterNet achieves a
perfect validity. In addition, CounterNet achieves the lowest proximity in
three out of four small datasets. This result further shows CounterNet’s
ability in balancing the cost-invalidity trade-off.

Table 12. Evaluation of counterfactual explanations on four small-sized datasets.  Method | Student | Titanic | Cancer | German
---|---|---|---|---
| Val. | Prox. | Spar. | Val. | Prox. | Spar. | Val. | Prox. | Spar. | Val. | Prox. | Spar.
VanillaCF | 0.80 | 0.101 | 0.762 | 0.91 | 0.289 | 0.381 | 1.00 | 0.135 | 0.278 | 0.86 | 0.384 | 0.967
DiverseCF | 0.53 | 0.117 | 0.565 | 0.52 | 0.321 | 0.370 | 0.99 | 0.075 | 0.157 | 0.64 | 0.246 | 1.000
ProtoCF | 0.32 | 0.107 | 0.754 | 0.76 | 0.305 | 0.383 | 1.00 | 0.070 | 0.167 | 0.82 | 0.369 | 0.983
UncertainCF | 0.45 | 0.251 | 0.675 | 0.41 | 0.422 | 0.512 | 1.00 | 0.023 | 0.039 | 0.50 | 0.310 | 0.945
C-CHVAE | 1.00 | 0.110 | 0.797 | 1.00 | 0.389 | 0.475 | 0.62 | 0.353 | 0.325 | 1.00 | 0.307 | 0.568
VAE-CF | 0.50 | 0.115 | 0.586 | 0.38 | 0.356 | 0.460 | 0.39 | 0.202 | 0.293 | 0.34 | 0.310 | 0.577
CounterNet | 1.00 | 0.075 | 0.725 | 1.00 | 0.257 | 0.354 | 1.00 | 0.121 | 0.259 | 1.00 | 0.222 | 0.626

##  Appendix F Second-order Evaluation

We define three additional second-order metrics which attempt to evaluate the
usability of CF explanation techniques by human end-users. We posit that
negligible feature differences (among continuous features) between instance
$x$ and CF example $x^{\prime}$ make it difficult for human end-users to use
CF example $x^{\prime}$ (as many of the recourse recommendations contained
within $x^{\prime}$ may not be actionable due to negligible differences). For
example, human end-users may find it impossible to increase their
Daily_Sugar_Consumed by 0.523 grams (if the value of Daily_Sugar_Consumed
feature is 700 and 700.523 between $x$ and $x^{\prime}$, respectively). As
such, human end-users may be willing to ignore small feature differences
between $x$ and $x^{\prime}$.

To define our usability related metrics, we construct a user-friendly second-
order CF example $x^{\prime\prime}$ by ignoring small feature differences
(i.e., $|x_{i}-x^{\prime}_{i}|$ is less than threshold $b$) between instance
$x$ and CF example $x^{\prime}$. Formally, let $x=\\{x_{1},x_{2},..,x_{d}\\}$
and $x^{\prime}=\\{x^{\prime}_{1},x^{\prime}_{2},..,x^{\prime}_{d}\\}$ be the
features of the input instance and the CF example, respectively. Then, we use
a threshold of $b$, and create a new data point
$x^{\prime\prime}=\\{l_{i}=\mathbbm{1}_{|x_{i}-x^{\prime}_{i}|\leq
b}x_{i}+\mathbbm{1}_{|x_{i}-x^{\prime}_{i}|>b}x^{\prime}_{i}\mbox{ }\forall
i\in 1\ldots d\\}$, i.e., we replace all features $i\in\\{1,d\\}$ in CF
example $x^{\prime}$ with features in the original input instance $x$ for
which $|x_{i}-x^{\prime}_{i}|\leq b$. Our metrics for CF usability are defined
in terms of $x$ and $x^{\prime\prime}$ as follows:

  * •

Second-Order Validity is defined as the fraction of input instances on which
$x^{\prime\prime}$ remains a valid CF example. High second-order validity is
desirable, because it implies that despite ignoring small feature differences,
the second-order CF example $x^{\prime\prime}$ remains valid.

  * •

Second-Order Proximity is defined as the $L_{1}$ norm distance between $x$ and
$x^{\prime\prime}$. It is desirable to maintain low second-order proximity
because it indicates fewer cumulative modifications in the input space.

  * •

Second-Order Sparsity is defined as the number of feature changes (i.e.,
$L_{0}$ norm) between $x$ and $x^{\prime\prime}$. High second-order sparsity
enhances the interpretability of a CF explanation. Note that second-order
sparsity is more important than the original sparsity metric, as the second-
order CF example $x^{\prime\prime}$ ignores small feature changes in the
continuous features, yielding fewer number of feature changes in the input
space.

###  F.1. Experimental Results

The evaluation of counterfactual usability measures the quality of the second-
order CF example $x^{\prime\prime}$ which is created by ignoring negligible
differences between input instance $x$ and the CF example $x^{\prime}$. We use
a fixed threshold $b=2$ to derive the “sparse” second-order CF example
$x^{\prime\prime}$, and compute the second-order evaluation metrics.

Second-order validity. Table 13 compares the second-order validity of CF
examples generated by CounterNet and other baselines on all six datasets.
Similar to results in Table 3, CounterNet performs consistently well across
all six datasets on the validity metric, as CounterNet is the only CF
explanation method which achieves over 93.7% second-order validity on all six
datasets. In particular, CounterNet achieves $\sim$11% higher second-order
validity than C-CHVAE (its closest competitor) on all six datasets. Further,
CounterNet is the only CF method which achieves more than 90% second-order
validity on the Breast Cancer dataset, whereas all post-hoc baselines perform
poorly (none of them achieve second-order validity higher than 70%), despite
the fact that three of these baselines (VanillaCF, DiverseCF, and ProtoCF)
achieved more than 99% first-order validity on this dataset. This result
demonstrates that CounterNet is much more robust against small perturbations
in the continuous feature space.

Second-order Sparsity and Proximity. In terms of second-order sparsity,
CounterNet outperforms two parametric CF explanation methods (C-CHVAE and VAE-
CF), and maintains competitive performance against two non-parametric methods
(VanillaCF and ProtoCF). Across all six datasets, CounterNet outperforms
C-CHVAE and VAE-CF by $\sim$10% on the this metric. Moreover, the difference
between the second-order sparsity achieved by CounterNet and VanillaCF (and
ProtoCF) is close to 1%, which indicates that CounterNet achieves the same
level of second-order sparsity as these two non-parametric methods. In terms
of second-order proximity, CounterNet is highly proximal against baseline
methods as it achieves the lowest proximity in HELOC, OULAD, and Titanic
datasets (similar to results in Table 3).

Figure 8. Illustration of trade-off between invalidity and sparsity across six
datasets (methods at the bottom left are preferable).

Cost-Invalidity Trade-off. Figure 8 shows that CounterNet positions on the
bottom left of this figure, which illustrates that CounterNet can balance the
cost-invalidity trade-off in the counterfactual usability evaluation. Notably,
CounterNet outperforms all post-hoc methods in the second-order invalidity
metric, and maintains the same level of second-order sparsity as VanillaCF and
ProtoCF ($\sim$1% difference). Moreover, although DiverseCF achieves $\sim$10%
lower second-order sparsity value than CounterNet, it has $\sim$50% higher
second-order invalidity than CounterNet. This results from DiverseCF’s
inability to balance the the trade-off between second-order invalidity and
sparsity. This high second-order invalidity of DiverseCF hampers its
usability, even though it generates more sparse explanations.

Table 13. Evaluation of Usability of Counterfactual Explanations Datasets | Metrics | Methods
---|---|---
| VanillaCF | DiverseCF | ProtoCF | C-CHVAE | VAE-CF | CounterNet
Adult | Validity | 0.764 | 0.515 | 0.508 | 0.995 | 0.348 | 0.995
Proximity | 5.843 | 8.007 | 7.261 | 8.139 | 8.319 | 7.170
Sparsity | 4.445 | 5.297 | 5.181 | 5.771 | 5.869 | 5.148
HELOC | Validity | 1.000 | 0.906 | 1.000 | 0.986 | 1.000 | 0.988
Proximity | 5.350 | 5.202 | 6.131 | 5.841 | 6.725 | 4.289
Sparsity | 20.304 | 9.979 | 18.514 | 18.166 | 20.546 | 17.020
OULAD | Validity | 1.000 | 0.701 | 0.999 | 0.886 | 0.969 | 0.980
Proximity | 12.469 | 14.751 | 13.183 | 13.569 | 13.335 | 11.740
Sparsity | 23.618 | 17.516 | 23.360 | 24.696 | 18.162 | 22.472
Student | Validity | 0.669 | 0.528 | 0.307 | 0.982 | 0.485 | 0.982
Proximity | 11.919 | 18.392 | 15.606 | 21.406 | 21.336 | 19.758
Sparsity | 6.840 | 9.313 | 7.896 | 10.847 | 10.951 | 10.043
Titanic | Validity | 0.987 | 0.570 | 0.785 | 1.000 | 0.386 | 0.978
Proximity | 17.282 | 16.809 | 17.039 | 21.145 | 20.278 | 15.056
Sparsity | 9.906 | 9.632 | 9.960 | 12.359 | 11.964 | 9.215
Breast Cancer | Validity | 0.699 | 0.196 | 0.329 | 0.615 | 0.210 | 0.937
Proximity | 1.313 | 0.890 | 0.655 | 3.618 | 2.089 | 1.422
Sparsity | 8.343 | 4.699 | 5.014 | 9.741 | 8.783 | 7.762

##  Appendix G CounterNet under the Multi-class Settings

In prior CF explanation literature, counterfactual explanations are primarily
evaluated under the binary classification settings (Mothilal et al., 2020;
Mahajan et al., 2019; Upadhyay et al., 2021). However, it is worth-noting that
CF explanation methods (including CounterNet) can be adapted to the multi-
class classification settings. This section first describes the problem
setting of the CF explanations when dealing with multi-class classification.
Next, we describe how to train CounterNet for multi-class predictions and CF
explanations. Finally, we present the evaluation set-up and show the
simulation results.

###  G.1. Training CounterNet for Multi-Class Classification

Given an input instance $x\in\mathbb{R}^{d}$, CounterNet aims to generate two
outputs: (i) a prediction $\hat{y}_{x}\in\mathbb{R}^{k}$ for input instance
$x$; and (ii) the CF example $x^{\prime}\in\mathbb{R}^{d}$ as an explanation
for input instance $x$. The prediction $\hat{y}_{x}\in\mathbb{R}^{k}$ is
encoded as one-hot format as $\hat{y}_{x}\in\\{0,1\\}^{k}$, where
$\sum_{i}^{k}\hat{y}_{x}^{(i)}=1$, $k$ denotes the number of classes.
Moreover, we assume that there is a desired outcome $y^{\prime}$ for every
input instances $x$. Then, it is desirable that a CF explanation
$y_{x^{\prime}}$ needs to be predicted as the desired outcome $y^{\prime}$
(i.e., $y_{x^{\prime}}=y^{\prime}$).

The objective for CounterNet in the multi-class setting remains the same as in
the binary setting. Specifically, we expect CounterNet to achieve high
_predictive accuracy_ , _counterfactual validity_ and _proximity_. As a
result, we adjust loss functions from Eq. 2 as follows:

(8)
$\begin{split}\mathcal{L}_{1}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(y_{i}-\hat{y}_{x_{i}})^{2}\\\
\mathcal{L}_{2}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(\hat{y}_{x_{i}}-y^{\prime})^{2}\\\
\mathcal{L}_{3}&=\frac{1}{N}\sum\nolimits_{i=1}^{N}(x_{i}-x^{\prime}_{i})^{2}\\\
\end{split}$

Same as training CounterNet in the binary setting, we optimize the parameter
$\theta$ of the overall network by solving the minimization problem in Eq. 2
to (except that we are switching to use loss functions in Eq. 8). Moreover, we
adopt the same block-wise coordinate optimization procedure to solve this
minimization problem by first updating for predictive accuracy
$\theta^{\prime}=\theta-\nabla_{\theta}(\lambda_{1}\cdot\mathcal{L}_{1})$, and
then updating for CF explanation
$\theta^{\prime\prime}=\theta^{\prime}-\nabla_{\theta}(\lambda_{2}\cdot\mathcal{L}_{2}+\lambda_{3}\cdot\mathcal{L}_{3})$.

###  G.2. Experimental Evaluation

Dataset. We use _Cover Type_ dataset (Blackard, 1998) for evaluating the
multi-class classification experiment. _Cover Type_ dataset predicts forest
cover type from cartographic variables. This dataset contains seven classes
(e.g., `Y=1`, `Y=2`, …, `Y=7`), with 10 continuous features. For CF
explanation generation, we assume that cover type `5` (e.g., `Y=5`) is the
desired class. The original dataset is highly imbalanced, so we equally sample
data instances from each class.

Results. Table 14 compares the performance of counterNet and our two most
competitive baselines (i.e., VanillaCF and C-CHVAE) in the evaluation for
binary datasets (as found in Table 3 & 13). This table shows that CounterNet
can achieve competitive performance against post-hoc CF explanation techniques
in the multi-class classification settings. In terms of predictive accuracy,
CounterNet performs comparably as the baseline methods with only $\sim$2%
decrease (in average). In terms of validity and proximity, CounterNet can
properly balance the cost-invalidity trade-off. Although CounterNet achieves
higher proximity score than VanillaCF, it achieves 100% validity score.
Compared to C-CHVAE, CounterNet achieves $\sim$80% lower proximity. Finally,
CounterNet runs order-of-magnitudes faster than our two baseline methods.
CounterNet runs more than 1000X and 3000X faster than C-CHVAE and VanillaCF,
respectively.

Table 14. Results for CF explanation methods on Forester Cover Type dataset. Methods |  | Predictive Accuracy
---
| Validity
---
| Proximity
---
| Running Time
---
VanillaCF | 0.911 | 0.921 | 0.379 | 1679.676
C-CHVAE | 0.911 | 1.000 | 1.503 | 734.625
CounterNet | 0.887 | 1.000 | 0.800 | 0.566

##  Appendix H Impact of Neural Network Structures

We further study the impact of the different neural network blocks. In our
experiment, we primarily use multi-layer perception as it is a suitable
baseline model for the tabular data. For comparison, We also implemented the
CounterNet with Convolutional building blocks (i.e. replace the feed forward
neural network with convolution layer). We implemented the convolutional
CounterNet on the Adult dataset. To train the feed forward neural network with
convolution layers, we set the learning rate as 0.03 and $\lambda_{1}=1.0$,
$\lambda_{2}=0.4$, $\lambda_{3}=0.01$. The rest of the configuration is
exactly the same as training CounterNet with MLP.

Table 15 shows comparison between CounterNet with convolutional building
blocks (_CounterNet-Conv_) and multi-layer perceptions (_CounterNet-MLP_). The
results indicate that CounterNet-Conv matches the performances of CounterNet-
MLP. In fact, CounterNet-Conv performs slightly worse than CounterNet-MLP
because convolutional block is not well-suitable for tabular datasets. Yet,
CounterNet-Conv outperforms the rest of our post-hoc baselines in validity
(with reasonably good proximity score). This illustrates CounterNet’s
potential real-world usage in various settings as it is agnostic to the
network structures.

Table 15. Results for the CounterNet with Convolution layers on Adult dataset. Building Block |  | Predictive Accuracy
---
| Validity
---
| Proximity
---
CounterNet-Conv | 0.823 | 0.980 | 7.554
CounterNet-MLP | 0.828 | 0.994 | 7.156

##  Appendix I CounterNet on the Image Dataset

CounterNet is designed to generate counterfactual explanations for tabular
datasets (the most common use case for CF explanations). We also experiment
with CounterNet on the image datasets. This experiment uses the MNIST dataset:
class “7” is used as the positive label, and class “1” is used as the negative
label. Next, we apply the same CounterNet training procedure to generate image
counterfactuals. Table 16 demonstrates the results of CounterNet on the MNIST
dataset. CounterNet achieves 52.4% validity with 0.059 average $L_{1}$
distance. This result shows a current limitation of CounterNet as applying
CounterNet as-is is ill-suited for generating image counterfactual
explanations.

Table 16. CounterNet on the Image Datasets. | Validity | Proximity
---|---|---
CounterNet | 0.524 | 0.059

##  Appendix J Real-World Usage.

We illustrate how CounterNet generates interpretable explanations for end-
users. Figure 9 show an actual data point $x$ from the Adult dataset, and the
corresponding CF explanation $x^{\prime}$ generated by CounterNet. This figure
shows that $x$ and $x^{\prime}$ differ in three features. In addition,
CounterNet generates $x^{\prime\prime}$ by ignoring feature changes that are
less than threshold $b=2$ (in practice, domain experts can help identify
realistic values of $b$). Note that due to CounterNet’s high second-order
validity, $x^{\prime\prime}$ also remains a valid CF example. After this post-
processing step, $x$ and $x^{\prime\prime}$ differ in exactly two features,
and the end-user is provided with the following natural-language explanation:
“ _If you want the ML model to predict that you will earn more than US$50K,
change your education from HS-Grad to Doctorate, and reduce the number of
hours of work/week from 48 to 33.5._”

Figure 9. A counterfactual explanation from CounterNet.