<Interpretable Machine Learning with Python> Understand the key aspects and challenges of machine learning interpretability, learn how to overcome them with interpretation methods, and leverage them to build fairer, safer, and more reliable models
Do you want to understand your models and mitigate risks associated with poor predictions using machine learning (ML) interpretation? Interpretable Machine Learning with Python can help you work effectively with ML models.
The first section of the book is a beginner's guide to interpretability, covering its relevance in business and exploring its key aspects and challenges. You'll focus on how white-box models work, compare them to black-box and glass-box models, and examine their trade-off. The second section will get you up to speed with a vast array of interpretation methods, also known as Explainable AI (XAI) methods, and how to apply them to different use cases, be it for classification or regression, for tabular, time-series, image or text. In addition to the step-by-step code, the book also helps the reader to interpret model outcomes using examples. In the third section, you'll get hands-on with tuning models and training data for interpretability by reducing complexity, mitigating bias, placing guardrails, and enhancing reliability. The methods you'll explore here range from state-of-the-art feature selection and dataset debiasing methods to monotonic constraints and adversarial retraining.
By the end of this book, you'll be able to understand ML models better and enhance them through interpretability tuning.
▶What You Will Learn
-Recognize the importance of interpretability in business
-Study models that are intrinsically interpretable such as linear models, decision trees, and Naive Bayes
-Become well-versed in interpreting models with model-agnostic methods
-Visualize how an image classifier works and what it learns
-Understand how to mitigate the influence of bias in datasets
-Discover how to make models more reliable with adversarial robustness
-Use monotonic constraints to make fairer and safer models
-Learn how to extract easy-to-understand insights from any machine learning model
-Become well-versed with interpretability techniques to build fairer, safer, and more reliable models
-Mitigate risks in AI systems before they have broader implications by learning how to debug black-box models
▶Who This Book Is For
This book is for data scientists, machine learning developers, and data stewards who have an increasingly critical responsibility to explain how the AI systems they develop work, their impact on decision making, and how they identify and manage bias. Working knowledge of machine learning and the Python programming language is expected.
▶What this book covers
- 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 both 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, Fundamentals of Feature Importance and Impact, employs a birth order classification example to discuss different methods to obtain feature importance such as those that use a model's intrinsic parameters, and a more reliable model-agnostic method called Permutation Feature Importance. Then, to convey a single feature's marginal impact on the prediction, we will study how to render and interpret Partial Dependence Plots (PDP) and Individual Conditional Expectation (ICE) plots.
- Chapter 5, Global Model-Agnostic Interpretation Methods, explores game-theory-inspired SHapley Additive exPlanations (SHAP) in great detail with fuel efficiency regression models, then visualizes conditional marginal distribution Accumulated Local Effects (ALE) plots. Finally, we touch on Global Surrogates, which can be very accurate and efficient interpretation tools when chosen correctly.
- Chapter 6, 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 7, Anchor 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 Contrastive Explanation Method (CEM), as well as the What-If-Tool (WIT).
- Chapter 8, Visualizing Convolutional Neural Networks, exclusively explores interpretation methods that work with Convolutional Neural Network (CNN) models with a fruit 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 Occlusion Sensitivity, LIME, and CEM.
- Chapter 9, Interpretation Methods for Multivariate Forecasting and Sensitivity Analysis, uses a traffic forecasting problem and Long Short-Term Memory (LSTM) models to look at 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 such 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 pre-processing methods such as reweighting and disparate impact 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, but we focus on evasion attacks such as Carlini and Wagner Infinity- Norm and Adversarial Patches and briefly explain other forms of attacks. We explain two defense methods: spatial smoothing preprocessing and adversarial training. Lastly, we demonstrate one robustness evaluation method and one certification 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!
From this book's title, you can infer that this book is about three things: Interpretation, Machine Learning, and Python. And they are precisely in that order of importance!
"Why?", you might ask.
Interpretable Machine Learning, also known as Explainable AI (XAI), is an everincreasing family of methods that we can leverage to learn from models and make them safe, fair, and reliable, which is something, I hope, we all want for our models.
However, since AI is replacing software (and humans), machine learning models are seen as a more "intelligent" form of software. Yes, they are ones and zeros, but they are not software in the sense that their logic is programmed by people and does as intended, by design. So, interpretation is how we can make sense of them and their mistakes, then correct their flaws, hopefully before they cause any harm. Hence, interpretation is critical to make models trustworthy, and ethical. Also, soon enough, we won't even train models with code, but with drag-and-drop interfaces! So, while we all love Python, the skill that will stand the test of time is machine learning interpretation.
For now, it still takes ample code to prepare and explore data and then train and productionize models, so every chapter in this book involves detailed Python code examples. Yet, the book wasn't designed to be employed as a programming "cookbook" disconnected from use cases and any sense of purpose. Instead, this book is flipping this paradigm around. The reason for this is simple: For Interpretable Machine Learning to be effective, the "why?" has to precede the "how?". After all, interpretation is all about answering the question "why?".
For this reason, most chapters begin with a mission (the "why?") followed by an approach (the "how?"). After that, the goal is to complete the mission using the methods (more "how?") taught throughout the chapter, focusing on interpreting outcomes (more "why?"). Lastly, it will reflect on what actionable insights were learned completing the task.
The book itself is also structured. It goes from fundamentals to more advanced topics. The tools employed are all open source and built by the most advanced research labs, such as Microsoft, Google, and IBM. It's a very broad area of research, most of which hasn't even left the lab and become widely used. This book has no intention of covering absolutely all of it. Instead, the objective is to present many interpretability tools in sufficient depth to be useful for practitioners and the many professionals involved in the machine learning field.
The first section of the book is a beginner's guide to interpretability, covering its relevance in business and exploring its key aspects and challenges. The second section will get you up to speed with a comprehensive collection of interpretation methods and how to apply them to different use cases, be it for classification or regression, for tabular data, time-series, images, or text. In the third section, you'll get hands-on with tuning models and training data for interpretability by reducing complexity, mitigating bias, placing guardrails, and enhancing reliability.
By the end of this book, you will be employing interpretation methods to understand machine learning models better and improving them through interpretability tuning.
▶About the Author
- Serg Masis
Serg Masis has been at the confluence of the internet, application development, and analytics for the last two decades. Currently, he's a Climate and Agronomic Data Scientist at Syngenta, a leading agribusiness company with a mission to improve global food security. Before that role, he co-founded a startup, incubated by Harvard Innovation Labs, that combined the power of cloud computing and machine learning with principles in decision-making science to expose users to new places and events. Whether it pertains to leisure activities, plant diseases, or customer lifetime value, Serg is passionate about providing the often-missing link between data and decision-making -and machine learning interpretation helps bridge this gap more robustly.
▶TABLE of CONTENTS
▷Section 1: Introduction to Machine Learning Interpretation
-Chapter 1: Interpretation, Interpretability, and Explainability; and Why Does It All Matter?
-Chapter 2: Key Concepts of Interpretability
-Chapter 3: Interpretation Challenges
▷Section 2: Mastering Interpretation Methods
-Chapter 4: Fundamentals of Feature Importance and Impact
-Chapter 5: Global Model-Agnostic Interpretation Methods
-Chapter 6: Local Model-Agnostic Interpretation Methods
-Chapter 7: Anchor and Counterfactual Explanations
-Chapter 8: Visualizing Convolutional Neural Networks
-Chapter 9: Interpretation Methods for Multivariate Forecasting and Sensitivity Analysis
▷Section 3:Tuning for Interpretability
-Chapter 10: Feature Selection and Engineering for Interpretability
-Chapter 11: Bias Mitigation and Causal Inference Methods
-Chapter 12: Monotonic Constraints and Model Tuning for Interpretability
-Chapter 13: Adversarial Robustness
-Chapter 14: What's Next for Machine Learning Interpretability?