Interpretable Machine Learning with Python - Second Edition

Book description

A deep and detailed dive into the key aspects and challenges of machine learning interpretability, complete with the know-how on how to overcome and leverage them to build fairer, safer, and more reliable models

Key Features

  • Extract easy-to-understand insights from any machine learning model
  • Become well-versed with interpretability techniques to build fairer, safer, and more reliable models
  • Lift the lid on the black box of transformer NLP models to improve your deep learning understanding

Book Description

Do you want to gain a deeper understanding of your models and better mitigate poor prediction risks associated with machine learning interpretation? If so, then Interpretable Machine Learning with Python, Second Edition is the book for you.

You’ll cover the fundamentals of interpretability, its relevance in business, and explore its key aspects and challenges.

See how white-box models work, compare them to black-box and glass-box models, and examine their trade-offs. Get 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, tabular data, time-series, images, or text.

In addition to the step-by-step code, this book will also help you interpret model outcomes using many examples. 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. You’ll also look under the hood of the latest NLP transformer models using the Language Interpretability Tool.

By the end of this book, you'll 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, Naive Bayes, and glass-box models, such as EBM and Gami-NET
  • Become well-versed in interpreting black-box models with model-agnostic methods
  • Use monotonic and interaction constraints to make fairer and safer models
  • Understand how to mitigate the influence of bias in datasets
  • Discover how to make models more reliable with adversarial robustness
  • Understand how transformer models work and how to interpret them

Who this book is for

This book is for data scientists, machine learning developers, MLOps engineers, 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 It’s also a useful resource for self-taught ML enthusiasts and beginners who want to go deeper into the subject matter, though a good grasp of the Python programming language is needed to implement the examples.

Table of contents

  1. Interpretable Machine Learning with Python, Second Edition: Build Your Own Interpretable Models
  2. 1 Interpretation, Interpretability, and Explainability; and Why Does It All Matter?
    1. Join our book community on Discord
    2. Technical requirements
    3. What is machine learning interpretation?
      1. Understanding a simple weight prediction model
    4. Understanding the difference between interpretability and explainability
      1. What is interpretability?
      2. What is explainability?
    5. A business case for interpretability
      1. Better decisions
      2. More trusted brands
      3. More ethical
      4. More profitable
    6. Summary
    7. Image sources
    8. Further reading
  3. 2 Key Concepts of Interpretability
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
      1. Details about CVD
    4. The approach
    5. Preparations
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Learning about interpretation method types and scopes
      1. Model interpretability method types
      2. Model interpretability scopes
      3. Interpreting individual predictions with logistic regression
    7. Appreciating what hinders machine learning interpretability
      1. Non-linearity
      2. Interactivity
      3. Non-monotonicity
    8. Mission accomplished
    9. Summary
    10. Further reading
  4. 3 Interpretation Challenges
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
    4. The approach
    5. The preparations
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Reviewing traditional model interpretation methods
      1. Predicting minutes delayed with various regression methods
      2. Classifying flights as delayed or not delayed with various classification methods
    7. Understanding limitations of traditional model interpretation methods
    8. Studying intrinsically interpretable (white-box) models
      1. Generalized Linear Models (GLMs)
      2. Decision trees
      3. RuleFit
      4. Nearest neighbors
      5. Naïve Bayes
    9. Recognizing the trade-off between performance and interpretability
      1. Special model properties
      2. Assessing performance
    10. Discovering newer interpretable (glass-box) models
      1. Explainable Boosting Machine (EBM)
      2. GAMI-Net
    11. Mission accomplished
    12. Summary
    13. Dataset sources
    14. Further reading
  5. 5 Local Model-Agnostic Interpretation Methods
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
    4. The approach
    5. The preparations
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Leveraging SHAP's KernelExplainer for local interpretations with SHAP values
      1. Training a C-SVC model
      2. Computing SHAP values using KernelExplainer
      3. Local interpretation for a group of predictions using decision plots
      4. Local interpretation for a single prediction at a time using a force plot
    7. Employing LIME
      1. What is LIME?
      2. Local interpretation for a single prediction at a time using LimeTabularExplainer
    8. Using LIME for NLP
      1. Training a LightGBM model
      2. Local interpretation for a single prediction at a time using LimeTextExplainer
    9. Trying SHAP for NLP
    10. Comparing SHAP with LIME
    11. Mission accomplished
    12. Summary
    13. Dataset sources
    14. Further reading
  6. 6 Anchor and Counterfactual Explanations
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
      1. Unfair bias in recidivisim risk assessments
    4. The approach
    5. The preparations
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Understanding anchor explanations
      1. Preparations for anchor and counterfactual explanations with alibi
      2. Local interpretations for anchor explanations
    7. Exploring counterfactual explanations
      1. Counterfactual explanations guided by prototypes
      2. Counterfactual instances and much more with the What-If Tool (WIT)
    8. Mission accomplished
    9. Summary
    10. Dataset sources
    11. Further reading
  7. 9 Interpretation Methods for Multivariate Forecasting and Sensitivity Analysis
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
    4. The approach
    5. The preparation
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Assessing time series models with traditional interpretation methods
    7. Generating LSTM attributions with integrated gradients
    8. Computing global and local attributions with SHAP's KernelExplainer
      1. Why use the KernelExplainer?
      2. Defining a strategy to get it to work with a multivariate time series model
      3. Laying the groundwork for the permutation approximation strategy
      4. Computing the SHAP values
    9. Identifying influential features with factor prioritization
      1. Computing Morris sensitivity indices
      2. Analyzing the elementary effects
    10. Quantifying uncertainty and cost sensitivity with factor fixing
      1. Generating and predicting on Salteli samples
      2. Performing Sobol sensitivity analysis
      3. Incorporating a realistic cost function
    11. Mission accomplished
    12. Summary
    13. Dataset and image sources
    14. References
  8. 10 Feature Selection and Engineering for Interpretability
    1. Join our book community on Discord
    2. Technical requirements
    3. The mission
    4. The approach
    5. The preparations
      1. Loading the libraries
      2. Understanding and preparing the data
    6. Understanding the effect of irrelevant features
      1. Creating a base model
      2. Evaluating the model
      3. Training the base model at different max depths
    7. Reviewing filter-based feature selection methods
      1. Basic filter-based methods
      2. Correlation filter-based methods
      3. Ranking filter-based methods
      4. Comparing filter-based methods
    8. Exploring embedded feature selection methods
    9. Discovering wrapper, hybrid, and advanced feature selection methods
      1. Wrapper methods
    10. Hybrid methods
      1. Advanced methods
      2. Evaluating all feature-selected models
    11. Considering feature engineering
    12. Mission accomplished
    13. Summary
    14. Dataset sources
    15. Further reading
  9. 14 What's Next for Machine Learning Interpretability?
    1. Join our book community on Discord
    2. Understanding the current landscape of ML interpretability
      1. Tying everything together!
      2. Current trends
    3. Speculating on the future of ML interpretability
      1. A new vision for ML
      2. A multidisciplinary approach
      3. Adequate standardization
      4. Enforcing regulation
      5. Seamless machine learning automation with built-in interpretation
      6. Tighter integration with MLOps engineers
    4. Further reading

Product information

  • Title: Interpretable Machine Learning with Python - Second Edition
  • Author(s): Serg Masís
  • Release date: October 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803235424