Index – Hands-On Explainable AI (XAI) with Python

Index

A

agnostic AutoML template

creating 277, 278

agnostic model

explaining, with SHAP 143

AI bias

autopilot decision making 55

decision tree, building 58

ethical AI moral limits, explaining 59, 60

MIT Moral Machine experiment 57

trolley problem 55, 56

using, in self-driving cars (SDCs) 55

AI diagnosis

enhancing, with XAI 41

Alibi

installing 333

anchors AI explanations 357

for ImageNet 361

income, predicting 357, 359

newsgroup discussions, classifying 359, 361

anchors AI explanations, for ImageNet

Alibi, installing 361, 362

anchor image explainer, building 364, 365, 366, 367

category 367, 369

image, downloading 363, 364

image, processing 364

InceptionV3 model 362

limitations 369, 370, 371

modules, importing 361, 362

predictions, making 364

area under the curve (AUC) 226

autoencoder

creating 343

defining 342

original images, comparing with decoded images 345, 346

saving 344, 345

training 342, 344

AutoML

interactive choice, of classifier 283, 284

model, training 283

prediction process, finalizing 284

predictions, making 283

autopilot decision tree

accuracy 78

accuracy, measuring 82

building 61

customized structure, output 78, 79, 80, 81

data, reading 64, 65

dataset, retrieving 63, 64

data, splitting 64, 65

decision tree classifiers, creating 67

decision tree classifiers, defining 66, 67

displaying 70, 72, 73, 74

ethics, using to control 81

ML bias 83, 84, 85

ML ethics and laws 85

model, loading 82

model, measuring 68, 69

model, saving 69

model, training 68, 70

modules, importing 62, 63

nodes, considering 77

real-time cases, simulating 83

SDC autopilot dilemma 61, 62

structure 74

structure, customized output 76

structure, output 74, 76

XAI, applying 74

XAI, using to control 81

B

bagging classifier 279

black box models

migrating, to XAI white box models 4

C

CEM, applying to MNIST 333

Alibi, installing 333

data, categorizing 337

data, preparing 335

data, scaling 336

dataset, importing 333, 334, 335

data, shaping 336

modules, importing 333, 334

modules, installing 333

cognitive explanation function 383, 384, 385, 386

cognitive rule-based explanations 377

defining 378, 379, 380

XAI tools, migrating to XAI concepts 377

cognitive XAI method 380

data, importing 380, 381

dictionaries 381, 382

global parameters 382, 383

modules, importing 380, 381

contrastive explanations method (CEM) 330, 331, 332

applying, to MNIST 333

human cognitive input 396

rule-based perspectives 397, 398, 399, 400, 401

convolutional neural network (CNN) 324

convolutional neural network (CNN) model

accuracy, testing 341

convolutional layer 337

creating 339

defining 337

dense layer 338

dropout layer 338

flatten layer 338

loading 341

pooling layer 337

training 340, 341

Correctional Offender Management Profiling for Alternative Sanctions (COMPAS) 199

counterfactual distances

visualizing, in WIT 302, 303

counterfactual explanations, logic 310

belief 310, 311, 312

justification 314

sensitivity 314, 315

truth 312, 313

counterfactual explanations method 301

data point distances, exploring with default view 304, 305, 306, 307, 308, 309

datasets 301

motivations 301

count features 203

CUI XAI dialog

Jupyter Notebook XAI agent manager 263

using, in Google Dialogflow 259

with Google Assistant 264, 265

custom distance functions 320

D

data

designing 6

extracting 6

data extraction tool

reference link 29

using 28, 29, 30, 31

datasets

ethical perspectives 160, 161

legal perspectives 160, 161

moral perspectives 160, 161

retrieving 275

vectorizing 275, 276

decision tree classifier 280

deep learning model, architecture 320

custom prediction, for WIT 322, 323

dataset, retrieving 325

Keras model, loading 324, 325

model, retrieving 325

WIT, invoking 321, 322

deep neural network (DNN) 190

dialog function

creating 245, 246

distance functions 316

custom distance functions 320

L1 norm 316, 318

L2 norm 319, 320

DNN model

creating 208, 209, 210

training 211

E

EEOC laws ban 168

Equal Employment Opportunity Commission (EEOC)

reference link 168

ethical AI perspective, Google�s WIT 199

explainability 198, 199, 200

interpretability 198, 199, 200

ethical perspective rules, U.S. census data problem

AI project, with controversial data, avoiding 168

controversial data, excluding form dataset 167

ethics

using, to control autopilot decision tree 81

experimental AutoML module 276

explainable AI (XAI)

defining 3, 4

for educational purposes 185, 186

explaining 6

extra trees classifiers 281

F

Facets

data files, reading 94

datasets, retrieving 93, 94

installing, on Google Colaboratory 93

starting with 92

Facets Dive

about 105

colors, adding to data points 109

display code, building 105, 106, 107

labels, displaying on data points 107, 108

x axis and y axis binning, defining 110, 111

x axis and y axis scatter plot, defining 111, 112, 113

Facets Overview

about 95

feature statistics, creating for datasets 95

false positives (FP) 223

feature statistics, Facets Overview

code, implementing 95, 96

creating, for datasets 95

data, sorting by feature order 98

displaying, with HTML code 96, 97

sorting 97, 98

sorting, by alphabetical order 102

sorting, by amount missing/zero 103

sorting, by distribution distance 103, 104, 105

sorting, by non-uniformity 99, 100, 101, 102

sorting, with XAI 98, 99

follow-up 249

G

General Data Protection Regulation (GDPR) 169

Google Assistant 264, 265

Google Colaboratory

Facet, installing 93

LIME, installing on 275

Google Dialogflow

access, via writing Python client 241, 242, 243, 244

agent, creating 236, 237, 238, 239

CUI XAI dialog, using 259

dialog function, creating 245, 246

enhancing, for Python client 245

integration, for website 260, 261, 262, 263

intent, creating 247, 248

interacting, with Python client 258, 259

URL 236

used, for installing Python client 234, 235

XAI implementation, constraints 246, 247

XAI Python client 254

Google Location History

data extraction tool, using 28, 29, 30, 31

downloading 26, 27, 28

used, by XAI 26

Google Location History data

displaying 31, 32

importing 34

import instructions 33

plotting options, setting up 36, 38, 39, 40

processing, for XAI and basemap 35, 36

reading 31, 32

used, for installing basemap packages 33

Google�s WIT

ethical AI perspective 198

ethical dataset 201, 202, 203

legal perspective 200

gradient boosting classifier 280

I

ImageNet

anchor AI explanations 361

IMDb

reference link 129

IMDb vectorizer

for SHAP 393, 394, 396

intent

creating, in Google Dialogflow 247, 248

follow-up intent, defining 249, 251, 252, 253

response 249

training phrases 248, 249

interactions

inserting, in MDP 255, 256, 257

intercepted dataset reviews, with SHAP 147

negative review 147, 149

positive review 149, 150

interception functions 285

interpretability 6

inverse document frequency (IDF) 129

J

Jupyter Notebook XAI agent manager 263

K

key principles, SHAP 117

additivity 119

null player 118, 119

symmetry 117, 118

L

L1 norm 316, 318

L2 norm 319, 320

LIME

vectorizer 391, 393

LIME explainer 286, 287

creating 288, 289

LIME explanations

conclusions 295

interpreting 290

predictions, as list 290, 291

with plot 292, 293, 294

linear models

defining 141, 142

explainer, creating 143

output, creating 138, 139, 140

output, training 138, 139, 140

output, visualizing 138, 139, 140

linear model�s prediction output

explaining 145, 147

intercepted dataset reviews, with SHAP 147

original IMDb reviews, explaining with SHAP 150, 151, 152

Local Interpretable Model-Agnostic Explanations (LIME) 270, 271, 274

installing, on Google Colaboratory 275

mathematical representation 272, 273, 274

M

marginal contribution, feature 386

mathematical perspective 386, 387

Markov decision process (MDP)

interactions, inserting 256, 257

interactions, inserting in 255

Matplotlib

documentation, reference link 33

medical diagnosis experimental program

XAI, applying 45

MIT Moral Machine experiment

reference link 57

ML bias 83, 84, 85

ML ethics and laws

about 85

emotional intelligence, in autopilot 87, 88

traffic regulations, override avoiding 85, 87

traffic regulations, overriding 87

ML perspectives, U.S. census data problem

anticipated outputs, analysis conclusion 183, 184

anticipated outputs, verifying 177

anticipated outputs, verifying with KMC 177, 178, 179, 180

input data, transforming 184, 185, 186

KMC algorithm output, analyzing 180, 181, 182, 183

training data, analyzing with Facets 173, 174, 175, 176

training data, displaying with Facets Dive 170, 172, 173

MNIST

CEM, applying to 333

model-agnostic approach 122

model outputs 212, 213, 214, 215

O

original IMDb reviews, explaining with SHAP 150, 151, 152

negative review sample 152, 153

positive review sample 153, 155

P

performance and fairness, WIT

AUC 226, 227

confusion matrix 229

cost ratio 223

fairness 224, 225

ground truth 222

PR curve 228

ROC 225, 227

slicing 224

pertinent negative explanation

CEM explainer, initializing 349

creating 348

creation, by setting CEM parameters 348, 349

visualizing 350, 351

pertinent negative (PN) 343

contrastive explanation, visualizing 348

pertinent positive (PP) 343

contrastive explanation, visualizing 347

plot function

creating 143, 144, 145

precision-recall curves (PR) 228

Python

KNN algorithm, building 12, 13, 14, 16, 17, 18, 19

Python client

APIs and services, enabling 239, 240, 241

installing, for Google Dialogflow 234, 235

used, for enhancing Google Dialogflow 245

used, for interacting Google Dialogflow 258, 259

writing, to access Google Dialogflow 241, 242, 243, 244

Python Imaging Library (PIL) 322

Python marginal cognitive contribution function 387, 388, 390

R

Race Equality Directive (RED) 169

receiver operating characteristic (ROC) 225

S

scores

interpreting 282

self-driving cars (SDCs)

AI bias, using 55

sentiment analysis 301

sentiment analysis example, SHAP 122, 123

value, for excellent 126

value, for good 124, 125

values, verifying 127

service-level agreement (SLA) 8

SHAP explainer

creating 211

values plot 212

SHapley Additive exPlanations (SHAP)

about 117

data, importing 129, 130

data interception function 132, 133, 134, 135

dataset, intercepting 130

datasets, vectorizing 136, 137

IMDb vectorizer 393, 394, 396

installing 128

key principles 117

modules, importing 128

sentiment analysis example 122, 123

starting with 128

unit tests 130, 131

used, for explaining agnostic model 143

used, for explaining intercepted dataset reviews 147

used, for explaining original IMDb reviews 150, 155

value, mathematical expression 120, 121, 122

SHAP values 212, 214, 215

standard AI program, used by practitioner 11

KNN algorithm, defining 11, 12

subject matter expert (SME) 19

T

text frequency (TF) 129

true positives (TP) 223

U

U.S. census data problem

about 161, 162

ethical perspective 167

legal perspective 168, 169, 170

ML perspectives 170

moral perspectives 165, 166

pandas, using to display data 162, 163, 164

V

vectorizer

for LIME 391, 392, 393

vectorizers

cognitive approach 390, 391

virtualenv

reference link 235

W

West Nile virus 19

in Chicago 24, 25

medical example 19, 20, 21, 22, 23

What-If Tool (WIT)

applying, to transformed dataset 186, 187, 188, 189, 190, 191, 192, 193, 194, 195

creating 216, 217

datapoint explorer 216, 218, 219, 220, 221

data, preprocessing 206, 207, 208

dataset, importing 205, 206

data structures creation, for training and testing 208

Features 216, 221, 222

performance and fairness 216, 222

starting with 204, 205

white box 5

WIT

counterfactual distances, visualizing 302, 303

work in progress (WIP) 253

X

XAI

applying, to autopilot decision tree 74

executive function 7, 8, 9

implementing 8

KNN, enhancing 41, 42, 43, 44, 45

used, for concluding critical diagnosis 50

used, for enhancing AI diagnosis 41

using, to control autopilot decision tree 81

XAI, applying medical diagnosis experimental program

mosquito detection data and natural language explanations, displaying 50

XAI, applying to medical diagnosis experimental program 45

KNN plot, displaying 46

Location History map, displaying 48, 49

mosquito detection data and natural language explanations, displaying 49

natural language explanations 47, 48

XAI approaches

AI to explain 9

expert 8

explaining 8

explicit 8

implicit 8

intuitive 8

objective 8

subjective 8

XAI implementation

constraints, on Google Dialogflow 246, 247

XAI medical diagnosis timeline 10

KNN algorithm, building in Python 12, 13, 14, 15, 17, 18, 19

standard AI program, used by practitioner 11

XAI Python client

about 254

interactions, inserting in MDP 255, 256, 257

XAI white box models

black box models, migrating to 4, 5