SkillAgentSearch skills...

Interpretable Machine Learning With Python 2E

Interpretable ML with Python, 2E - published by Packt

Install / Use

npx skills add PacktPublishing/Interpretable-Machine-Learning-with-Python-2E

Installs into whichever agent you are using.

About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Interpretable Machine Learning with Python

<a href="https://www.packtpub.com/product/interpretable-machine-learning-with-python-2e-second-edition/9781803235424"><img src="https://content.packt.com/B18406/cover_image_small.jpg" alt="Interpretable Machine Learning with Pythone" height="256px" align="right"></a>

This is the code repository for Interpretable Machine Learning with Python, 2E, published by Packt.

Build explainable, fair, and robust high-performance models with hands-on, real-world examples

The author of this book is -Serg Masís

About the book

Interpretable Machine Learning with Python, Second Edition, brings to light the key concepts of interpreting machine learning models by analyzing real-world data, providing you with a wide range of skills and tools to decipher the results of even the most complex models. Build your interpretability toolkit with several use cases, from flight delay prediction to waste classification to COMPAS risk assessment scores. This book is full of useful techniques, introducing them to the right use case. Learn traditional methods, such as feature importance and partial dependence plots to integrated gradients for NLP interpretations and gradient-based attribution methods, such as saliency maps. In addition to the step-by-step code, you’ll get hands-on with reducing complexity, mitigating bias, placing guardrails, and enhancing reliability. By the end of the book, you’ll be confident in tackling interpretability challenges with black-box models using tabular, language, image, and time series data.

image

image

image

What's New:

This second edition introduces analysis of NLP transformers, leveraging BertViz to visualize transformer models, layers, and attention heads, and integrated gradients and the Visualization Data Record to see what tokens are responsible for a predicted label. You’ll also get a crash course on the Learning Interpretability Tool (LIT) and go through new and updated uses case.

What is this book about?

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.

This book covers the following exciting features:

  • 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

If you feel this book is for you, get your copy today!

<a href="https://www.packtpub.com/?utm_source=github&utm_medium=banner&utm_campaign=GitHubBanner"><img src="https://raw.githubusercontent.com/PacktPublishing/GitHub/master/GitHub.png" alt="https://www.packtpub.com/" border="5" /></a>

Instructions and Navigations

All of the code is organized into folders. For example, 02 for Chapter 2.

The code will look like the following:

base_classifier = KerasClassifier(model=base_model,\
                                  clip_values=(min_, max_))
y_test_mdsample_prob = np.max(y_test_prob[sampl_md_idxs],\
                                                       axis=1)
y_test_smsample_prob = np.max(y_test_prob[sampl_sm_idxs],\
                                                       axis=1)

Following is what you need for this book: 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.

With the following software and hardware list you can run all code files present in the book (Chapter 1-14).

Software and Hardware List

Software

You can install the software required in any operating system by first installing Jupyter Notebook or Jupyter Lab with the most recent version of Python, or install Anaconda which can install everything at once. Python versions 3.9 and onwards are supported. For what packages are required see below.

Hardware

While hardware requirements for Jupyter are relatively modest, we recommend a machine with at least 4 cores of 2Ghz and 8Gb of RAM. A GPU is highly recommended for chapters with Deep Learning (7, 8, 9, 12, and 13). If you don't have a GPU in your machine, we recommend you use Google Colab for these chapters. Skip to the Google Colab section for details.

Python Packages

The packages required for the entire book are in requirements.txt and there's a similar file in in each chapter folder specifying the requirements for the corresponding chapter. For installation instructions, see below.

Installation Instructions

Once you clone this repository, there are many ways to setup your Python environment and Jupyter installation. You may have your packages managed by Anaconda or Miniconda (conda), Conan (conan), Mamba (mamba), or Poetry (poetry). Either way, we strongly suggest you setup an independent environment and install the requirements there with python like this:

# Go to cloned repository
cd /path/to/repo/

# Run the setup script
python setup.py

Under the hood it is using pip to install the packages one-by-one as specified requirements.txt. If it's starting from a clean slate it should have no conflicts. Please note that for some systems you might need to install pip and setuptools before you run setup.py since these usually come already installed but sometimes they aren't.

If you are having issues with the installation you can try pip directly which can install most of the packages all-in-one-go using -r. There are two packages we must install without dependencies to avoid conflicts.

# Install most requirements (it will fail if one conflict is found)
pip install -r requirements_w_pip.txt

# Install the two requirements with special arguments
pip install --no-deps git+https://github.com/EthicalML/xai.git
pip install --no-deps adversarial-robustness-toolbox~=1.12.2

You can also create virtual environments on a chapter by chaper basis with pipenv, venv, virtualenv, conda or any of the other options, and use the chapter_setup.py script located in every chapter to ensure that the packages are installed. For instance:

# Go to chapter's folder
cd /path/to/chapter

# Create a virtual environment called "myenv"
python -m venv myvenv

# Activate the "myenv" environment
source myenv/bin/activate

# Run the chapter setup script in that environment
python chapter_setup.py

The setup script won't take care of your Jupyter installation, You would still need to install Jupyter like this:

# Install Jupyter Notebook
pip install notebook

# Set the "myenv" virtual environment as a Jupyter kernel
python -m ipykernel install --user --name=myvenv

# Start a Jupyter server (typically available at http://localhost:8888/tree)
jupyter notebook

Google Colab

You can run all the code in Google Colab with the following links:

  • Chapter 1: Interpretation, Interpretability, and Explainability; and why does it all matter?
  • Chapter 2: Key Concepts of Interpretability
    • Cardiovascular Disease Risk Factors CVD.ipynb
  • Chapter 3: Interpretation Challenges
  • Chapter 4: Global Model-Agnostic Interpretation Methods
    • Used Cars Price Prediction UsedCars.ipynb (Best run on CPU with High RAM)
  • Chapter 5: Local Model-agnostic Interpretation Methods
  • Chapter 6: Anchor and Counterfactual Explanations
  • Chapter 7: Visualizing Convolutional Neural Networks

Related Skills

View on GitHub
GitHub Stars111
CategoryEducation
Updated1mo ago
Forks46

Languages

Jupyter Notebook

Security Score

95/100

Audited on Jul 8, 2026

No findings