Interpretable Machine Learning with Python
eBook - ePub

Interpretable Machine Learning with Python

Learn to build interpretable high-performance models with hands-on real-world examples

Serg Masís

Condividi libro
  1. 736 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Interpretable Machine Learning with Python

Learn to build interpretable high-performance models with hands-on real-world examples

Serg Masís

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

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

  • 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

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 deserves a place on your bookshelf.We'll be starting off with the fundamentals of interpretability, its relevance in business, and exploring its key aspects and challenges. As you progress through the chapters, you'll then focus on how white-box models work, compare them to black-box and glass-box models, and examine their trade-off. You'll also 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, this book will also help you interpret model outcomes using 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.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 Naïve 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

Who this book is for

This book is primarily written for data scientists, machine learning developers, and data stewards who find themselves under increasing pressures to explain the workings of AI systems, their impacts 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 solid grasp on the Python programming language and ML fundamentals is needed to follow along.

]]>

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Interpretable Machine Learning with Python è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Interpretable Machine Learning with Python di Serg Masís in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Computer Science General. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2021
ISBN
9781800206571

Section 1: Introduction to Machine Learning Interpretation

In this section, you will recognize the importance of interpretability in business and understand its key aspects and challenges.
This section includes the following chapters:
  • Chapter 1, Interpretation, Interpretability and Explainability; and why does it all matter?
  • Chapter 2, Key Concepts of Interpretability
  • Chapter 3, Interpretation Challenges

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

We live in a world whose rules and procedures are governed by data and algorithms.
For instance, there are rules as to 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.
You 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 would ask 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 override it.
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?
Hold on to that thought because, throughout this book, we will be learning the answers to these questions and many more!
To interpret decisions made by a machine learning model is to find meaning in it, but furthermore, you can trace it back to its source and the process that transformed it. 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!

Technical requirements

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 requests, bs4, pandas, sklearn , matplotlib, and scipy Python libraries. The code for this chapter is located here: https://github.com/PacktPublishing/Interpretable-Machine-Learning-with-Python/tree/master/Chapter01.

What is machine learning interpretation?

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
features with the
coefficients. In this case, there's only one
feature or predictor variable, and the
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
to produce the output
. The following example can illustrate this concept in further detail.

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
synthetic records of weights and heights of
-year-olds. We won't use the entire dataset but only the sample table on the web page itself with
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,
and
, so the formula for the linear regression model would be as follows:
You can find the code for this example here: https://github.com/PacktPublishing/Interpretable-Machine-Learning-with-Python/blob/master/Chapter01/WeightPrediction.ipynb.
To run this example, you need to install the following libraries:
  • requests to fetch the web page
  • bs4 (Beautiful Soup) to scrape the table from the web page
  • pandas to load the table in to 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 requests 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)
Then, take these contents and scrape out just the contents of the table with BeautifulSoup, as follows:
soup = BeautifulSoup(page.content, 'html.parser')
tbl = soup.find("table",{"class":"wikitable"})
pandas can turn the raw HyperText Markup Language (HTML) contents...

Indice dei contenuti