C OUNTERFACTUAL P LANS UNDER D ISTRIBUTIONAL A MBIGUITY
A BSTRACT
Counterfactual explanations are attracting signiﬁcant attention due to the ﬂourishing applications of machine learning models in consequential domains.
A counterfactual plan consists of multiple possibilities to modify a given instance so that the model’s prediction will be altered.
As the predictive model can be updated subject to the future arrival of new data, a counterfactual plan may become ineffective or infeasible with respect to the future values of the model parameters.
In this work, we study the counterfactual plans under model uncertainty, in which the distribution of the model parameters is partially prescribed using only the ﬁrst- and second-moment information.
First, we propose an uncertainty quantiﬁcation tool to compute the lower and upper bounds of the probability of validity for any given counterfactual plan.
We then provide corrective methods to adjust the counterfactual plan to improve the validity measure.
The numerical experiments validate our bounds and demonstrate that our correction increases the robustness of the counterfactual plans in different real-world datasets.
I NTRODUCTION
Machine learning models, thanks to their superior predictive performance, are blooming with increasing applications in consequential decision-making tasks.
Along with the potential to help making better decisions, current machine learning models are also raising concerns about their explainability and transparency, especially in domains where humans are at stake.
These domains span from loan approvals (Siddiqi, 2012), university admission (Waters & Miikkulainen, 2014) to job hiring (Ajunwa et al., 2016).
In these applications, it is instructive to understand why a particular algorithmic decision is made and counterfactual explanations act as a useful toolkit to comprehend (black-box) machine learning models (Wachter et al., 2017).
Counterfactual explanation is also known in the ﬁeld of interpretable machine learning as contrastive explanation (Miller, 2018;
Karimi et al., 2020b) or recourse (Ustun et al., 2019).
A counterfactual explanation suggests how an instance should be modiﬁed so as to receive an alternate algorithmic outcome.
As such, it could be used as a suggestion for improvement purposes.
For example, a student is rejected from graduate study, and the university can provide one or multiple counterfactuals to guide the applicant for admission in the following year.
A concrete example may be of the form “get a GRE score of at least 325” or “get a 6-month research experience”.
In practice, providing a counterfactual plan consisting of multiple examples is highly desirable because a single counterfactual to every applicant with the same covariates may be unsatisfactory (Wachter et al., 2017).
Indeed, the covariates can barely capture the intrinsic behaviors, constraints and unrevealed preferences of the person they represent so that the users with the same features may have different preferences to modify their input.
As a consequence, a pre-emptive design choice is to provide a “menu” of possible recourses, and let the applicant choose the recourse that ﬁts them best.
Viewed in this way, a counterfactual plan has the potential to increase satisfaction and build trust among the stakeholders of any machine learning applications.
Constructing a counterfactual plan, however, is not a straightforward task because of the many competing criteria in the design process.
By deﬁnition, the plan should be valid: by committing to any counterfactual in the plan, the application should be able to ﬂip his current unfavorable outcome to a favorable one.
However, each possibility in the plan should be in the proximity of the covariates of the applicant so that the modiﬁcation is actionable.
Further, the plan should consist of a diverse range of recourses to accommodate the different tastes and preferences of the population.
Russell (2019) propose a mixed integer programming method to generate a counterfactual plan for a linear classiﬁer, in which the diversity is imposed using a rule-based approach.
In Dandl et al.
(2020), the authors propose a model-agnostic approach using a multi-objective evolutionary algorithm to construct a diverse counterfactual plan.
More recently, Mothilal et al.
(2020) use the determinantal point process to measure the diversity of a plan.
The authors then formulate an optimization problem to ﬁnd the counterfactual plan that minimizes the weighted sum of three terms representing validity, proximity, and diversity.
A critical drawback of the existing works is the assumption of an invariant predictive model, which often fails to hold in practical settings.
In fact, during a turbulent pandemic time, it is difﬁcult to assume that the demographic population of students applying for postgraduate studies remain unchanged.
And even in the case that the demography remains unchanged, special pandemic conditions such as hybrid learning mode or travel bans may affect the applicants’ package, which in turn leads to ﬂuctuations of the covariate distribution in the applicant pool.
These shifts in the data are channeled to the shift in the parameters of the predictive model: when the machine learning models are re-trained or re-calibrated with new data, their parameters also change accordingly (Venkatasubramanian & Alfano, 2020).
This raises an emerging concern because the counterfactual plan is usually designed to be valid to only the current model, but that is not enough to guarantee any validity on the future models.
Thus, the counterfactual plan carries a promise of a favorable future outcome, nevertheless, this promise is fragile.
It is hence reasonable to demand the counterfactual plan to be robust with respect to the shift of the parameters.
Pawelczyk et al.
(2020) study the sparsity of counterfactuals and its non-robustness under different ﬁxed models (predictive multiplicity).
Rawal et al.
(2020) consider the counterfactual plan problem and describe several types of model shift related to the correction, temporal, and geospatial shift from data.
They also study the trade-off between the recourse proximity and its validity regarding to the model updates.
Most recently, Upadhyay et al.
(2021) leverage robust optimization to generate a counterfactual that is robust to some constrained perturbations of the model’s parameters.
However, both works consider only the single counterfactual settings.
Contributions.
We study the many facets of the counterfactual plans with respect to random future model parameters.
We focus on a linear classiﬁcation setting and we prescribe the random model parameters only through the ﬁrst- and second-moment information.
We contribute concretely
a diagnostic tool to assess the validity of a counterfactual plan.
It provides a lower and upper bound on the probability of joint validity of a given plan subject to uncertain model parameters.
a correction tool to improve the validity of a counterfactual plan, while keeping the modiﬁcations to each counterfactual at a minimal level.
The corrections are intuitive and admit closed-form expression.
a COunterfactual Plan under Ambiguity (COPA) framework to construct a counterfactual plan which explicitly takes the model uncertainty into consideration.
It minimizes the weighted sum of validity, proximity and diversity terms and can be solved efﬁciently using gradient descents.
Each of our above contributions is exposed in Section 2, 3 and 4, respectively.
In Section 5, we conduct experiments on both synthetic and real-world datasets to demonstrate the efﬁciency of our corrections and of our COPA framework.
All proofs can be found in the appendix.
General setup.
Consider a covariate space R d and a linear binary classiﬁcation setting.
Each linear classiﬁer can be parametrized by θ ∈ R d with decision output C θ ( x ) =
if θ (cid:62) x ≥ 0 , and
0 otherwise, where 0 represents an unfavorable outcome.
Note that we omit the bias term to avoid clutter, taking the bias term into account can be achieved by extending the dimension of x and θ by an extra dimension.
A counterfactual plan is a set of J counterfactual explanations { x j } j =1 ,...,J , and we denote { x j } for short.
When J = 1 , we have a single counterfactual explanation problem, which is the subject of recent works (Ustun et al., 2019;
Karimi et al., 2020a; Upadhyay et al., 2021).
Next, we deﬁne the joint validity of a counterfactual plan.
Deﬁnition 1.1 (Joint validity) .
A counterfactual plan { x j } is valid with respect to a realization θ if
C θ ( x j ) = 1 for all j = 1 , . . .
, J .
Notations.
We use S d ++ ( S d + ) to denote the space of symmetric positive (semi)deﬁnite matrices.
For any A ∈ R m × m , the trace operator is Tr (cid:2)
A (cid:3) =
(cid:80) di
=1 A ii .
For any integer J , [ J ] (cid:44) { 1 , . . .
, J } .
V ALIDITY B OUNDS OF C OUNTERFACTUAL P LANS
In this section, we propose a diagnostic tool to benchmark the validity of a pre-computed counterfactual plan { x j } .
We model the random model parameters ˜ θ with a nominal distribution (cid:98) P .
Instead of making a strong assumption on a speciﬁc parametric form of (cid:98) P such as Gaussian distribution, we only assume that (cid:98) P is known only up to the second moment.
More speciﬁcally, we assume that under (cid:98) P , ˜ θ has a nominal mean vector (cid:98) µ and nominal covariance matrix (cid:98) Σ ∈ S d ++ .
Deﬁnition 2.1 (Gelbrich distance) .
The Gelbrich distance between two pairs ( µ 1 , Σ 1 ) ∈ R d × S d + and ( µ 2 , Σ 2 ) ∈ R d × S d + is deﬁned as
[Equation]
The Gelbrich distance is closely related to the optimal transport distance between Gaussian distributions.
Indeed, G (cid:0) ( µ 1 , Σ 1 ) , ( µ 2 , Σ 2 ) (cid:1) is equal to the type- 2 Wasserstein distance between two
Gaussian distributions N ( µ 1 , Σ 1 ) and N ( µ 2 , Σ 2 ) (Gelbrich, 1990).
It is thus trivial that G is a distance on R d × S d + , and as a consequence, it is symmetric and G (cid:0) ( µ 1 , Σ 1 ) , ( µ 2 , Σ 2 ) (cid:1)
=
if and only if ( µ 1 , Σ 1 ) = ( µ 2 , Σ 2 ) .
Using the Gelbrich distance to design the moment ambiguity set for distributionally robust optimization leads to many desirable properties such as computational tractability and performance guarantees (Kuhn et al., 2019; Nguyen et al., 2021a).
Motivated by this idea, we ﬁrst construct the following uncertainty set
[Equation]
which is formally a ρ -neighborhood in the mean vector-covariance matrix space around the nominal moment ( (cid:98) µ, (cid:98) Σ) .
The ambiguity set for the distributions of ˜ θ is obtained by lifting U to generate a family of probability measures that satisfy the moment conditions
[Equation]
[Equation]
U such that Q ∼ ( µ, Σ) } , where P is a set of all probability measures supported on R d and Q ∼ ( µ, Σ) indicates that Q has mean vector µ and covariance matrix Σ .
The central question of this section is: If the distribution of ˜ θ belongs to B , what is the probability that a given plan { x j } is valid?
To answer this question, we deﬁne the event set Θ( { x j } ) that contains all model parameter values that renders { x j } jointly valid.
Under the deﬁnition of a linear model, Θ( { x j } ) is an intersection of J open hyperplanes of the form
[Equation]
We name Θ( { x j } ) the set of favorable parameters.
The probability of validity for a plan under a measure Q is Q (˜ θ ∈ Θ( { x j } )) .
We are interested in evaluating the lower and the upper bound probability that the plan { x j } is valid uniformly over all distributions Q ∈ B .
This is equivalent to quantifying the following quantities
[Equation]
In the remainder of this section, we discuss how to evaluate the bounds for these terms.
Lower bound.
We denote by Θ ◦ the interior of the set Θ , that is, Θ ◦ ( { x j } ) (cid:44) (cid:8) θ ∈ R
d : x (cid:62) j θ > 0 ∀ j (cid:9) .
Note that all the inequalities deﬁning Θ ◦ ( { x j } ) are strict inequalities.
By deﬁnition, we have Θ ◦ ( { x j } ) ⊂
Θ( { x j } ) , and hence inf Q ∈ B Q (˜ θ ∈ Θ ◦ ( { x j } )) ≤ inf Q ∈ B Q (˜ θ ∈ Θ( { x j } )) .
Because Θ ◦ ( { x j } ) is an open set, we can leverage the generalized Chebyshev lower bound to evaluate the minimum quantity of Q (˜ θ ∈ Θ ◦ ( { x j } )) over all distributions with a given mean and covariance matrix (Vandenberghe et al., 2007).
Adding moment uncertainty via the set U is obtained by rejoining two minimization layers.
The next theorem presents this result.
Theorem 2.2 (Lower bound) .
For any ρ ∈ R + , (cid:98) µ ∈ R d and (cid:98) Σ ∈ S d + , let L (cid:63) be the optimal value of the following semideﬁnite program
[Equation]
Then we have
[Equation]
Upper bound.
Because Θ( { x j } ) is a closed set, we can leverage a duality result to evaluate the maximum quantity of Q (˜ θ ∈ Θ( { x j } )) over all distributions with a given mean and covariance matrix (Isii, 1960).
Adding moment uncertainty via the set U is obtained by invoking the support function of the moment set.
This result is presented in the next theorem
Theorem 2.3 (Upper bound) .
For any ρ ∈ R + , (cid:98) µ ∈ R d and (cid:98) Σ ∈ S d + , let U (cid:63) be the optimal value of the following semideﬁnite program
[Equation]
Σγ (cid:98) Σ
Q (cid:21) (cid:23) 0 , (cid:20) γI − Z γ (cid:98) µ + z γ (cid:98) µ (cid:62) + z (cid:62) q (cid:21) (cid:23)(cid:20)
Z z z (cid:62) z(cid:21) (cid:23) 0 , (cid:20)
Z z z (cid:62) z 0 −(cid:21) (cid:23) (cid:80)
j ∈
[ J ] λ j (cid:20)12 x
j 12 x (cid:62) j (cid:21) .
Then we have sup Q ∈ B Q (˜ θ ∈ Θ( { x j } ))
≤ U (cid:63) .
Thanks to the choice of the Gelbrich distance G , both optimization problems in Theorems 2.2 and 2. are linear semideﬁnite programs, and they can be solved efﬁciently by standard, off-the-shelf solvers such as MOSEK to high dimensions (MOSEK ApS, 2019).
Other choices of distance (divergence) are also available: for example, one may opt for the Kullback-Leibler (KL) type divergence between
Gaussian distribution to prescribe U as in Nguyen et al.
(2020) and Taskesen et al.
Unfortunately, the KL type divergence entails a log-determinant term, and the resulting optimization problems are no longer linear programs and are no longer solvable using MOSEK.
Equipped with L (cid:63) and U (cid:63) , we have the bounds
L (cid:63) ≤ Q ( { x j } is a valid plan ) ≤ U (cid:63) ∀ Q ∈ B on the validity of the counterfactual plans { x j } under the distributional ambiguity set B .
Complementary information.
The previous results show that we can compute the lower bound
L (cid:63) and upper bound U (cid:63) for the probability of validity by solving semideﬁnite programs.
We now show that the two quantities L (cid:63) and U (cid:63) are complementary to each other in a speciﬁc sense.
Proposition 2.4 (Complementary information) .
For any instance, either L (cid:63) = 0 or U (cid:63) = 1 .
More speciﬁcally, we have: (i)
If (cid:98) µ ∈ Θ( { x j } )
, then U (cid:63) = 1 , and (ii)
If (cid:98) µ (cid:54)∈ Θ( { x j } ) , then L (cid:63) = 0 .
Because L (cid:63) and U (cid:63) are bounds for a probability quantity, they are only informative when they are different from 0 and 1 .
Proposition 2.4 asserts that the upper bound U (cid:63) is trivial when (cid:98) µ ∈ Θ( { x j } ) , while the lower bound L (cid:63) becomes trival if (cid:98) µ (cid:54)∈ Θ( { x j } ) .
Next, we leverage these insights to improve the validity of a given counterfactual plan.
C OUNTERFACTUAL P LAN C ORRECTIONS
Given a counterfactual plan { x j } , it may happen that { x j } have low probability of being valid under random realizations of the future model parameter ˜ θ .
The diagnostic tools proposed in Sectionindicates that { x j } have low validity when the bounds are low, and we are here interested in correcting this plan such that the lower bounds L (cid:63) are increased.
Indeed, increasing L (cid:63) guarantees a higher conﬁdence that the plan is valid, should the distribution of ˜ θ belongs to the ambiguity set.
At this point, one may be tempted to optimize L (cid:63) directly with { x j } by ﬁrst converting problem (2) into a maximization problem, and then jointly maximize with { x j } being decision variables.
Unfortunately, this approach entails bilinear terms x (cid:62) j z j in the constraints, and this approach is notoriously challenging to solve.
We thus resort to heuristics for correction.
Towards this end, the results from
Proposition 2.4 suggest that there are two correction operations that we need to perform to improve the validity of the counterfactual plan:
(i) When (cid:98) µ (cid:54)∈ Θ( { x j } ) , then Proposition 2.4 suggests that we should modify the plan { x j } so that the resulting set of favorable parameters contains (cid:98) µ .
We term this type of correction as a Requirement correction, and we consider one speciﬁc Requirement correction in Section 3.1.
(ii) When (cid:98)
µ ∈ Θ( { x j } )
, we can also modify { x j } to as to increase the lower bound L (cid:63) .
This type of correction is termed an Improvement correction because its goal is to increase the validity of the counterfactual plans.
We consider the Mahalanobis Improvement correction in Section 3.2.
We emphasize that the corrections of the plan { x j } are designed such that the modiﬁcations to each counterfactual x
j should be minimal.
This is achieved by two main criteria: the correction should modify as few counterfactuals as possible, and the modiﬁcation to each counterfactual should also be as small as possible.
3. R EQUIREMENT C ORRECTION
We propose a Requirement correction with the goal of obtaining a corrected plan { x (cid:48)
j } from the given plan { x j } such that (cid:98) µ lies inside (or strictly inside) the set Θ( { x (cid:48) j } ) .
A simple Requirement correction is to construct the corrected plan { x (cid:48) j } by
[Equation]
for some (cid:15) ≥ 0 .
Using this rule, x (cid:48)
j is the smallest modiﬁcation of x j measured in the Euclidean distance such that x (cid:48)
j is valid with (cid:15) -margin with respect to the expected future parameter (cid:98) µ .
The margin (cid:15) adds a layer of robustness: if (cid:15) > 0 then (cid:98) µ lies in the interior of the set Θ( { x (cid:48) j } ) , while if (cid:15) =
then (cid:98) µ lies on the boundary of the set Θ( { x (cid:48) j } )) .
Moreover, it is easy to see that in the case (cid:98) µ (cid:62) x j < (cid:15) , the resulting x (cid:48)
j is the Euclidean projection of x j onto the hyperplane (cid:98) µ (cid:62) x
j = (cid:15) .
The proposed Requirement correction admits thus the analytical form:
[Equation]
3. M AHALANOBIS I MPROVEMENT C ORRECTION
Given a plan { x j } such that (cid:98) µ ∈ Θ( { x j } ) and an integer K between 1 and J , the Mahalanobis
Improvement correction aims to modify K out of J plans to obtain the corrected plan { x (cid:48) j } .
The goal of this correction is to increase the lower bound value L (cid:63) associated with the plan { x (cid:48)
j } , while at the same time keeping the amount of modiﬁcation as small as possible.
To attain this goal, we ﬁrst describe the geometric intuition behind the lower bound L (cid:63) in (2), and then leverage this intuition to generate the correction.
Geometric intuition.
We ﬁrst analyze the distribution of the random vector ˜ θ that attains the validity lower bound L (cid:63) .
To simplify the exposition, we assume that λ (cid:63) > 0 and deﬁne λ (cid:63)
= 1 − (cid:80) j λ (cid:63)j .
Following the same argument as in Vandenberghe et al.
(2007, § 2.2), the distribution of ˜ θ can be constructed as a mixture of J +random vectors ˜ θ j satisfying:
[Equation]
where for each j = 1 , . . .
, J , we have E [˜ θ j ] =
z (cid:63)j /λ (cid:63)j and ˜ θ 0 follows a properly chosen distribution.
By the validity of z (cid:63) , we can verify that the location z (cid:63)j /λ (cid:63)j lies on the hyperplane { θ : x (cid:62) j θ = 0 } .
Thus, we can think of λ (cid:63)j as the marginal increase in the lower bound L (cid:63) if we slightly perturb x j so that the point z (cid:63)j /λ (cid:63)j lies inside the set of favorable parameters.
This observation underlies the Mahalanobis correction which we describe next.
Correction procedure.
If we can adjust K out of J counterfactuals to improve the validity, then it is reasonable to modify the K counterfactuals associated with the K largest values of λ (cid:63)j , where λ (cid:63)j is the optimal value of the variable λ j in problem (2).
Without any loss of generality, assume that λ (cid:63)j have decreasing values, and in this case, our correction procedure will modify the counterfactuals x j for j = 1 , . .
, K .
Further, to correct each counterfactual, we ﬁnd x (cid:48)
j in a ∆ -neighborhood of x j such that the Mahalanobis distance from (cid:98) µ to the hyperplane { θ : θ (cid:62) x (cid:48)
j = 0 } is maximized, where the Mahalanobis distance is computed with the nominal covariance matrix (cid:98) Σ .
This is equivalent to solving a max-min problem
[Equation]
The next result indicates that x (cid:48)
j can be found by solving a conic optimization problem.
Theorem 3.1 (Mahalanobis Improvement correction) .
The Mahalanobis correction of x j is x (cid:48)
j = v (cid:63) /t
(cid:63) , where ( v (cid:63) , t (cid:63) ) is the optimal solution of the following conic optimization problem
[Equation]
We have speciﬁcally modiﬁed x (cid:48)
j in (3) with respect to the nominal mean vector and covariance matrix ( (cid:98) µ, (cid:98) Σ) of the random vector ˜ θ .
Alternatively, we can also use ( µ (cid:63) , Σ (cid:63) ) , where ( µ (cid:63) , Σ (cid:63) ) is the optimal solution in the variable ( µ, Σ) of (2) to form the optimization problem.
Theorem 3.1 holds with the corresponding parameters ( µ (cid:63) , Σ (cid:63) ) .
Similarly, equation (4) recovers the Euclidean projection if we use an identity matrix for weighting.
The conic optimization problem in Theorem 3.1 can be solved using standard off-the-shelf solvers such as Mosek (MOSEK ApS, 2019).
C OUNTERFACTUAL P LAN C ONSTRUCTION UNDER A MBIGUITY
We propose in this section the COunterfactual Plan under Ambiguity (COPA) framework to devise a counterfactual plan that has high validity under random future model parameters.
Given an input instance x 0 , COPA builds a plan { x j } of J ≥ 1 counterfactuals that balances between competing objectives including proximity, diversity and validity.
We next describe each cost component.
Proximity.
It is reasonable to ask that each counterfactual x j should be close to the input x 0 so that x j is actionable.
We suppose that the distance between x 0 and x j can be measured using a function c : R d × R d → R .
In general, the cost c is used to capture the ease of adopting the changes for a speciﬁc variable (e.g., one could barely change their height or race).
The proximity of a plan { x j } is simply the average distance from x 0 to each counterfactual in the plan.
More speciﬁcally, we have
[Equation]
Diversity.
We measure the diversity of a plan using the determinant point process (Kulesza, 2012) similar to the approach in Mothilal et al.
The diversity is given by:
[Equation]
where K
[Equation]
Then, a plan with a larger value Diversity( { x j } ) is more diverse.
Validity.
Given the moment information ( (cid:98) µ, (cid:98) Σ) , one potential approach to compute the validity of a plan { x j } is to compute the value L (cid:63) in (2).
However, for large covariate dimension d or high number of counterfactual J , the semideﬁnite program (2) becomes time-consuming to solve and is not practical.
This entails us to derive the a computationally efﬁcient proxy for the validity of { x j } .
Towards this goal, we use the volume of the maximum-volume ellipsoid with center (cid:98) µ and covariance (cid:98) Σ that can be inscribed in Θ( { x j } ) .
Following Boyd & Vandenberghe (2004, § 8.4.2), an ellipsoid with center (cid:98) µ , covariance matrix (cid:98) Σ and radius r can be written in the parametric form as
E ( (cid:98) µ, (cid:98) Σ) ( r ) = { (cid:98) Σ 1 2 u + (cid:98) µ : (cid:107) u (cid:107) 2 ≤ r } .
The validity of the plan { x j } is thus deﬁned as
Validity( { x [Equation] , (cid:98)
[Equation]
, (cid:98)
[Equation]
The next result asserts that the above validity measure can be re-expressed in closed form, which justiﬁes its computational efﬁciency.
Lemma 4.1 (Validity value) .
If (cid:98) µ ∈ Θ( { x j } ) , then Validity( { x j } , (cid:98) µ, (cid:98) Σ) =
min j (cid:98) µ (cid:62) x j / (cid:107) (cid:98) Σ 12 x j (cid:107) 2 .
Lemma 4.1 and the analysis in Proposition 2.4 also suggest that the counterfactual plan should satisfy (cid:98) µ ∈ Θ( { x j } ) so as to improve the validity.
Similar to Section 3.1, we will impose the constraints that (cid:98) µ (cid:62) x
j ≥ (cid:15) ∀ j for some margin (cid:15) ≥ 0 for validity purposes.
COPA framework.
Our COPA framework ﬁnds the counterfactual plan that minimizes the weighted sum of the proximity, the diversity and the validity measure.
More precisely, the COPA counterfactual plan is the minimizer of
[Equation]
for some non-negative parameters λ 1 and λ 2 .
The COPA problem (6) can be solved efﬁciently under mild conditions using a projected (sub)gradient descent algorithm.
A projected gradient descent algorithm can be used to solve the COPA problem (6).
The gradient of the objective function of (6) can be computed using auto-differentiation.
We now discuss further the projection operator.
Let X (cid:44) { x ∈ R d : (cid:98) µ (cid:62) x ≥ (cid:15) } , then the feasible set of the COPA problem (6) is a product space X J .
The projection operator Proj X J on the product set X J is decomposable into simpler projections onto individual set X as Proj X J
( { x (cid:48) j } )
=
{ Proj X ( x (cid:48) 1 ) , . . .
, Proj X ( x (cid:48) J ) } , where each individual projection is
[Equation]
Note that the second equality above follows from the analytical formula for the Euclidean projection onto a half-space, which was previously used in Section 3.1.
N UMERICAL E XPERIMENTS
In this section, we evaluate the correctness of our validity bounds and the performance of our corrections and our COPA framework on both synthetic and real-world datasets.
Our baseline for comparison is the counterfactual plan constructed from the state-of-the-art DiCE framework (Mothilal et al., 2020).
Throughout the experiments, we set the number of counterfactuals to J = 5 .
For DiCE, we use the default parameters recommended in the DiCE source code.
The Mahalanobis correction will use the counterfactual plan obtained by DiCE method with K = 3 and the perturbation limit ∆ is 0 . 1 .
In our COPA framework, we use Adam optimizer to implement Projected Gradient Descent and (cid:96) 2 -distance to compute perturbation cost between inputs.
[Figure] [Figure]
5. S YNTHETIC DATASET
We ﬁrst generate 1000 samples with two-dimensional features from two Gaussian distributions
N ( µ 0 , Σ 0 ) and N ( µ 1 , Σ 1 ) to create a synthetic dataset.
Each instance is labelled as 0 or 1 corresponding to the distribution that generated it.
For the Gaussian distributions, we use similar parameters as in Upadhyay et al.
(2021), where µ 0 =
[ − 2 , − 2] (cid:62) , µ 1 = [2 , 2] (cid:62) , Σ 0 = Σ 1 = 0 .
5 I with
I being the identity matrix.
This dataset is then used to train a logistic classiﬁer with the present parameter θ 0 .
This classiﬁer C θ 0 is ﬁxed for the experiments that follow.
The impact of Gelbrich radius on the validity.
Given a counterfactual plan generated by DiCE on the classiﬁer C θ 0 , we consider two scenarios: (cid:98) µ ∈ Θ( { x j } ) and (cid:98) µ / ∈ Θ( { x j } ) .
We choose (cid:98) µ = θfor the case (cid:98) µ ∈ Θ( { x j } ) and (cid:98) µ = − θ 0 , otherwise.
We also set (cid:98) Σ = 0 .
5 I .
We then compute the lower and upper validity bound of this plan with respect to different Gelbrich bounds ρ ∈ [0 , 1] .
To evaluate the empirical validity of this plan, we simulate 1000 futures for ˜ θ .
For each future, we generate µ g and Σ g randomly so that G (( (cid:98) µ, (cid:98) Σ) , ( µ g , Σ g )) ≤ 1 , and then we sample 10 6 values of ˜ θ ∼ N g ( µ g , Σ g ) .
The empirical validity of the plan for each future is the fraction of parameter samples from the future that the prescribed plan is valid.
We plot the 1000 empirical validity of the plan in Figure 3.
This result is consistent with our guarantees that the validity is between the two bounds.
We also observe that increasing ρ loosens the validity bounds.
The impact of degree of distribution shift on validity of a plan.
We explore the case (cid:98) µ ∈ Θ( { x j } ) , where (cid:98) µ = θ 0 and (cid:98) Σ = 0 .
5 I , to assess the impact of distribution shift to three algorithms DiCE, MahalanobisCrr, and COPA.
In this experiment, we run our COPA framework with λ 1 = 2 . 0 , λ 2 = 200 . 0 .
To assess the performance of three algorithms, we parameterize the ground truth distribution of the future parameters ˜ θ ∼ N ( µ g , Σ g ) as follows: µ g = (cid:98) µ + α [0 , − 1 , 0] (cid:62) ,
Σ g = (1 + β ) I .
Here, we simulate three types of distributional shift of the parameters ˜
θ : (1) mean shift ( α ∈ [0 , 1] , β = 0 ), (2) covariance shift ( α = 0 , β ∈ [0 , 3] ), and (3) mean and covariance shift ( ( α, β ) ∈ [0 , 1] × [0 , 3] ).
For each shift’s type, we generate 100 counterfactual plans corresponding to 100 original inputs x 0 and compute the empirical validity as previously described.
The average and conﬁdence range of the empirical validity are plotted in Figure 4.
This result shows the tendency of decreasing validity measure of all algorithms when increasing the Gelbrich distance between estimate and ground truth distribution.
However, COPA shows stability and robustness for all shift types.
The validity of DiCE deteriorates when the ground truth distribution is far from θ 0 .
Meanwhile, MahalanobisCrr increases the robustness of the plans obtained by DiCE signiﬁcantly.
5. R EAL - WORLD DATASETS
In this experiment, we evaluate the robustness of the counterfactual plans obtained by three frameworks on the real datasets.
We use three real-world datasets: German Credit (Dua & Graff, 2017;
Groemping, 2019), Small Bussiness Administration (SBA)
(Li et al., 2018), and Student performance (Cortez & Silva, 2008).
Each dataset contains two sets of data (the present data - D 1 and the shifted data D 2 ).
The shifted dataset D 2 could capture the correction shift (German credit), the temporal shift (SBA), or the geospatial shift (Student).
More details for each dataset are provided in Appendix.
Experimental settings.
For each present dataset D 1 , we train a logistic classiﬁer C θ 0 with parameter θ 0 on 80% of instances of the dataset and ﬁx this classiﬁer to construct counterfactual plans in whole experiment.
We generate 100 counterfactual plans for 100 original inputs and report the average of values of our evaluation metrics.
To estimate (cid:98) µ and (cid:98) Σ , we train 1000 different classiﬁers from the present dataset D 1 (each is trained on a random set containing 50% instances of D 1 ), then use the empirical mean and covariance matrix of the parameter.
We set Gelbrich radius ρ = 0 .
Metrics.
To compute the empirical validity in the shift dataset D 2 , we sample 50% instances of
D 2 1000 times to train 1000 different logistic classiﬁers.
We then report the empirical validity of a plan as the fraction of the classiﬁers with respect to which the plan is valid.
We also use the lower validity bound as a metric for evaluating the robustness of a plan.
We use the formula in (4) and (5) to measure the proximity and diversity of a counterfactual plan.
[Table]
Results.
The results in Table 1 show that our COPA framework achieves highest empirical validity,
L ∗ , and diversity (especially when increasing λ 2 ) in all evaluated datasets.
Comparing DiCE and
Mahalanobis correction, we can observe that the trade-off of proximity and diversity of Mahalanobis correction is relatively small as compared to its improvement in terms of validity.
C ONCLUSION
This paper studies the problem of generating counterfactual plans under the distributional shift of the classiﬁer’s parameters given the fact that the classiﬁcation model is usually updated upon the arrival of new data.
We propose an uncertainty quantiﬁcation tool to compute the bounds of the probability of validity for a given counterfactual plan, subject to uncertain model parameters.
Further, we introduce a correction tool to increase the validity of the given plan.
We also propose a COPA framework to construct a counterfactual plan by taking the model uncertainty into consideration.
The experiments demonstrate the efﬁciency of our methods on both synthetic and real-world datasets.
Further extensions, notably to incorporate nonlinearities, are presented in the appendix.
A P ROOFS A. P ROOFS OF S ECTION
Proof of Theorem 2.2.
For any ( µ, Σ) ∈ R d × S d + , let
[Equation]
denote the set of probability measures under which the random vector ˜ θ has mean µ and covariance matrix Σ .
The inﬁmum probability can be decomposed as
[Equation]
where the second equality follows from Vandenberghe et al.
By Malag ` o et al.
Proposition 2)
[Equation]
we have
[Equation]
s .
t .
[Equation]
t .
[Equation]
(cid:98)
[Equation]
(cid:21) (cid:23) 0 .
Hence, by combing two inﬁmum operators, we have inf
[Equation]
 
[Equation]
[Equation]
(cid:22) (cid:20) Σ
[Equation]
µµ (cid:62) µ µ (cid:62)
[Equation]
(cid:21) (cid:107) (cid:98) µ (cid:107) 2 −
[Equation]
(cid:98) µ (cid:62) µ [Equation] (cid:2) [Equation]
(cid:62)
[Equation] (cid:98) Σ − [Equation] C (cid:3)
[Equation]
ρ
[Equation]
(cid:20) Σ C C (cid:62) (cid:98) Σ (cid:21) (cid:23) 0 . In the last step, we add an auxiliary variable M ∈ S d + with the constraint M = Σ + µµ (cid:62) .
Note that this constraint can be replaced by M (cid:23) Σ + µµ (cid:62) without affecting the optimal value of the optimization problem.
Using the Schur complement, this constraint is equivalent to
[Equation]
This completes the proof.
Proof of Theorem 2.3.
Let 1 Θ ( θ ) be the indicator function of the set Θ( { x j } ) , that is,
[Equation]
By deﬁning the loss function (cid:96) ( θ ) =
1 Θ ( θ ) and let Z be the convex feasible set deﬁned by
[Equation]
Notice that Z is a closed and convex set because it is an intersection of uncountably many closed and covex sets.
Denote the following set V of mean - second moment matrices that is induced by U by
[Equation]
[Equation]
∃
[Equation]
µ, Σ) ∈ U such that ( µ, M ) =
( µ, Σ + µµ (cid:62) ) } .
The support function δ ∗V of the set V is deﬁned as
[Equation]
Using these notations, we now have
[Equation]
where equality (7a) is from the two layer decomposition of the ambiguity set B , and inequality (7b) is from the Isii’s duality result Isii (1960).
Equality (7c) follows from the Sion’s minimax theorem Sion (1958) which holds because the objective function is linear in each variable and because
V is compact by the compactness of U (Nguyen et al., 2021b, Lemma A.6).
We thus have
[Equation]
where the equality follows by substituting the support function of V in Kuhn et al.
(2019, Lemma 2).
Consider now the last constraint of the above optimization problem
[Equation]
it is easy to see that it is equivalent to
[Equation]
The ﬁrst semi-inﬁnite constraint is equivalent to the semideﬁnite constraints
[Equation]
A sufﬁcient condition for the second semi-inﬁnite constraint is that
[Equation]
which holds thanks to the S-lemma P´olik & Terlaky (2007)
Adding these above constraints into the optimization problem leads to the desired upper bound.
This completes the proof.
The proof of Proposition 2.4 relies on the following result on the multivariate Chebyshev inequalities, which can be found in Marshall & Olkin (1960) and Bertsimas & Popescu (2005).
Theorem A.1 (Multivariate Chebyshev inequality) .
Let S be a convex set, then
[Equation]
We are now ready to prove Proposition 2.4.
Proof of Proposition 2.4.
If (cid:98) µ ∈ Θ( { x j } ) , then it is clear that
[Equation]
thus we have U (cid:63) ≥
[Equation]
Q
[Equation]
˜ θ ∈ Θ( { x
[Equation]
1 by Theorem A.1.
This leads to U (cid:63) = 1 .
Consider the case when (cid:98) µ (cid:54)∈ Θ( { x j } ) .
By the hyperplane separation theorem, there exists a vector ¯ x ∈ R d such that ¯ x (cid:62) θ ≥ 0 for all θ ∈ Θ( { x j } ) and ¯ x (cid:62) (cid:98) µ < 0 .
Let T (cid:44) { θ : ¯ x (cid:62) θ ≥ 0 } , then it is trivial that Θ( { x j } ) ⊆ T and that T is a convex set.
We now have
[Equation]
where the penultimate equality follows from Theorem A.1.
This leads to L (cid:63) = 0 .
A. P ROOFS OF S ECTION
Proof of Theorem 3.1.
Notice that the optimal solution in x should satisfy x (cid:62) (cid:98) µ > 0 .
Fix any value of x (cid:54) = 0 .
Consider ﬁrst the inner minimization problem of (3), and associate with the equality constraint a Lagrangian dual variable ζ ∈ R , we have
[Equation]
where the second equality follows from convex duality result.
The third equality follows from the fact that for every value of ζ , the optimal solution in the variable θ is
[Equation]
Moreover, the last equality follows from the optimality condition in ζ which gives ζ (cid:63) = (cid:98) µ (cid:62) x/
( x (cid:62) (cid:98) Σ x ) .
Because the optimal solution in x should satisfy x (cid:62) (cid:98) µ > 0 , problem (3) is hence equivalent to
[Equation]
Adding now two auxiliary variables t ∈ R + and v ∈ R d with the constraints:
[Equation]
the claim in the statement of the theorem now follows by a simple substitution to get
[Equation]
Swapping the maximum operator to a minimum operator completes the proof.
A. P ROOFS OF S ECTION
Proof of Lemma 4.1.
From the deﬁnition of the set Θ( { x j } ) , we have
[Equation]
where the last equality follows from the dual norm property.
The proof now follows by ﬁnding the maximum value of r so that the problem is feasible.
B E XPERIMENTS B. E XPERIMENTAL DETAIL
Real-world datasets Here, we provide more detail about three real-world datasets we used.
Source code can be found at https://github.com/ngocbh/COPA .
i German Credit (Dua & Graff, 2017).
The dataset contains the information (e.g. age, gender, ﬁnancial status,...) of 1000 customers who took a loan from a bank.
The classiﬁcation task is to determine the risk (good or bad) of an individual.
There is another version of this dataset regarding to corrections of coding error (Groemping, 2019).
We use the corrected version of this dataset as a shifted data to capture correction shift.
The features we used in this dataset include ‘duration’, ‘amount’, ‘personal status sex’, and ‘age’.
ii Small Bussiness Administration (SBA)
(Li et al.,
This data includes 2,102 observations with historical data of small business loan approvals from 1987 to 2014.
We divide this dataset into two datasets (one is instances from 1989 - 2006 and one is instances from 2006 - 2014) to capture temporal shift.
We use the following features: selected, ‘Term’, ‘NoEmp’, ‘CreateJob’, ‘RetainedJob’, ‘UrbanRural’, ‘ChgOffPrinGr’, ‘GrAppv’, ‘SBA Appv’, ‘New’, ‘RealEstate’, ‘Portion’, ‘Recession’.
iii Student performance (Cortez & Silva, 2008).
This data includes the performance records ofstudents in two schools: Gabriel Pereira (GP) and Mousinho da Silveira (MS).
The classiﬁcation task is to determine if their ﬁnal score is above average or not.
We split this dataset into two sets in two schools to capture geospatial shift.
The features we used are: ‘age’, ‘Medu’, ‘Fedu’, ‘studytime’, ‘famsup’, ‘higher’, ‘internet’, ‘romantic’, ‘freetime’, ‘goout’, ‘health’, ‘absences’, ‘G1’, ‘G2’.
Classiﬁer Throughout this paper, we use a Logistic Regression for linear classiﬁer and a threelayer MLP with 20, 50, 20 nodes and ReLU activation in each consecutive layer as nonlinear classiﬁer.
We use one-hot encoding for categorical features in the datasets to convert it to a vector of [0 , 1] .
We use min-max normalization to scale the numerical features to [0, 1].
We report the performance of the classiﬁers in three real-world datasets in Table
B. A DDITIONAL EXPERIMENTS
The impact of degree of distribution shift on validity of a plan.
We provide an additional experiment in different covariance shift Σ g =
(1 + β ) A, A (cid:23) 0 .
In this experiment, we choose A as:
A =
(cid:32)− 1−     (cid:33) .
The matrix A introduces both positive and negative correlations between classiﬁer’s parameters.
Other settings are set the same as the experiment in Section 5.1.
[Table]
[Figure]
Mahalanobis correction on real-world dataset.
In this experiment, we evaluate the Mahalanobis correction on different number of corrections K and different perturbation limit ∆ .
We set ρ = 0 .
01 , (cid:15) = 0 .
1 , K ∈ { 0 , . . .
, J } , J = 5 , ∆ ∈ [0 . 05 , 0 . 35] .
( (cid:98) µ, (cid:98) Σ) is estimated using similar manner as in Section 5.2 of the main paper.
The results in shown in Figure 6.
Counterfactual explanations for real-world datasets.
To illustrate the use case of the counterfactual explanations, we provide some examples on the German dataset with J =
(Table 3) in which we consider the “personal status and sex” feature as immutable.
Here, we can observe that three algorithms could provide diverse sets of counterfactuals that the users may prefer.
However, by providing better empirical validity, the plans generated by MahalanobisCrr and COPA are more robust with distribution shift than DiCE (generated without considering the shift).
C E XTENSION TO NONLINEAR CLASSIFIERS
In the main paper, our analysis is based on the linearity in both features and model’s parameters.
We now discuss two extensions of our COPA framework to the nonlinear settings.
C. N ONLINEARITY IN I NPUT F EATURES
This section extends to any linear classiﬁer C θ ( x ) =
if θ (cid:62) φ ( x ) ≥ 0 , and 0 otherwise, where φ :
X → R d is a (possibly nonlinear) feature mapping that maps input features to a latent representation in a covariate space R d .
Note that our bounds in Section 2 still hold in latent space R d : for a concrete example, Theorem 2.2 holds with x j being replaced by φ ( x j ) .
The COPA framework is also extendable to incorporate the feature map φ .
Assuming that φ is differentiable, the COPA framework solves the following optimization problem:
[Equation]
The proximity and diversity are measured in the input space and the validity term is now measured in latent space space instead.
This optimization problem can be solved efﬁciently by a projected gradient descent algorithm similar to Section 4.
C. N ONLINEARITY IN M ODEL ’ S P ARAMETERS
Similar to the prior works (Ustun et al., 2019; Rawal & Lakkaraju, 2020; Upadhyay et al., 2021), our work can adapt to nonlinear classiﬁers C nl using a local surrogate models such as LIME (Ribeiro et al., 2016).
LIME (Ribeiro et al., 2016) is a popular technique for explaining predictions of blackbox machine learning models.
The main idea of LIME is to train a local surrogate model C x 0 θ on a perturbed samples around a given input instance x 0 to approximate the local decision boundary of the black-box models.
We thus model the uncertainty of parameters θ in the surrogate model C x 0 θ for x 0 instead of the parameters of C nl .
For the experiment, we ﬁrst generate a local linear model C x 0 θ using LIME method with 5000 perturbed samples.
We then choose ( (cid:98) µ, (cid:98) Σ) =
( θ, 0 . 05 I ) , where I is identity matrix, to model the [Table] distributional uncertainty of the parameters.
Similar to Section 5.2, we set Gelbrich radius ρ is to 0 .
01 , J = 5 , K = 3 .
[Table] [Table] We report the performance of three algorithms on the MLP classiﬁer in the real-world datasets in Table 4.
The result is promising since the proposed COPA can increase the empirical validity signiﬁcantly.
However, the inﬁdelity of LIME could lead to invalid counterfactual explanations, represented by a lower current validity value.
The low current validity is also observed in the literature, see Upadhyay et al.
For further investigation, one can use another local surrogate model that provides a better approximation of the decision boundary (e.g., BayLIME (Zhao et al., 2020)).
Another direction is to use a mixture linear regression model to approximate the decision boundary as in Guo et al.
However, advocating for the mixture of linear models requires further analysis.