{'fraction_non_alphanumeric': 0.02673992673992674, 'fraction_numerical': 0.008110936682365254, 'mean_word_length': 5.011638880150991, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Interpretable Credit Application Predictions With Counterfactual Explanations

We predict credit applications with off-the-shelf, interchangeable black-box classifiers and we explain single predictions with counterfactual explanations. Counterfactual explanations expose the minimal changes required on the input data to obtain a different result e.g., approved vs rejected application. Despite their effectiveness, counterfactuals are mainly designed for changing an undesired outcome of a prediction i.e. loan rejected. Counterfactuals, however, can be difficult to interpret, especially when a high number of features are involved in the explanation. Our contribution is two-fold: i) we propose positive counterfactuals, i.e. we adapt counterfactual explanations to also explain accepted loan applications, and ii) we propose two weighting strategies to generate more interpretable counterfactuals. Experiments on the HELOC loan applications dataset show that our contribution outperforms the baseline counterfactual generation strategy, by leading to smaller and hence more interpretable counterfactuals.


Introduction
Explaining predictions of black box models is of uttermost importance in the domain of credit risk assessment Bruckner [2018]. The problem is even more prominent given the recent right to explanation introduced by the European General Data Protection Regulation Goodman and Flaxman [2016], and a must due to regulation in the financial domain. A common approach to explain black box predictions focuses on generating local approximations of decisions. If f is a machine learning model taking the features X and mapping them to targets Y , then the goal is to find a subdomain of the feature variables and over that domain approximate f ∼ g, where g is an interpretable and easy to understand function. There has been recent interest in model-agnostic methods of explainability. These methods look to create an explainer that should be able to explain any model treating the underlying model as a black box. Ribeiro et al. [2016a]. Wachter et al. [2017], one of these modelagnostic methods. A counterfactual explanation may justify a rejected loan application as follows:

This paper focuses on Counterfactual Explanations
Your application was denied because your annual income is $30,000 and your current balance is $200. If your income had instead been $35,000 and your current balance had been $400 and all other values remained constant, your application would have been approved.
The explanation describes the required minimum change in inputs to flip the decision of the black box classifier. Note that the latter remains a black box: it is only through changing inputs and outputs that an explanation is obtained. Despite their effectiveness, two problems arise: on one hand counterfactuals are inherently designed to describe what it takes to flip the decision of a classifier, hence they poorly address the case in which the decision was satisfactory from an end user perspective (e.g. loan approved). Problems also arise when assessing the interpretability of counterfactuals: the generated counterfactuals often suggest to change a high number of features, therefore leading to less intelligible explanations. For example, counterfactuals generation strategies do not take into account the importance of the dataset features, thus underestimating or overestimating certain dimensions. This problem is of particular importance given that it has been showed that human short-term memory is unable to retain a large number of information units Vogel et al. [2001], Alvarez and Cavanagh [2004]. This remains as problematic in the finance domains of loan approval when data scientis and regulators are in the loop.
We predict loan applications with off-the-shelf, interchangeable black-box estimators, and we explain their predictions with counterfactual explanations. To overcome the aforementioned problems, we present the following contribution: • Positive Counterfactuals: in case of a desired outcome, we interpret counterfactuals as a safety margin, i.e. a tolerance from the decision boundary. Such counterfactual explanations for positive predictions answer the question "How much was I accepted by?".
• Weighted Counterfactuals: inspired by Huysmans et al. Huysmans et al. [2011], we use the size of explanations as a proxy to measure their interpretability. To obtain more compact (and hence more intelligible) counterfactuals we introduce weights in the their generation strategy. We propose two weighting strategies: one based on global feature importance, the other based on nearest neighbours.
We experiment on a credit application dataset and show that our weighted counterfactuals generation strategies lead to smaller counterfactuals (i.e. counterfactuals that suggest to change a smaller number of features), thus delivering more interpretable explanations.

Related Work
Local Interpretability A number of works focus on explaining single predictions of machine learning models, rather than the model as a whole. This task is also known as local interpretability. White box models come with local explanations by design: traditional transparent design approaches include decision trees and rule extraction Guidotti et al. [2018], Molnar [2018]. In that respect some works such as Craven and Shavlik [1995] built surrogate models by interfacing complex models such as deep neural networks with more interpertable models such as decision trees. The authors aim at mimicing the behaviour of a complex model with a much simpler model for interpretability purpose. Other approaches are instead model-agnostic, and also address explanations of predictions of black box models. LIME generates local explanations from randomly generated neighbours of a  Kurakin et al. [2016] are another example-based approach, but they are designed to flip the decision of a black-box predictor rather than explaining it. Counterfactual explanations are also an example-based strategy, but unlike adversarial examples, they inform on how a record features must change to radically influence the outcome of the prediction.
Interpretable Credit Risk Prediction Providing a comprehensive review of more than 20 years of research in credit risk prediction models is out of the scope of this paper. The survey by Lyn et al. Thomas et al. [2017] gives a comprehensive and up-to-date overview). Huang et al. Huang et al. [2004] briefly mention an explanation of predictive models for credit rating, but their survey limits to ranking features by importance with variance analysis. A more recent survey by Louzada  Although they evaluate the predictive power of their models they do not attempt to explain their predictions, either locally or globally. To the best of our knowledge, no work in literature focuses on local interpretability for black box models applied to credit risk prediction.

Preliminaries: Counterfactual Explanations
A counterfactual explanation describes a generic causal situation in the form: , and all other variables had remained constant, score y ′ would have been returned.
Counterfactuals do not need to know the internal structure or state of model or system (e.g. neural network, logistic regression, support vector machine, etc). We treat f as a black box that takes the feature vector x and generates the outcome y, and we determine what is the closest x ′ to x that would change the outcome of the model from y to the desired y ′ (Figure 1). When generating counterfactuals it is assumed that the model f , the feature vector x and the desired output y ′ are provided. The challenge is finding x ′ , i.e. an hypothetical input vector which falls close to x but also for which f (x ′ ) falls sufficiently close to y ′ .
Generating Counterfactuals. We generate counterfactual explanations by calculating the smallest possible change (∆X) that can be made to the input X, such that the outcome flips from y to y ′ . We generate counterfactuals by optimizing the following loss function L, as proposed by Wachter et al. Wachter et al. [2017]: arg min where x is the actual input vector, x ′ is counterfactual vector, y ′ is the desired output state,f (...) is the trained model, λ is the balance weight. λ balances the counterfactual between obtaining the exact desired output and making the smallest possible changes to the input vector x. Larger values for λ favor counterfactuals x ′ which result in af (x ′ ) that comes close to the desired output y ′ , while smaller values lead to counterfactuals x ′ that are very similar to x. The distance metric d(x, x ′ ) measures ∆x, i.e. the amount of change between x and x ′ . We use the Manhattan distance weighted feature-wise with the inverse median absolute deviation (MAD) 3. Such metric is robust to outliers, and introduces sparse solutions where most entries are zero Wachter et al. [2017]. Indeed, the ideal counterfactual is one in which only a small number of features change and the majority of them remain constant. The distance metric d(x, x ′ ) can be written as: M AD j = median i∈{1,...,n} x i,j − median l∈{1,...,n} (x l,j ) .
To generate counterfactuals we adopt the iterative approach described in Algorithm 1. We optimize L with the Nelder-Mead algorithm, as suggested in Molnar [2018]. We constrain the optimisation with a tolerance ε s.t |f (x ′ ) − y ′ | ≤ ε. The value for ε depends on the problem space and is determined by the range and scale of y.
Step 3 iterates over λ until the ε constraint is satisfied. A check is performed for a value greater than ε as increasing λ will place more weight on obtaining anf (x ′ ) closer to the given desired output y ′ . Once an acceptable value for λ is obtained for the given x and y ′ a set of counterfactuals can be obtained by repeating steps 1 and 2 with the calculated λ. Note that we constrain the features manually, since the heuristic in Algorithm 1 and the adopted optimization algorithm are designed for unconstrained optimization.

Contribution
In this section we describe our two main contributions made towards the explainability of black box machine learning pipelines that predict credit decisions. Using positive counterfactuals we explain why a loan was accepted and provide details that help inform an individual when making future financial decisions. Next we present weighted counterfactuals that aim at personalizing the counterfactual recommendations that are provided to individuals that received an undesirable outcome (i.e. their loan was denied).

Counterfactuals for positive predictions
In order to explain why applications were accepted, we applied counterfactuals to the scenario where the individual received the desired outcome, i.e positive counterfactuals. Here instead of answering the question "Why wasn't I accepted?" we focus on the question of "How much was I accepted by?". Such approach informs the individual about the features and value ranges that were important for their specific application, thus favouring more informed decisions about potential future financial activities. For example, if the individual is considering an action that may temporarily increase their number of delinquencies then, armed with positive counterfactuals, they will have a better understanding of the impact on future loan applications.
In the binary classification case we achieve positive counterfactuals by setting the target y ′ to be the decision boundary i.e P (y = 1) = 0.5. This allows us to identify the locally important features that would push the individual to the threshold of being accepted. Another way of viewing this is that these are the features that locally contribute to the desired outcome.
We present this information to the individual and display it as tolerance. In Figure 2 this is illustrated by a dashed line. Given that future actions do not reduce the indicated features below the dashed line, and all other features remain constant, then the individuals application should remain likely to be approved.

Weighted Counterfactuals
The general implementation of counterfactuals described in Section 3 assumes all features are equally important and changing each feature is equally viable. This, however, is not necessarily the case. For each feature its ability to change and the magnitude of the change may vary on a case by case bases. In order to capture this information and create more interpretable actionable recommendations, the generated counterfactuals need to take this into consideration. For example some individuals may be able to increase their savings, while others instead may find it easier to reduce their current expenses. There are also cases where some features may be fixed or immutable.
Features like the number of delinquencies in the last six months is historical and fixed. Recommending to change these types of features would be of little use. Our intuition is that promoting highly discriminative features during the generation of counterfactuals leads to more compact, hence better interpretable explanations Huysmans et al. [2011].
We address these issues by introducing a weight vector θ to the distance metric defined in Equation 3. This vector promotes highly discriminative features.
We propose two different strategies to generate these weight vectors. The first relies on the global feature importance, the second relies on a Nearest Neighbors approach. The goal is obtaining coun-terfactuals that suggest a smaller number of changes or focus on values that are relevant to the individual and have historically been shown to vary.
Global feature importance. We compute global feature importance using analysis of variance (ANOVA F-values) between each feature and the target, and we create a weight vector that promotes highly discriminative features. Our goal is obtaining a smaller set of features in the resulting counterfactual recommendation, thus obtaining more compact explanations.
K-Nearest Neighbors. The second approach uses K-Nearest Neighbors to find cases that are close to the individual but have achieved the desired results. Looking at the nearest neighbors and aggregating over the relative changes we build a weight vector θ that captures the locally important features for this individual that have historically been shown to change. Here we aim to find counterfactuals containing features that are more actionable by the individual. By using K-Nearest Neighbors approach these weights can be automatically learned when applied to new problem spaces.

Experiments
We perform a a binary classification task on a credit application dataset. We train a range of black box models and we explain their predictions with counterfactuals, the goal being explaining the classifier decision to reject or accept a loan application. We perform two separate experiments: first, we carry out a preliminary evaluation of the predictive power of our pipeline. This is not the primary focus of this paper, but it is a required step to gauge the quality of predictions. In a second experiment, we assess the size of counterfactuals generated by our weighted counterfactuals generation.

Experimental Settings
Dataset. We experiment with the HELOC (Home Equity Line of Credit) credit application dataset. Used in the FICO 2018 xML Challenge 1 , it includes anonymized credit applications made by real homeowners. We drop highly correlated features and filter duplicate records. After pre-processing we obtain 9,870 records (of which 5,000 positives, i.e. accepted credit applications), and 22 distinct features.
Implementation Details. Our machine learning pipeline is written in Python 3.6. This includes preprocessing, training, counterfactuals generation, and performance evaluation. We use scikit-learn 0.20 for the black box classifiers 2 . All experiments were run under Ubuntu 16.04 on an Intel Xeon E5-2620 v4 2.10 GHz workstation with 32 GB of system memory.

Results
Predictive Power As preliminary experiment, we assess the predictive power of four classifiers: logistic regression (LogReg), gradient boosting (GradBoost), support vector machine with linear kernel (SVC), and multi-layer perceptron (MLP). Logistic regression apart, the others fall within the black box category. We perform 3-fold, cross-validated grid search model selection over a number of hyperparameters. We adopt balanced class weights for logistic regression, exponential loss for gradient boosting, for each dataset. SVM uses balanced weights, C = .001. The neural network uses one hidden layer with 22 units. We use the logistic activation function. Where not specified, we rely on scikit-learn defaults. Results in Table 1 show the predictive power of the best models. Metrics are 3-fold cross-validated.
Counterfactuals Size The preliminarily results of the different weighting strategies as described in Section 4.2 are presented in Table 2. We experiment with 5,000 loan applications in the dataset: we generate a counterfactual explanation for each of them, and compute the average counterfactuals size. Results show that both weighted strategies bring counterfactuals that have a smaller mean and standard deviation. We also observed that in general the average size of the counterfactual recommendations can vary dramatically for the same data given the underlying model.  In general the global feature importance results in features with a lower mean and standard deviation. We obtain explanations which are 11.2% smaller on average using the global feature importance strategy against the baseline. This is to be expected, as we promote more discriminative features and as a consequence less ancillary features are required. The benefit in the KNN approach is that the counterfactuals are weighted on the features that are locally important. Here we see that while they may not be the best approach they never perform worse than the baseline. The benefit of the weighting strategies comes with helping the optimization process converge on a local optimum when the underlying space is complex. We look to investigate this claim in future work.

Conclusion
We explain credit application predictions obtained with black box models with counterfactuals. In case of positive prediction, we show how counterfactuals can be interpreted as a safety margin from the decision boundary. We propose two weighted strategies to generate counterfactuals: one derives weights from features importance, the other relies on nearest neighbours. Experiments on the HELOC loan applications dataset show that weights generated from feature importance lead to more compact counterfactuals, therefore offering more compact and intelligible explanations for end users. Future work will focus on validating the effectiveness of our counterfactual explanations against human-grounded and application-grounded evaluation protocols (including the claim that smaller counterfactuals are indeed more interpretable). We will also experiment with weighting strategies that rely on model-specific feature importance, i.e. effect of feature perturbation on entropy of changes in predictions.