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
▶Book Description
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
▶Key Features
-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!