Skip to content
ImagineWorld

Interpretation, Interpretability, and Explainability; and Why Does It All Matter?

node_idnode-book_interpretable-machine-learning-with-python-second-edition_chapter-01-interpretation-interpretability-and-explainability-and-why-does-it-all-matter
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num1
chapter_titleInterpretation, Interpretability, and Explainability; and Why Does It All Matter?
pillar_membershipJ — architecture_design_craft
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 1 — Interpretation, Interpretability, and Explainability; and Why Does It All Matter?

Section titled “Chapter 1 — Interpretation, Interpretability, and Explainability; and Why Does It All Matter?”

The title of this book suggests its central themes: interpretation, machine learning, and Python, with the first theme being the most crucial.

So, why is interpretation so important?

Interpretable machine learning, often referred to as Explainable AI (XAI), encompasses a growing array of techniques that help us glean insights from models, aiming to ensure they are safe, fair, and reliable – a goal I believe we all share for our models.

With the rise of AI superseding traditional software and even human tasks, machine learning models are viewed as a more advanced form of software. While they operate on binary data, they aren’t typical software; their logic isn’t explicitly coded by developers but emerges from data patterns. This is where interpretation steps in, helping us understand these models, pinpoint their errors, and rectify them before any potential mishaps. Thus, interpretation is essential in fostering trust and ethical considerations in these models. And it’s worth noting that in the not-so-distant future, training models might move away from coding to more intuitive drag-and-drop interfaces. In this context, understanding machine learning models becomes an invaluable skill.

Currently, there’s still a significant amount of coding involved in data preprocessing, exploration, model training, and deployment. And while this book is rich with Python examples, it’s not merely a coding guide removed from practical applications or the bigger picture. The book’s essence is to prioritize the why before the how when it comes to interpretable machine learning, as interpretation revolves around the question of why.

Therefore, most chapters of this book kickoff by outlining a mission (the why) and then delving into the methodology (the how). The aim is to achieve the mission using the techniques discussed in the chapter, with an emphasis on understanding the results. The chapters wrap up by pondering on the practical insights gained from the exercises.

The structure of this book is progressive, starting from the basics and moving to more intricate topics. The tools utilized in this book are open source and are products of leading research institutions like Microsoft, Google, and IBM. Even though interpretability is a vast research field with many aspects still in the developmental phase, this book doesn’t aim to cover it all. Its primary goal is to delve deeply into a selection of interpretability tools, making it beneficial for those working in the machine learning domain.

The book’s initial section introduces interpretability, emphasizing its significance in the business landscape and discussing its core components and challenges. The subsequent section provides a detailed overview of various interpretation techniques and their applications, whether it’s for classification, regression, tabular data, time series, images, or text. In the final section, readers will engage in practical exercises on model tuning and data training for interpretability, focusing on simplifying models, addressing biases, setting constraints, and ensuring dependability.

By the book’s conclusion, readers will be adept at using interpretability techniques to gain deeper insights into machine learning models.

This book caters to a diverse audience, including:

  • Data professionals who face the growing challenge of explaining the functioning of AI systems they create and manage and seek ways to enhance them.
  • Data scientists and machine learning professionals aiming to broaden their expertise by learning model interpretation techniques and strategies to overcome model challenges from fairness to robustness.
  • Aspiring data scientists who have a basic grasp of machine learning and proficiency in Python.
  • AI ethics officers aiming to deepen their knowledge of the practical aspects of their role to guide their initiatives more effectively.
  • AI project supervisors and business leaders eager to integrate interpretable machine learning in their operations, aligning with the values of fairness, responsibility, and transparency.

Chapter 1, Interpretation, Interpretability, and Explainability; and Why Does It All Matter?, introduces machine learning interpretation and related concepts, such as interpretability, explainability, black-box models, and transparency, providing definitions for these terms to avoid ambiguity. We then underpin the value of machine learning interpretability for businesses.

Chapter 2, Key Concepts of Interpretability, uses a cardiovascular disease prediction example to introduce two fundamental concepts (feature importance and decision regions) and the most important taxonomies used to classify interpretation methods. We also detail what elements hinder machine learning interpretability as a primer for what lies ahead.

Chapter 3, Interpretation Challenges, discusses the traditional methods used for machine learning interpretation for regression and classification with a flight delay prediction problem. We will then examine the limitations of these traditional methods and explain what makes “white-box” models intrinsically interpretable and why we cannot always use white-box models. To answer this question, we consider the trade-off between prediction performance and model interpretability. Finally, we will discover some new “glass-box” models that attempt to not compromise in this trade-off.

Chapter 4, Global Model-Agnostic Interpretation Methods, explores Partial Dependence Plots (PDP) and game-theory-inspired SHapley Additive exPlanations (SHAP) with used car pricing regression models, then visualizes conditional marginal distribution Accumulated Local Effects (ALE) plots.

Chapter 5, Local Model-Agnostic Interpretation Methods, covers local interpretation methods, explaining a single or a group of predictions. To this end, the chapter covers how to leverage SHAP and Local Interpretable Model-agnostic Explanations (LIME) for local interpretations with a chocolate bar rating example, with both tabular and text data.

Chapter 6, Anchors and Counterfactual Explanations, continues with local model interpretations, but only for classification problems. We use a recidivism risk prediction example to understand how we can explain unfair predictions in a human-interpretable way. This chapter covers anchors, counterfactuals, and the What-If-Tool (WIT).

Chapter 7, Visualizing Convolutional Neural Networks, explores interpretation methods that work with Convolutional Neural Network (CNN) models with a garbage classifier model. Once we have grasped how a CNN learns with activations, we will study several gradient-based attribution methods, such as saliency maps, Grad-CAM, and integrated gradients, to debug class attribution. Lastly, we will extend our attribution debugging know-how with perturbation-based attribution methods such as feature ablation, occlusion sensitivity, Shapley value sampling, and KernelSHAP.

Chapter 8, Interpreting NLP Transformers, discusses how to visualize attention mechanisms in a restaurant review sentiment classifier transformer model, followed by interpreting integrated gradient attributions and exploring the Learning Interpretability Tool (LIT).

Chapter 9, Interpretation Methods for Multivariate Forecasting and Sensitivity Analysis, uses a traffic forecasting problem and Long Short-Term Memory (LSTM) models to show how to employ integrated gradients and SHAP for this use case. Lastly, the chapter looks at how forecasting and uncertainty are intrinsically linked, and sensitivity analysis – a family of methods designed to measure the uncertainty of a model’s output in relation to its input. We study two methods: Morris for factor prioritization and Sobol for factor fixing.

Chapter 10, Feature Selection and Engineering for Interpretability, uses a challenging non-profit direct mailing optimization problem to review filter-based feature selection methods, such as Spearman’s correlation and learn about embedded methods, such as Lasso. Then, you will discover wrapper methods, such as sequential feature selection and hybrid ones, such as recursive feature elimination, as well as more advanced ones, such as genetic algorithms. Lastly, even though feature engineering is typically conducted before selection, there’s value in exploring feature engineering for many reasons after the dust has settled.

Chapter 11, Bias Mitigation and Causal Inference Methods, takes a credit card default problem to demonstrate leveraging fairness metrics and visualizations to detect undesired bias. Then, the chapter looks at how to reduce it via preprocessing methods such as reweighting and prejudice remover for in-processing and equalized odds for post-processing. Then, we test treatments for lowering credit card default and leverage causal modeling to determine their Average Treatment Effects (ATE) and Conditional Average Treatment Effects (CATE). Finally, we test causal assumptions and the robustness of estimates.

Chapter 12, Monotonic Constraints and Model Tuning for Interpretability, continues with the recidivism risk prediction problem from Chapter 7. We will learn how to place guardrails with feature engineering on the data side and monotonic and interaction constraints on the model to ensure fairness while also learning how to tune a model when there are several objectives.

Chapter 13, Adversarial Robustness, uses a face mask detection problem to cover an end-to-end adversarial solution. An adversary can purposely thwart a model in many ways, and we focus on evasion attacks, such as Carlini and Wagner infinity-norm and adversarial patches, and briefly explain other forms of attack. We explain two defense methods: spatial smoothing preprocessing and adversarial training. Lastly, we demonstrate a robustness evaluation method.

Chapter 14, What’s Next for Machine Learning Interpretability?, summarizes what was learned in the context of the ecosystem of machine learning interpretability methods. And then speculates on what’s to come next!


We live in a world whose rules and procedures are ever-increasingly governed by data and algorithms.

For instance, there are rules about who gets approved for credit or released on bail, and which social media posts might get censored. There are also procedures to determine which marketing tactics are most effective and which chest x-ray features might diagnose a positive case of pneumonia.

We expect this because it is nothing new!

But not so long ago, rules and procedures such as these used to be hardcoded into software, textbooks, and paper forms, and humans were the ultimate decision-makers. Often, it was entirely up to human discretion. Decisions depended on human discretion because rules and procedures were rigid and, therefore, not always applicable. There were always exceptions, so a human was needed to make them.

For example, if you apply for a mortgage, your approval depended on an acceptable and reasonably lengthy credit history. This data, in turn, would produce a credit score using a scoring algorithm. Then, the bank had rules that determined what score was good enough for the mortgage you wanted. Your loan officer could follow it or not.

These days, financial institutions train models on thousands of mortgage outcomes, with dozens of variables. These models can be used to determine the likelihood that you would default on a mortgage with a presumed high accuracy. If there is a loan officer to stamp the approval or denial, it’s no longer merely a guideline but an algorithmic decision. How could it be wrong? How could it be right? How and why was the decision made?

Hold on to that thought because, throughout this book, we will be learning the answers to these questions and many more!

Machine learning model interpretation enables you to understand the logic behind a decision and trace back the detailed steps of the process behind the logic. This chapter introduces machine learning interpretation and related concepts, such as interpretability, explainability, black-box models, and transparency. This chapter provides definitions for these terms to avoid ambiguity and underpins the value of machine learning interpretability. These are the main topics we are going to cover:

  • What is machine learning interpretation?
  • Understanding the difference between interpretation and explainability
  • A business case for interpretability

Let’s get started!

To follow the example in this chapter, you will need Python 3, either running in a Jupyter environment or in your favorite integrated development environment (IDE) such as PyCharm, Atom, VSCode, PyDev, or Idle. The example also requires the pandas, sklearn, matplotlib, and scipy Python libraries.

The code for this chapter is located here: https://packt.link/Lzryo.

To interpret something is to explain the meaning of it. In the context of machine learning, that something is an algorithm. More specifically, that algorithm is a mathematical one that takes input data and produces an output, much like with any formula.

Let’s examine the most basic of models, simple linear regression, illustrated in the following formula:

Once fitted to the data, the meaning of this model is that predictions are a weighted sum of the x features with the β coefficients. In this case, there’s only one x feature or predictor variable, and the y variable is typically called the response or target variable. A simple linear regression formula single-handedly explains the transformation, which is performed on the input data x1 to produce the output . The following example can illustrate this concept in further detail.

Understanding a simple weight prediction model

Section titled “Understanding a simple weight prediction model”

If you go to this web page maintained by the University of California, http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_Dinov_020108_HeightsWeights, you can find a link to download a dataset of 25,000 synthetic records of the weights and heights of 18-year-olds. We won’t use the entire dataset but only the sample table on the web page itself with 200 records. We scrape the table from the web page and fit a linear regression model to the data. The model uses the height to predict the weight.

In other words, x1= height and y= weight, so the formula for the linear regression model would be as follows:

weight=β0+β1×heightweight = \beta_0 + \beta_1 \times height

You can find the code for this example here: https://github.com/PacktPublishing/Interpretable-Machine-Learning-with-Python-2E/blob/main/01/WeightPrediction.ipynb.

To run this example, you need to install the following libraries:

  • pandas to load the table into a DataFrame
  • sklearn (scikit-learn) to fit the linear regression model and calculate its error
  • matplotlib to visualize the model
  • scipy to test the correlation

You should load all of them first, as follows:

import math
import requests
from bs4 import BeautifulSoup
import pandas as pd
from sklearn import linear_model
from sklearn.metrics import mean_absolute_error
import matplotlib.pyplot as plt
from scipy.stats import pearsonr

Once the libraries are all loaded, you use pandas to fetch the contents of the web page, like this:

url = \
'http://wiki.stat.ucla.edu/socr/index.php/SOCR_Data_Dinov_020108_HeightsWeights'
page = requests.get(url)
height_weight_df = pd.read_html(url)[1][​['Height(Inches)','Weight(Pounds)']​]

pandas can turn the raw HyperText Markup Language (HTML) contents of the table into a DataFrame, which we subset to only include only two columns. And voilà! We now have a DataFrame with Heights(Inches) in one column and Weights(Pounds) in another.

Now that we have the data, we must transform it so that it conforms to the model’s specifications. sklearn needs it as numpy arrays with (200,1) dimensions, so we must first extract the Height(Inches) and Weight(Pounds) pandas series. Then, we turn them into (200,) numpy arrays, and, finally, reshape them into (200,1) dimensions. The following commands perform all the necessary transformation operations:

x = height_weight_df['Height(Inches)'].values.reshape(num_records, 1)
y = height_weight_df['Weight(Pounds)'].values.reshape(num_records, 1)

Then, we initialize the scikit-learn LinearRegression model and fit it with the training data, as follows:

model = linear_model.LinearRegression().fit(x,y)

To output the fitted linear regression model formula in scikit-learn, you must extract the intercept and coefficients. This is the formula that explains how it makes predictions:

print("ŷ =" + str(model.intercept_[0]) + " + " +\
str(model.coef_.T[0][0]) + " x₁")

The following is the output:

ŷ = -106.02770644878132 + 3.432676129271629 x1

This tells us that, on average, for every additional pound, there are 3.4 inches of height.

However, explaining how the model works is only one way to explain this linear regression model, and this is only one side of the story. The model isn’t perfect because the actual outcomes and the predicted outcomes are not the same for the training data. The difference between them is the error or residuals.

There are many ways of understanding an error in a model. You can use an error function such as mean_absolute_error to measure the deviation between the predicted values and the actual values, as illustrated in the following code snippet:

y_pred = model.predict(x)
print(mean_absolute_error(y, y_pred))

A 7.8 mean absolute error means that, on average, the prediction is 7.8 pounds from the actual value, but this might not be intuitive or informative. Visualizing the linear regression model can shed some light on how accurate these predictions truly are.

This can be done by using a matplotlib scatterplot and overlaying the linear model (in blue) and the mean absolute error (as two parallel bands in gray), as shown in the following code snippet:

plt.scatter(x, y, color='black')
plt.plot(x, y_pred, color='blue', linewidth=3)
plt.plot(x, y_pred + mae, color='lightgray')
plt.plot(x, y_pred - mae, color='lightgray')

If you run the preceding snippet, the plot shown here in Figure 1.1 is what you get as the output:

Figure 1.1 – Linear regression model to predict weight based on height

Figure 1.1: Linear regression model to predict weight based on height

As you can appreciate from the plot in Figure 1.1, there are many times in which the actuals are 20–25 pounds away from the prediction. Yet the mean absolute error can fool you into thinking that the error is always closer to 8. This is why it is essential to visualize the error of the model to understand its distribution. Judging from this graph, we can tell that there are no red flags that stand out about this distribution, such as residuals being more spread out for one range of heights than for others. Since it is more or less equally spread out, we say it’s homoscedastic. In the case of linear regression, this is one of many model assumptions you should test for, along with linearity, normality, independence, and lack of multicollinearity (if there’s more than one feature). These assumptions ensure that you are using the right model for the job. In other words, the height and weight can be explained with a linear relationship, and it is a good idea to do so, statistically speaking.

With this model, we are trying to establish a linear relationship between x height and y weight. This association is called a linear correlation. One way to measure this relationship’s strength is with Pearson’s correlation coefficient. This statistical method measures the association between two variables using their covariance divided by their standard deviations. It is a number between -1 and 1 whereby the closer the number is to 0, the weaker the association is. If the number is positive, there is a positive association, and if it’s negative, there is a negative one. In Python, you can compute Pearson’s correlation coefficient with the pearsonr function from scipy, as illustrated here:

corr, pval = pearsonr(x[:,0], y[:,0])
print(corr)

The following is the output:

0.5568647346122992

The number is positive, which is no surprise because as height increases, weight also tends to increase, but it is also closer to 1 than to 0, denoting that it is strongly correlated. The second number produced by the pearsonr function is the p-value for testing non-correlation. If we test that it’s less than a threshold of 5%, we can say there’s sufficient evidence of this correlation, as illustrated here:

print(pval < 0.05)

It confirms with a True that it is statistically significant.

Understanding how a model performs under different circumstances can help us explain why it makes certain predictions, and when it cannot. Let’s imagine we are asked to explain why someone who is 71 inches tall was predicted to have a weight of 134 pounds but instead weighed 18 pounds more. Judging from what we know about the model, this margin of error is not unusual even though it’s not ideal. However, there are many circumstances in which we cannot expect this model to be reliable. What if we were asked to predict the weight of a person who is 56 inches tall with the help of this model? Could we assure the same level of accuracy? Definitely not, because we fit the model on the data of subjects no shorter than 63 inches. The same is true if we were asked to predict the weight of a 9-year-old, because the training data was for 18-year-olds.

Despite the acceptable results, this weight prediction model was not a realistic example. If you wanted to be more accurate but—more importantly—faithful to what can really impact the weight of an individual, you would need to add more variables. You can add—say—gender at birth, age, diet, and activity levels. This is where it gets interesting because you have to make sure it is fair to include them, or to exclude them. For instance, if gender were included and most of our dataset was composed of males, how could you ensure accuracy for females? This is what is called selection bias. And what if weight had more to do with lifestyle choices and circumstances such as poverty and pregnancy than gender? If these variables aren’t included, this is called omitted variable bias. And then, does it make sense to include the sensitive gender variable at the risk of adding bias to the model?

Once you have multiple features that you have vetted for bias, you can find out and explain which features impact model performance. We call this feature importance. However, as we add more variables, we increase the complexity of the model. Paradoxically, this is a problem for interpretation, and we will explore this in further detail in the following chapters. For now, the key takeaway should be that model interpretation has a lot to do with explaining the following:

  • Can we explain how predictions were made, and how the model works?
  • Can we ensure that they are reliable and safe?
  • Can we explain that predictions were made without bias?

And ultimately, the question we are trying to answer is this:

Can we trust the model?

The three main concepts of interpretable machine learning directly relate to the three preceding questions and have the acronym of FAT, which stands for fairness, accountability, and transparency. If you can explain that predictions were made without discernible bias, then there is fairness. If you can explain why it makes certain predictions, then there’s accountability. And if you can explain how predictions were made and how the model works, then there’s transparency. There are many ethical concerns associated with these concepts, as shown here in Figure 1.2. It’s portrayed as a triangle because each layer depends on the previous one.

Figure 1.2 – Three main concept of Interpretable Machine Learning

Figure 1.2: Three main concepts of interpretable machine learning

Some researchers and companies have expanded FAT under a larger umbrella of ethical AI, thus turning FAT into FATE. However, both concepts very much overlap since interpretable machine learning is how FAT principles and ethical concerns get implemented in machine learning. In this book, we will discuss ethics in this context. For instance, Chapter 13, Adversarial Robustness, discusses reliability, safety, and security. Chapter 11, Bias Mitigating and Causal Inference Methods, discusses fairness. That being said, interpretable machine learning can be leveraged with no ethical aim in mind, and also for unethical reasons too.

Understanding the difference between interpretability and explainability

Section titled “Understanding the difference between interpretability and explainability”

Something you’ve probably noticed when reading the first few pages of this book is that the verbs interpret and explain, as well as the nouns interpretation and explanation, have been used interchangeably. This is not surprising, considering that to interpret is to explain the meaning of something. Despite that, the related terms interpretability and explainability should not be used interchangeably, even though they are often mistaken for synonyms. Most practitioners don’t make any distinction and many academics reverse the definitions provided in this book.

Interpretability is the extent to which humans, including non-subject-matter experts, can understand the cause and effect, and input and output, of a machine learning model. To say a model has a high level of interpretability means you can describe in a human-interpretable way its inference. In other words, why does an input to a model produce a specific output? What are the requirements and constraints of the input data? What are the confidence bounds of the predictions? Or, why does one variable have a more substantial impact on the prediction than another? For interpretability, detailing how a model works is only relevant to the extent that it can explain its predictions and justify that it’s the right model for the use case.

In this chapter’s example, we could explain that there’s a linear relationship between human height and weight, so using linear regression rather than a non-linear model makes sense. We can prove this statistically because the variables involved don’t violate the assumptions of linear regression. Even when statistics support your explanation, we still should consult with the domain knowledge area involved in the use case. In this scenario, we rest assured, biologically speaking, because our knowledge of human physiology doesn’t contradict the relationship between height and weight.

Many machine learning models are inherently harder to understand simply because of the math involved in the inner workings of the model or the specific model architecture. In addition to this, many choices are made that can increase complexity and make the models less interpretable, from dataset selection to feature selection and engineering to model training and tuning choices. This complexity makes explaining how machine learning models work a challenge. Machine learning interpretability is a very active area of research, so there’s still much debate on its precise definition. The debate includes whether total transparency is needed to qualify a machine learning model as sufficiently interpretable.

This book favors the understanding that the definition of interpretability shouldn’t necessarily exclude opaque models, which, for the most part, are complex, as long as the choices made don’t compromise their trustworthiness. This compromise is what is generally called post-hoc interpretability. After all, much like a complex machine learning model, we can’t explain exactly how a human brain makes a choice, yet we often trust its decision because we can ask a human for their reasoning. Post-hoc machine learning interpretation is similar, except it’s a human explaining the reasoning on behalf of the model. Using this particular concept of interpretability is advantageous because we can interpret opaque models and not sacrifice the accuracy of our predictions. We will discuss this in further detail in Chapter 3, Interpretation Challenges.

Decision-making systems don’t always require interpretability. There are two cases that are offered as exceptions, outlined here:

  • When incorrect results have no significant consequences. For instance, what if a machine learning model is trained to find and read the postal code in a package, occasionally misreads it, and sends it elsewhere? There’s little chance of discriminatory bias, and the cost of misclassification is relatively low. It doesn’t occur often enough to magnify the cost beyond acceptable thresholds.
  • When there are consequences, but these have been studied sufficiently and validated enough in the real world to make decisions without human involvement. This is the case with a Traffic-Alert And Collision-Avoidance System (TCAS), which alerts the pilot of another aircraft that poses a threat of a mid-air collision.

On the other hand, interpretability is needed for these systems to have the following attributes:

  • Minable for scientific knowledge: For example, meteorologists have much to learn from a climate model, but only if it’s easy to interpret.
  • Reliable and safe: The decisions made by a self-driving vehicle must be debuggable so that its developers can understand and correct points of failure.
  • Ethical: A translation model might use gender-biased word embeddings that result in discriminatory translations, such as a doctor being paired with male pronouns, but you must be able to find these instances easily to correct them. However, the system must be designed in such a way that you can be made aware of a problem before it is released to the public.
  • Conclusive and consistent: Sometimes, machine learning models may have incomplete and mutually exclusive objectives—for instance, a cholesterol-control system may not consider how likely a patient is to adhere to the diet or drug regimen, or there might be a trade-off between one objective and another, such as safety and non-discrimination.

By explaining the decisions of a model, we can cover gaps in our understanding of the problem—its incompleteness. One of the most significant issues is that given the high accuracy of our machine learning solutions, we tend to increase our confidence level to a point where we think we fully understand the problem. Then, we are misled into thinking our solution covers EVERYTHING!

At the beginning of this book, we discussed how leveraging data to produce algorithmic rules is nothing new. However, we used to second-guess these rules, and now we don’t. Therefore, a human used to be accountable, and now it’s the algorithm. In this case, the algorithm is a machine learning model that is accountable for all of the ethical ramifications this entails. This switch has a lot to do with accuracy. The problem is that although a model may surpass human accuracy in aggregate, machine learning models have yet to interpret their results as a human would. Therefore, it doesn’t second-guess its decisions, so as a solution, it lacks a desirable level of completeness. That’s why we need to interpret models so that we can cover at least some of that gap. So, why is machine learning interpretation not already a standard part of the data science pipeline? In addition to our bias toward focusing on accuracy alone, one of the biggest impediments is the daunting concept of black-box models.

This is just another term for opaque models. A black box refers to a system in which only the input and outputs are observable, and you cannot understand what is transforming the inputs into the outputs. In the case of machine learning, a black-box model can be opened, but its mechanisms are not easily understood.

These are the opposite of black-box models (see Figure 1.3). They are also known as transparent because they achieve total or near-total interpretation transparency. We call them intrinsically interpretable in this book, and we cover them in more detail in Chapter 3, Interpretation Challenges.

Have a look at a comparison between the models here:

Figure 1.3 – Visual comparison between white- and black-box models

Figure 1.3: Visual comparison between white- and black-box models

Next, we will examine the property that separates white- and black-box models: explainability.

Explainability encompasses everything interpretability is. The difference is that it goes deeper on the transparency requirement than interpretability because it demands human-friendly explanations for a model’s inner workings and the model training process, and not just model inference. Depending on the application, this requirement might extend to various degrees of model, design, and algorithmic transparency. There are three types of transparency, outlined here:

  • Model transparency: Being able to explain how a model is trained step by step. In the case of our simple weight prediction model, we can explain how the optimization method called ordinary least squares finds the β coefficient that minimizes errors in the model.
  • Design transparency: Being able to explain choices made, such as model architecture and hyperparameters. For instance, we could justify these choices based on the size or nature of the training data. If we were performing a sales forecast and we knew that our sales were seasonal over the year, this could be a sound parameter choice. If we had doubts, we could always use some well-established statistical method to find seasonality patterns.
  • Algorithmic transparency: Being able to explain automated optimizations such as grid search for hyperparameters, but note that the ones that can’t be reproduced because of their random nature—such as random search for hyperparameter optimization, early stopping, and stochastic gradient descent—make the algorithm non-transparent.

Black-box models are called opaque simply because they lack model transparency, but for many models this is unavoidable, however justified the model choice might be. In many scenarios, even if you outputted the math involved in, for example, training a neural network or a random forest, it would raise more doubts than generate trust. There are at least a few reasons for this, outlined here:

  • Not “statistically grounded”: An opaque model training process maps an input to an optimal output, leaving behind what appears to be an arbitrary trail of parameters. These parameters are optimized to a cost function but are not grounded in statistical theory, which makes predictions hard to justify and explain in statistical terms.
  • Uncertainty and non-reproducibility: Many opaque models are equally reproducible because they use random numbers to initialize their weights, regularize or optimize their hyperparameters, or make use of stochastic discrimination (such is the case for random forest algorithms).
  • Overfitting and the curse of dimensionality: Many of these models operate in a high-dimensional space. This doesn’t elicit trust because it’s harder to generalize on a larger number of dimensions. After all, there’s more opportunity to overfit a model the more dimensions you add.
  • The limitations of human cognition: Transparent models are often used for smaller datasets with fewer dimensions. They also tend to not complicate the interactions between these dimensions more than necessary. This lack of complexity makes it easier to visualize what the model is doing and its outcomes. Humans are not very good at understanding many dimensions, so using transparent models tends to make this much easier to understand. That being said, even these models can get so complex they might become opaque. For instance, if a decision tree model is 100 levels deep or a linear regression model has 100 features, it’s no longer easy for us to understand.
  • Occam’s razor: This is what is called the principle of simplicity or parsimony. It states that the simplest solution is usually the right one. Whether true or not, humans also have a bias for simplicity, and transparent models are known for—if anything—their simplicity.

Trustworthy and ethical decision-making is the main motivation for interpretability. Explainability has additional motivations such as causality, transferability, and informativeness. Therefore, there are many use cases in which total or nearly total transparency is valued, and rightly so. Some of these are outlined here:

  • Scientific research: Reproducibility is essential for scientific research. Also, using statistically grounded optimization methods is especially desirable when causality needs to be established.
  • Clinical trials: These must also produce reproducible findings and be statistically grounded. In addition to this, given the potential of overfitting, they must use the fewest dimensions possible and models that don’t complicate them.
  • Consumer product safety testing: Much as with clinical trials, when life-and-death safety is a concern, simplicity is preferred whenever possible.
  • Public policy and law: This is a more nuanced discussion, as part of what legal scholars call algorithmic governance, and they have distinguished between fishbowl transparency and reasoned transparency. Fishbowl transparency seeks total explainability and it’s closer to the rigor required for consumer product safety testing, whereas reasoned transparency is one where post-hoc interpretability, as defined earlier, would suffice. One day, the government could be entirely run by algorithms. When that happens, it’s hard to tell which policies will align with which form of transparency, but there are many areas of public policy, such as criminal justice, where absolute transparency is necessary. However, whenever total transparency contradicts privacy or security objectives, a less rigorous form of transparency may be preferred.
  • Criminal investigation and regulatory compliance audits: If something goes wrong, such as an accident at a chemical factory caused by a robot malfunction or a crash by an autonomous vehicle, an investigator would need a decision trail. This is to facilitate the assignment of accountability and legal liability. Even when no accident has happened, this kind of auditing can be performed when mandated by authorities. Compliance auditing applies to industries that are regulated, such as financial services, utilities, transportation, and healthcare. In many cases, fishbowl transparency is preferred.

This section describes several practical business benefits of machine learning interpretability, such as better decisions, as well as being more trusted, ethical, and profitable.

Typically, machine learning models are trained and then evaluated against the desired metrics. If they pass quality control against a hold-out dataset, they are deployed. However, once tested in the real world, things can get wild, as in the following hypothetical scenarios:

  • A high-frequency trading algorithm could single-handedly crash the stock market.
  • Hundreds of smart home devices might inexplicably burst into unprompted laughter, terrifying their users.
  • License-plate recognition systems could incorrectly read a new kind of license plate and fine the wrong drivers.
  • A racially biased surveillance system could incorrectly detect an intruder, and because of this guards shoot an innocent office worker.
  • A self-driving car could mistake snow for a pavement, crash into a cliff, and injure passengers.

Any system is prone to error, so this is not to say that interpretability is a cure-all. However, focusing on just optimizing metrics can be a recipe for disaster. In the lab, the model might generalize well, but if you don’t know why the model is making the decisions, then you can miss an opportunity for improvement. For instance, knowing what a self-driving car identifies as a road is not enough, but knowing why could help improve the model. If, say, one of the reasons was that road is light-colored like the snow, this could be dangerous. Checking the model’s assumptions and conclusions can lead to an improvement in the model by introducing winter road images into the dataset or feeding real-time weather data into the model. Also, if this doesn’t work, maybe an algorithmic fail-safe can stop it from acting on a decision that it’s not entirely confident about.

One of the main reasons why a focus on machine learning interpretability leads to better decision-making was mentioned earlier when we discussed completeness. If we think a model is complete, what is the point of making it better? Furthermore, if we don’t question the model’s reasoning, then our understanding of the problem must be complete. If this is the case, perhaps we shouldn’t be using machine learning to solve the problem in the first place! Machine learning creates an algorithm that would otherwise be too complicated to program in if-else statements, precisely to be used for cases where our understanding of the problem is incomplete!

It turns out that when we predict or estimate something, especially with a high level of accuracy, we think we control it. This is what is called the illusion of control bias. We can’t underestimate the complexity of a problem just because, in aggregate, the model gets it right almost all the time. Even for a human, the difference between snow and concrete pavement can be blurry and difficult to explain. How would you even begin to describe this difference in such a way that it is always accurate? A model can learn these differences, but it doesn’t make it any less complex. Examining a model for points of failure and continuously being vigilant for outliers requires a different outlook, whereby we admit that we can’t control the model, but we can try to understand it through interpretation.

The following are some additional decision biases that can adversely impact a model, and serve as reasons why interpretability can lead to better decision-making:

  • Conservatism bias: When we get new information, we don’t change our prior beliefs. With this bias, entrenched pre-existing information trumps new information, but models ought to evolve. Hence, an attitude that values questioning prior assumptions is a healthy one to have.
  • Salience bias: Some prominent or more visible things may stand out more than others, but statistically speaking, they should get equal attention to others. This bias could inform our choice of features, so an interpretability mindset can expand our understanding of a problem to include other less perceived features.
  • Fundamental attribution error: This bias causes us to attribute outcomes to behavior rather than circumstances, character rather than situations, and nature rather than nurture. Interpretability asks us to explore deeper and look for the less obvious relationships between our variables or those that could be missing.

One crucial benefit of model interpretation is locating outliers. These outliers could be a potential new source of revenue or a liability waiting to happen. Knowing this can help us to prepare and strategize accordingly.

Trust is defined as a belief in the reliability, ability, or credibility of something or someone. In the context of organizations, trust is their reputation; and in the unforgiving court of public opinion, all it takes is one accident, controversy, or fiasco to lose public confidence. This, in turn, can cause investor confidence to wane.

Let’s consider what happened to Boeing after the 737 MAX debacle or Facebook after the Cambridge Analytica elections scandal. In both cases, the technological failures were shrouded in mystery, leading to massive public distrust.

And these were examples of, for the most part, decisions made by people. With decisions made exclusively by machine learning models, this could get worse because it is easy to drop the ball and keep the accountability in the model’s corner. For instance, if you started to see offensive material in your Facebook feed, Facebook could say it’s because its model was trained with your data such as your comments and likes, so it’s really a reflection of what you want to see. Not their fault—your fault. If the police targeted our neighborhood for aggressive policing because it uses PredPol, an algorithm that predicts where and when crimes will occur, it could blame the algorithm. On the other hand, the makers of this algorithm could blame the police because the software is trained on their police reports. This generates a potentially troubling feedback loop, not to mention an accountability gap. And if some pranksters or hackers physically place strange textured meshes onto a highway (see https://arxiv.org/pdf/2101.06784.pdf), this could cause a Tesla self-driving car to veer into the wrong lane. Is this Tesla’s fault for not anticipating this possibility, or the hackers’ for throwing a monkey wrench into their model? This is called an adversarial attack, and we discuss this in Chapter 13, Adversarial Robustness.

It is undoubtedly one of the goals of machine learning interpretability to make models better at making decisions. But even when they fail, you can show that you tried. Trust is not lost entirely because of the failure itself but because of the lack of accountability, and even in cases where it is not fair to accept all the blame, some accountability is better than none. For instance, in the previous set of examples, Facebook could look for clues as to why offensive material is shown more often and then commit to finding ways to make it happen less, even if this means making less money. PredPol could find other sources of crime-rate datasets that are potentially less biased, even if they are smaller. They could also use techniques to mitigate bias in existing datasets (these are covered in Chapter 11, Bias Mitigation and Causal Inference Methods). And Tesla could audit its systems for adversarial attacks, even if this delays the shipment of its cars. All of these are interpretability solutions. Once they become common practice, they can lead to an increase in not only public trust—be it from users and customers—but also internal stakeholders such as employees and investors.

Many public relation AI blunders have occurred over the past couple of years. Due to trust issues, many AI-driven technologies are losing public support, to the detriment of both companies that monetize AI and users that could benefit from them. This, in part, requires a legal framework at a national or global level and, at the organizational end for those that deploy these technologies, more accountability.

There are three schools of thought for ethics: utilitarians focus on consequences, deontologists are concerned with duty, and teleologicalists are more interested in overall moral character. So, this means that there are different ways to examine ethical problems. For instance, there are useful lessons to draw from all of them. There are cases in which you want to produce the greatest amount of “good,” despite some harm being produced in the process. Other times, ethical boundaries must be treated as lines in the sand you mustn’t cross. And at other times, it’s about developing a righteous disposition, much like many religions aspire to do. Regardless of the school of ethics that we align with, our notion of what it is evolves with time because it mirrors our current values. At this moment, in Western cultures, these values include the following:

  • Human welfare
  • Ownership and property
  • Privacy
  • Freedom from bias
  • Universal usability
  • Trust
  • Autonomy
  • Informed consent
  • Accountability
  • Courtesy
  • Environmental sustainability

Ethical transgressions are cases whereby you cross the moral boundaries that these values seek to uphold, be it by discriminating against someone or polluting their environment, whether it’s against the law or not. Ethical dilemmas occur when you have a choice between options that lead to transgressions, so you have to choose between one and another.

The first reason machine learning is related to ethics is that technologies and ethical dilemmas have an intrinsically linked history.

Even the first widely adopted tools made by humans brought progress but also caused harm, such as accidents, war, and job losses. This is not to say that technology is always bad but that we lack the foresight to measure and control its consequences over time. In AI’s case, it is not clear what the harmful long-term effects are. What we can anticipate is that there will be a major loss of jobs and an immense demand for energy to power our data centers, which could put stress on the environment. There’s speculation that AI could create an “algocratic” surveillance state run by algorithms, infringing on values such as privacy, autonomy, and ownership. Some readers might point to examples of this already happening.

The second reason is even more consequential than the first. It’s that predictive modeling is a technological first for humanity: machine learning is a technology that can make decisions for us, and these decisions can produce individual ethical transgressions that are hard to trace. The problem with this is that accountability is essential to morality because you have to know who to blame for human dignity, atonement, closure, or criminal prosecution. However, many technologies have accountability issues to begin with, because moral responsibility is often shared in any case. For instance, maybe the reason for a car crash was partly due to the driver, mechanic, and car manufacturer. The same can happen with a machine learning model, except it gets trickier. After all, a model’s programming has no programmer because the “programming” was learned from data, and there are things a model can learn from data that can result in ethical transgressions. Top among them are biases such as the following:

  • Sample bias: When your data, the sample, doesn’t represent the environment accurately, also known as the population
  • Exclusion bias: When you omit features or groups that could otherwise explain a critical phenomenon with the data
  • Prejudice bias: When stereotypes influence your data, either directly or indirectly
  • Measurement bias: When faulty measurements distort your data

Interpretability comes in handy to mitigate bias, as seen in Chapter 11, Bias Mitigation and Causal Inference Methods, or even placing guardrails on the right features, which may be a source of bias. This is covered in Chapter 12, Monotonic Constraints and Model Tuning for Interpretability. As explained in this chapter, explanations go a long way in establishing accountability, which is a moral imperative. Also, by explaining the reasoning behind models, you can find ethical issues before they cause any harm. But there are even more ways in which models’ potentially worrisome ethical ramifications can be controlled, and this has less to do with interpretability and more to do with design. There are frameworks such as human-centered design, value-sensitive design, and techno-moral virtue ethics that can be used to incorporate ethical considerations into every technological design choice. An article by Kirsten Martin (https://doi.org/10.1007/s10551-018-3921-3) also proposes a specific framework for algorithms. This book won’t delve into algorithm design aspects too much, but for those readers interested in the larger umbrella of ethical AI, this article is an excellent place to start.

Organizations should take the ethics of algorithmic decision-making seriously because ethical transgressions have monetary and reputation costs. But also, AI left to its own devices could undermine the very values that sustain democracy and the economy that allows businesses to thrive.

As seen already in this section, interpretability improves algorithmic decisions, boosting trust and mitigating ethical transgressions.

When we leverage previously unknown opportunities and mitigate threats such as accidental failures through better decision-making, we are likely to improve the bottom line; and if we increase trust in an AI-powered technology, we are likely to increase its use and enhance overall brand reputation, which also has a beneficial impact on profits. On the other hand, ethical transgressions can occur by design or by accident, and when they are discovered, they adversely impact both profits and reputation.

When businesses incorporate interpretability into their machine learning workflows, it’s a virtuous cycle, and it results in higher profitability. In the case of a non-profit or government, profits might not be a motive. Still, finances are undoubtedly involved because lawsuits, lousy decision-making, and tarnished reputations are expensive. Ultimately, technological progress is contingent not only on the engineering and scientific skills and materials that make it possible but its voluntary adoption by the general public.

This chapter has shown us what machine learning interpretation is and what it is not, and the importance of interpretability. In the next chapter, we will learn what can make machine learning models so challenging to interpret, and how you would classify interpretation methods in both category and scope.

  • Statistics Online Computational Resource, University of Southern California. (1993). Growth Survey of 25,000 children from birth to 18 years of age recruited from Maternal and Child Health Centers. Originally retrieved from http://www.socr.ucla.edu/
  • Lipton, Zachary (2017). The Mythos of Model Interpretability. ICML 2016 Human Interpretability in Machine Learning Workshop: https://doi.org/10.1145/3236386.3241340
  • Roscher, R., Bohn, B., Duarte, M.F. & Garcke, J. (2020). Explainable Machine Learning for Scientific Insights and Discoveries. IEEE Access, 8, 42200-42216: https://dx.doi.org/10.1109/ACCESS.2020.2976199
  • Doshi-Velez, F. & Kim, B. (2017). Towards A Rigorous Science of Interpretable Machine Learning: http://arxiv.org/abs/1702.08608
  • Arrieta, A.B., Diaz-Rodriguez, N., Ser, J.D., Bennetot, A., Tabik, S., Barbado, A., Garc’ia, S., Gil-L’opez, S., Molina, D., Benjamins, R., Chatila, R., & Herrera, F. (2020). Explainable Artificial Intelligence (XAI): Concepts, Taxonomies, Opportunities and Challenges toward Responsible AI: https://arxiv.org/abs/1910.10045
  • Coglianese, C. & Lehr, D. (2019). Transparency and algorithmic governance. Administrative Law Review, 71, 1-4: https://ssrn.com/abstract=3293008
  • Weller, Adrian. (2019) Transparency: Motivations and Challenges. arXiv:1708.01870 [Cs]: http://arxiv.org/abs/1708.01870