0% found this document useful (0 votes)
9 views72 pages

Explainable AI Recipes: Implement Solutions To Model Explainability and Interpretability With Python 1st Edition Pradeepta Mishra

The document promotes the ebook 'Explainable AI Recipes' by Pradeepta Mishra, which focuses on model explainability and interpretability using Python. It provides links to download this and other related ebooks on AI and machine learning from ebookmass.com. The content includes various recipes for implementing solutions to enhance understanding of AI models.

Uploaded by

curtyameyaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views72 pages

Explainable AI Recipes: Implement Solutions To Model Explainability and Interpretability With Python 1st Edition Pradeepta Mishra

The document promotes the ebook 'Explainable AI Recipes' by Pradeepta Mishra, which focuses on model explainability and interpretability using Python. It provides links to download this and other related ebooks on AI and machine learning from ebookmass.com. The content includes various recipes for implementing solutions to enhance understanding of AI models.

Uploaded by

curtyameyaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Download the full version and explore a variety of ebooks

or textbooks at https://ebookmass.com

Explainable AI Recipes: Implement Solutions to


Model Explainability and Interpretability with
Python 1st Edition Pradeepta Mishra

_____ Follow the link below to get your download now _____

https://ebookmass.com/product/explainable-ai-recipes-
implement-solutions-to-model-explainability-and-
interpretability-with-python-1st-edition-pradeepta-mishra/

Access ebookmass.com now to download high-quality


ebooks or textbooks
Here are some recommended products for you. Click the link to
download, or explore more at ebookmass.com

Explainable AI Recipes: Implement Solutions to Model


Explainability and Interpretability with Python 1st
Edition Pradeepta Mishra
https://ebookmass.com/product/explainable-ai-recipes-implement-
solutions-to-model-explainability-and-interpretability-with-
python-1st-edition-pradeepta-mishra-2/

Productionizing AI: How to Deliver AI B2B Solutions with


Cloud and Python 1st Edition Barry Walsh

https://ebookmass.com/product/productionizing-ai-how-to-deliver-
ai-b2b-solutions-with-cloud-and-python-1st-edition-barry-walsh/

Introduction to Responsible AI: Implement Ethical AI Using


Python 1st Edition Manure

https://ebookmass.com/product/introduction-to-responsible-ai-
implement-ethical-ai-using-python-1st-edition-manure/

Productionizing AI: How to Deliver AI B2B Solutions with


Cloud and Python 1st Edition Barry Walsh

https://ebookmass.com/product/productionizing-ai-how-to-deliver-
ai-b2b-solutions-with-cloud-and-python-1st-edition-barry-walsh-2/
Time Series Algorithms Recipes: Implement Machine Learning
and Deep Learning Techniques with Python Akshay R Kulkarni

https://ebookmass.com/product/time-series-algorithms-recipes-
implement-machine-learning-and-deep-learning-techniques-with-python-
akshay-r-kulkarni/

PyTorch Recipes: A Problem-Solution Approach to Build,


Train and Deploy Neural Network Models, 2nd Edition
Pradeepta Mishra
https://ebookmass.com/product/pytorch-recipes-a-problem-solution-
approach-to-build-train-and-deploy-neural-network-models-2nd-edition-
pradeepta-mishra/

Introduction to Datafication : Implement Datafication


Using AI and ML Algorithms Shivakumar R. Goniwada

https://ebookmass.com/product/introduction-to-datafication-implement-
datafication-using-ai-and-ml-algorithms-shivakumar-r-goniwada-2/

Introduction to Datafication: Implement Datafication Using


AI and ML Algorithms Shivakumar R. Goniwada

https://ebookmass.com/product/introduction-to-datafication-implement-
datafication-using-ai-and-ml-algorithms-shivakumar-r-goniwada/

Introduction to Prescriptive AI: A Primer for Decision


Intelligence Solutioning with Python Akshay Kulkarni

https://ebookmass.com/product/introduction-to-prescriptive-ai-a-
primer-for-decision-intelligence-solutioning-with-python-akshay-
kulkarni/
Explainable AI Recipes: Implement Solutions to Model Explainability and
Interpretability with Python
Pradeepta Mishra
Bangalore, Karnataka, India

ISBN-13 (pbk): 978-1-4842-9028-6 ISBN-13 (electronic): 978-1-4842-9029-3


https://doi.org/10.1007/978-1-4842-9029-3

Copyright © 2023 by Pradeepta Mishra


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: James Markham
Coordinating Editor: Mark Powers
Copy Editor: Kim Wimpsett
Cover designed by eStudioCalamar
Cover image by Marek Piwinicki on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY
10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected],
or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance
Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on GitHub (https://github.com/Apress). For more detailed information,
please visit www.apress.com/source-code.
Printed on acid-free paper
I dedicate this book to my late father; my mother; my lovely
wife, Prajna; and my daughters, Priyanshi (Aarya) and
Adyanshi (Aadya). This work would not have been possible
without their inspiration, support, and encouragement.
Table of Contents
About the Author������������������������������������������������������������������������������xvii

About the Technical Reviewer�����������������������������������������������������������xix

Acknowledgments�����������������������������������������������������������������������������xxi

Introduction�������������������������������������������������������������������������������������xxiii

Chapter 1: Introducing Explainability and Setting Up


Your Development Environment�����������������������������������������������������������1
Recipe 1-1. SHAP Installation�������������������������������������������������������������������������������3
Problem�����������������������������������������������������������������������������������������������������������3
Solution�����������������������������������������������������������������������������������������������������������3
How It Works���������������������������������������������������������������������������������������������������4
Recipe 1-2. LIME Installation��������������������������������������������������������������������������������6
Problem�����������������������������������������������������������������������������������������������������������6
Solution�����������������������������������������������������������������������������������������������������������6
How It Works���������������������������������������������������������������������������������������������������6
Recipe 1-3. SHAPASH Installation�������������������������������������������������������������������������8
Problem�����������������������������������������������������������������������������������������������������������8
Solution�����������������������������������������������������������������������������������������������������������8
How It Works���������������������������������������������������������������������������������������������������9
Recipe 1-4. ELI5 Installation���������������������������������������������������������������������������������9
Problem�����������������������������������������������������������������������������������������������������������9
Solution�����������������������������������������������������������������������������������������������������������9
How It Works���������������������������������������������������������������������������������������������������9

v
Table of Contents

Recipe 1-5. Skater Installation����������������������������������������������������������������������������11


Problem���������������������������������������������������������������������������������������������������������11
Solution���������������������������������������������������������������������������������������������������������11
How It Works�������������������������������������������������������������������������������������������������11
Recipe 1-6. Skope-rules Installation�������������������������������������������������������������������12
Problem���������������������������������������������������������������������������������������������������������12
Solution���������������������������������������������������������������������������������������������������������12
How It Works�������������������������������������������������������������������������������������������������12
Recipe 1-7. Methods of Model Explainability������������������������������������������������������13
Problem���������������������������������������������������������������������������������������������������������13
Solution���������������������������������������������������������������������������������������������������������13
How It Works�������������������������������������������������������������������������������������������������14
Conclusion����������������������������������������������������������������������������������������������������������15

Chapter 2: Explainability for Linear Supervised Models���������������������17


Recipe 2-1. SHAP Values for a Regression Model on All Numerical
Input Variables����������������������������������������������������������������������������������������������������18
Problem���������������������������������������������������������������������������������������������������������18
Solution���������������������������������������������������������������������������������������������������������18
How It Works�������������������������������������������������������������������������������������������������18
Recipe 2-2. SHAP Partial Dependency Plot for a Regression Model�������������������25
Problem���������������������������������������������������������������������������������������������������������25
Solution���������������������������������������������������������������������������������������������������������25
How It Works�������������������������������������������������������������������������������������������������25
Recipe 2-3. SHAP Feature Importance for Regression Model with
All Numerical Input Variables������������������������������������������������������������������������������29
Problem���������������������������������������������������������������������������������������������������������29
Solution���������������������������������������������������������������������������������������������������������29
How It Works�������������������������������������������������������������������������������������������������29

vi
Table of Contents

Recipe 2-4. SHAP Values for a Regression Model on All Mixed


Input Variables����������������������������������������������������������������������������������������������������31
Problem���������������������������������������������������������������������������������������������������������31
Solution���������������������������������������������������������������������������������������������������������32
How It Works�������������������������������������������������������������������������������������������������32
Recipe 2-5. SHAP Partial Dependency Plot for Regression Model
for Mixed Input����������������������������������������������������������������������������������������������������35
Problem���������������������������������������������������������������������������������������������������������35
Solution���������������������������������������������������������������������������������������������������������36
How It Works�������������������������������������������������������������������������������������������������36
Recipe 2-6. SHAP Feature Importance for a Regression Model with
All Mixed Input Variables�������������������������������������������������������������������������������������41
Problem���������������������������������������������������������������������������������������������������������41
Solution���������������������������������������������������������������������������������������������������������41
How It Works�������������������������������������������������������������������������������������������������41
Recipe 2-7. SHAP Strength for Mixed Features on the Predicted Output
for Regression Models����������������������������������������������������������������������������������������43
Problem���������������������������������������������������������������������������������������������������������43
Solution���������������������������������������������������������������������������������������������������������43
How It Works�������������������������������������������������������������������������������������������������43
Recipe 2-8. SHAP Values for a Regression Model on Scaled Data���������������������44
Problem���������������������������������������������������������������������������������������������������������44
Solution���������������������������������������������������������������������������������������������������������44
How It Works�������������������������������������������������������������������������������������������������45
Recipe 2-9. LIME Explainer for Tabular Data�������������������������������������������������������48
Problem���������������������������������������������������������������������������������������������������������48
Solution���������������������������������������������������������������������������������������������������������49
How It Works�������������������������������������������������������������������������������������������������49

vii
Table of Contents

Recipe 2-10. ELI5 Explainer for Tabular Data������������������������������������������������������51


Problem���������������������������������������������������������������������������������������������������������51
Solution���������������������������������������������������������������������������������������������������������51
How It Works�������������������������������������������������������������������������������������������������51
Recipe 2-11. How the Permutation Model in ELI5 Works������������������������������������53
Problem���������������������������������������������������������������������������������������������������������53
Solution���������������������������������������������������������������������������������������������������������53
How It Works�������������������������������������������������������������������������������������������������54
Recipe 2-12. Global Explanation for Logistic Regression Models�����������������������54
Problem���������������������������������������������������������������������������������������������������������54
Solution���������������������������������������������������������������������������������������������������������54
How It Works�������������������������������������������������������������������������������������������������55
Recipe 2-13. Partial Dependency Plot for a Classifier����������������������������������������58
Problem���������������������������������������������������������������������������������������������������������58
Solution���������������������������������������������������������������������������������������������������������58
How It Works�������������������������������������������������������������������������������������������������58
Recipe 2-14. Global Feature Importance from the Classifier������������������������������61
Problem���������������������������������������������������������������������������������������������������������61
Solution���������������������������������������������������������������������������������������������������������61
How It Works�������������������������������������������������������������������������������������������������61
Recipe 2-15. Local Explanations Using LIME������������������������������������������������������63
Problem���������������������������������������������������������������������������������������������������������63
Solution���������������������������������������������������������������������������������������������������������63
How It Works�������������������������������������������������������������������������������������������������63
Recipe 2-16. Model Explanations Using ELI5������������������������������������������������������67
Problem���������������������������������������������������������������������������������������������������������67
Solution���������������������������������������������������������������������������������������������������������67
How It Works�������������������������������������������������������������������������������������������������67

viii
Table of Contents

Conclusion����������������������������������������������������������������������������������������������������������71
References����������������������������������������������������������������������������������������������������������72

Chapter 3: Explainability for Nonlinear Supervised Models���������������73


Recipe 3-1. SHAP Values for Tree Models on All Numerical Input Variables�������74
Problem���������������������������������������������������������������������������������������������������������74
Solution���������������������������������������������������������������������������������������������������������74
How It Works�������������������������������������������������������������������������������������������������74
Recipe 3-2. Partial Dependency Plot for Tree Regression Model������������������������81
Problem���������������������������������������������������������������������������������������������������������81
Solution���������������������������������������������������������������������������������������������������������81
How It Works�������������������������������������������������������������������������������������������������81
Recipe 3-3. SHAP Feature Importance for Regression Models with
All Numerical Input Variables������������������������������������������������������������������������������82
Problem���������������������������������������������������������������������������������������������������������82
Solution���������������������������������������������������������������������������������������������������������83
How It Works�������������������������������������������������������������������������������������������������83
Recipe 3-4. SHAP Values for Tree Regression Models with All Mixed
Input Variables����������������������������������������������������������������������������������������������������85
Problem���������������������������������������������������������������������������������������������������������85
Solution���������������������������������������������������������������������������������������������������������85
How It Works�������������������������������������������������������������������������������������������������85
Recipe 3-5. SHAP Partial Dependency Plot for Regression Models with
Mixed Input���������������������������������������������������������������������������������������������������������87
Problem���������������������������������������������������������������������������������������������������������87
Solution���������������������������������������������������������������������������������������������������������87
How It Works�������������������������������������������������������������������������������������������������88

ix
Table of Contents

Recipe 3-6. SHAP Feature Importance for Tree Regression Models with
All Mixed Input Variables�������������������������������������������������������������������������������������90
Problem���������������������������������������������������������������������������������������������������������90
Solution���������������������������������������������������������������������������������������������������������91
How It Works�������������������������������������������������������������������������������������������������91
Recipe 3-7. LIME Explainer for Tabular Data�������������������������������������������������������93
Problem���������������������������������������������������������������������������������������������������������93
Solution���������������������������������������������������������������������������������������������������������93
How It Works�������������������������������������������������������������������������������������������������93
Recipe 3-8. ELI5 Explainer for Tabular Data��������������������������������������������������������96
Problem���������������������������������������������������������������������������������������������������������96
Solution���������������������������������������������������������������������������������������������������������96
How It Works�������������������������������������������������������������������������������������������������96
Recipe 3-9. How the Permutation Model in ELI5 Works������������������������������������100
Problem�������������������������������������������������������������������������������������������������������100
Solution�������������������������������������������������������������������������������������������������������101
How It Works�����������������������������������������������������������������������������������������������101
Recipe 3-10. Global Explanation for Decision Tree Models�������������������������������101
Problem�������������������������������������������������������������������������������������������������������101
Solution�������������������������������������������������������������������������������������������������������101
How It Works�����������������������������������������������������������������������������������������������102
Recipe 3-11. Partial Dependency Plot for a Nonlinear Classifier����������������������104
Problem�������������������������������������������������������������������������������������������������������104
Solution�������������������������������������������������������������������������������������������������������104
How It Works�����������������������������������������������������������������������������������������������104
Recipe 3-12. Global Feature Importance from the Nonlinear Classifier������������107
Problem�������������������������������������������������������������������������������������������������������107
Solution�������������������������������������������������������������������������������������������������������107
How It Works�����������������������������������������������������������������������������������������������107
x
Table of Contents

Recipe 3-13. Local Explanations Using LIME����������������������������������������������������108


Problem�������������������������������������������������������������������������������������������������������108
Solution�������������������������������������������������������������������������������������������������������109
How It Works�����������������������������������������������������������������������������������������������109
Recipe 3-14. Model Explanations Using ELI5����������������������������������������������������113
Problem�������������������������������������������������������������������������������������������������������113
Solution�������������������������������������������������������������������������������������������������������113
How It Works�����������������������������������������������������������������������������������������������114
Conclusion��������������������������������������������������������������������������������������������������������117

Chapter 4: Explainability for Ensemble Supervised Models�������������119


Recipe 4-1. Explainable Boosting Machine Interpretation��������������������������������120
Problem�������������������������������������������������������������������������������������������������������120
Solution�������������������������������������������������������������������������������������������������������120
How It Works�����������������������������������������������������������������������������������������������121
Recipe 4-2. Partial Dependency Plot for Tree Regression Models��������������������125
Problem�������������������������������������������������������������������������������������������������������125
Solution�������������������������������������������������������������������������������������������������������125
How It Works�����������������������������������������������������������������������������������������������125
Recipe 4-3. Explain a Extreme Gradient Boosting Model with
All Numerical Input Variables����������������������������������������������������������������������������131
Problem�������������������������������������������������������������������������������������������������������131
Solution�������������������������������������������������������������������������������������������������������131
How It Works�����������������������������������������������������������������������������������������������131
Recipe 4-4. Explain a Random Forest Regressor with Global and
Local Interpretations�����������������������������������������������������������������������������������������136
Problem�������������������������������������������������������������������������������������������������������136
Solution�������������������������������������������������������������������������������������������������������136
How It Works�����������������������������������������������������������������������������������������������136

xi
Table of Contents

Recipe 4-5. Explain the Catboost Regressor with Global and Local
Interpretations��������������������������������������������������������������������������������������������������139
Problem�������������������������������������������������������������������������������������������������������139
Solution�������������������������������������������������������������������������������������������������������139
How It Works�����������������������������������������������������������������������������������������������140
Recipe 4-6. Explain the EBM Classifier with Global and
Local Interpretations�����������������������������������������������������������������������������������������142
Problem�������������������������������������������������������������������������������������������������������142
Solution�������������������������������������������������������������������������������������������������������142
How It Works�����������������������������������������������������������������������������������������������143
Recipe 4-7. SHAP Partial Dependency Plot for Regression Models with
Mixed Input�������������������������������������������������������������������������������������������������������145
Problem�������������������������������������������������������������������������������������������������������145
Solution�������������������������������������������������������������������������������������������������������145
How It Works�����������������������������������������������������������������������������������������������145
Recipe 4-8. SHAP Feature Importance for Tree Regression Models with
Mixed Input Variables����������������������������������������������������������������������������������������149
Problem�������������������������������������������������������������������������������������������������������149
Solution�������������������������������������������������������������������������������������������������������149
How It Works�����������������������������������������������������������������������������������������������150
Recipe 4-9. Explaining the XGBoost Model�������������������������������������������������������154
Problem�������������������������������������������������������������������������������������������������������154
Solution�������������������������������������������������������������������������������������������������������154
How It Works�����������������������������������������������������������������������������������������������154
Recipe 4-10. Random Forest Regressor for Mixed Data Types�������������������������159
Problem�������������������������������������������������������������������������������������������������������159
Solution�������������������������������������������������������������������������������������������������������159
How It Works�����������������������������������������������������������������������������������������������159

xii
Table of Contents

Recipe 4-11. Explaining the Catboost Model����������������������������������������������������162


Problem�������������������������������������������������������������������������������������������������������162
Solution�������������������������������������������������������������������������������������������������������162
How It Works�����������������������������������������������������������������������������������������������162
Recipe 4-12. LIME Explainer for the Catboost Model and Tabular Data������������165
Problem�������������������������������������������������������������������������������������������������������165
Solution�������������������������������������������������������������������������������������������������������165
How It Works�����������������������������������������������������������������������������������������������166
Recipe 4-13. ELI5 Explainer for Tabular Data����������������������������������������������������168
Problem�������������������������������������������������������������������������������������������������������168
Solution�������������������������������������������������������������������������������������������������������168
How It Works�����������������������������������������������������������������������������������������������168
Recipe 4-14. How the Permutation Model in ELI5 Works����������������������������������172
Problem�������������������������������������������������������������������������������������������������������172
Solution�������������������������������������������������������������������������������������������������������172
How It Works�����������������������������������������������������������������������������������������������172
Recipe 4-15. Global Explanation for Ensemble Classification Models��������������173
Problem�������������������������������������������������������������������������������������������������������173
Solution�������������������������������������������������������������������������������������������������������173
How It Works�����������������������������������������������������������������������������������������������173
Recipe 4-16. Partial Dependency Plot for a Nonlinear Classifier����������������������176
Problem�������������������������������������������������������������������������������������������������������176
Solution�������������������������������������������������������������������������������������������������������176
How It Works�����������������������������������������������������������������������������������������������176
Recipe 4-17. Global Feature Importance from the Nonlinear Classifier������������178
Problem�������������������������������������������������������������������������������������������������������178
Solution�������������������������������������������������������������������������������������������������������178
How It Works�����������������������������������������������������������������������������������������������178

xiii
Table of Contents

Recipe 4-18. XGBoost Model Explanation���������������������������������������������������������181


Problem�������������������������������������������������������������������������������������������������������181
Solution�������������������������������������������������������������������������������������������������������181
How It Works�����������������������������������������������������������������������������������������������181
Recipe 4-19. Explain a Random Forest Classifier���������������������������������������������189
Problem�������������������������������������������������������������������������������������������������������189
Solution�������������������������������������������������������������������������������������������������������189
How It Works�����������������������������������������������������������������������������������������������190
Recipe 4-20. Catboost Model Interpretation for Classification Scenario����������192
Problem�������������������������������������������������������������������������������������������������������192
Solution�������������������������������������������������������������������������������������������������������193
How It Works�����������������������������������������������������������������������������������������������193
Recipe 4-21. Local Explanations Using LIME����������������������������������������������������194
Problem�������������������������������������������������������������������������������������������������������194
Solution�������������������������������������������������������������������������������������������������������195
How It Works�����������������������������������������������������������������������������������������������195
Recipe 4-22. Model Explanations Using ELI5����������������������������������������������������198
Problem�������������������������������������������������������������������������������������������������������198
Solution�������������������������������������������������������������������������������������������������������198
How It Works�����������������������������������������������������������������������������������������������198
Recipe 4-23. Multiclass Classification Model Explanation��������������������������������201
Problem�������������������������������������������������������������������������������������������������������201
Solution�������������������������������������������������������������������������������������������������������201
How It Works�����������������������������������������������������������������������������������������������202
Conclusion��������������������������������������������������������������������������������������������������������205

xiv
Table of Contents

Chapter 5: Explainability for Natural Language Processing�������������207


Recipe 5-1. Explain Sentiment Analysis Text Classification Using SHAP����������208
Problem�������������������������������������������������������������������������������������������������������208
Solution�������������������������������������������������������������������������������������������������������208
How It Works�����������������������������������������������������������������������������������������������208
Recipe 5-2. Explain Sentiment Analysis Text Classification Using ELI5������������213
Problem�������������������������������������������������������������������������������������������������������213
Solution�������������������������������������������������������������������������������������������������������213
How It Works�����������������������������������������������������������������������������������������������213
Recipe 5-3. Local Explanation Using ELI5���������������������������������������������������������216
Problem�������������������������������������������������������������������������������������������������������216
Solution�������������������������������������������������������������������������������������������������������216
How It Works�����������������������������������������������������������������������������������������������216
Conclusion��������������������������������������������������������������������������������������������������������218

Chapter 6: Explainability for Time-Series Models����������������������������219


Recipe 6-1. Explain Time-Series Models Using LIME����������������������������������������220
Problem�������������������������������������������������������������������������������������������������������220
Solution�������������������������������������������������������������������������������������������������������220
How It Works�����������������������������������������������������������������������������������������������220
Recipe 6-2. Explain Time-Series Models Using SHAP���������������������������������������228
Problem�������������������������������������������������������������������������������������������������������228
Solution�������������������������������������������������������������������������������������������������������228
How It Works�����������������������������������������������������������������������������������������������228
Conclusion��������������������������������������������������������������������������������������������������������231

xv
Table of Contents

Chapter 7: Explainability for Deep Learning Models������������������������233


Recipe 7-1. Explain MNIST Images Using a Gradient Explainer Based
on Keras������������������������������������������������������������������������������������������������������������234
Problem�������������������������������������������������������������������������������������������������������234
Solution�������������������������������������������������������������������������������������������������������234
How It Works�����������������������������������������������������������������������������������������������234
Recipe 7-2. Use Kernel Explainer–Based SHAP Values from a Keras Model����239
Problem�������������������������������������������������������������������������������������������������������239
Solution�������������������������������������������������������������������������������������������������������239
How It Works�����������������������������������������������������������������������������������������������240
Recipe 7-3. Explain a PyTorch-Based Deep Learning Model����������������������������243
Problem�������������������������������������������������������������������������������������������������������243
Solution�������������������������������������������������������������������������������������������������������243
How It Works�����������������������������������������������������������������������������������������������243
Conclusion��������������������������������������������������������������������������������������������������������249

Index�������������������������������������������������������������������������������������������������251

xvi
About the Author
Pradeepta Mishra is an AI/ML leader,
experienced data scientist, and artificial
intelligence architect. He currently heads
NLP, ML, and AI initiatives for five products at
FOSFOR by LTI, a leading-edge innovator in AI
and machine learning based out of Bangalore,
India. He has expertise in designing artificial
intelligence systems for performing tasks such
as understanding natural language and making
recommendations based on natural language
processing. He has filed 12 patents as an inventor and has authored
and coauthored five books, including R Data Mining Blueprints (Packt
Publishing, 2016), R: Mining Spatial, Text, Web, and Social Media Data
(Packt Publishing, 2017), PyTorch Recipes (Apress, 2019), and Practical
Explainable AI Using Python (Apress, 2023). There are two courses
available on Udemy based on these books.
Pradeepta presented a keynote talk on the application of bidirectional
LSTM for time-series forecasting at the 2018 Global Data Science
Conference. He delivered the TEDx talk “Can Machines Think?” on the
power of artificial intelligence in transforming industries and job roles
across industries. He has also delivered more than 150 tech talks on data
science, machine learning, and artificial intelligence at various meetups,
technical institutions, universities, and community forums. He is on
LinkedIn (www.linkedin.com/in/pradeepta/) and Twitter
(@pradmishra1).

xvii
About the Technical Reviewer
Bharath Kumar Bolla has more than ten years
of experience and is currently working as a
senior data science engineer consultant at
Verizon, Bengaluru. He has a PG diploma in
data science from Praxis Business School and
an MS in life sciences from Mississippi State
University. He previously worked as a data
scientist at the University of Georgia, Emory
University, and Eurofins LLC & Happiest
Minds. At Happiest Minds, he worked on
AI-based digital marketing products and
NLP-based solutions in the education domain. Along with his day-to-day
responsibilities, Bharath is a mentor and an active researcher. To date, he
has published ten articles in journals and peer-reviewed conferences. He is
particularly interested in unsupervised and semisupervised learning and
efficient deep learning architectures in NLP and computer vision.

xix
Acknowledgments
I would like to thank my wife, Prajna, for her continuous inspiration and
support and for sacrificing her weekends to help me complete this book;
and my daughters, Aarya and Aadya, for being patient throughout the
writing process.
A big thank-you to Celestin Suresh John and Mark Powers for fast-­
tracking the whole process and guiding me in the right direction.
I would like to thank the authors of the Appliances Energy Prediction
dataset (http://archive.ics.uci.edu/ml) for making it available: D. Dua
and C. Graff. I use this dataset in the book to show how to develop a model
and explain the predictions generated by a regression model for the
purpose of model explainability using various explainable libraries.

xxi
Introduction
Artificial intelligence plays a crucial role determining the decisions
businesses make. In these cases, when a machine makes a decision,
humans usually want to understand whether the decision is authentic
or whether it was generated in error. If business stakeholders are not
convinced by the decision, they will not trust the machine learning system,
and hence artificial intelligence adoption will gradually reduce within that
organization. To make the decision process more transparent, developers
must be able to document the explainability of AI decisions or ML model
decisions. This book provides a series of solutions to problems that require
explainability and interpretability. Adopting an AI model and developing a
responsible AI system requires explainability as a component.
This book covers model interpretation for supervised learning linear
models, including important features for regression and classification
models, partial dependency analysis for regression and classification
models, and influential data point analysis for both classification and
regression models. Supervised learning models using nonlinear models is
explored using state-of-the-art frameworks such as SHAP values/scores,
including global explanation, and how to use LIME for local interpretation.
This book will also give you an understanding of bagging, boosting-
based ensemble models for supervised learning such as regression and
classification, as well as explainability for time-series models using LIME
and SHAP, natural language processing tasks such as text classification,
and sentiment analysis using ELI5, ALIBI. The most complex models for
classification and regression, such as neural network models and deep
learning models, are explained using the CAPTUM framework, which
shows feature attribution, neuron attribution, and activation attribution.

xxiii
Introduction

This book attempts to make AI models explainable to help developers


increase the adoption of AI-based models within their organizations and
bring more transparency to decision-making. After reading this book,
you will be able to use Python libraries such as Alibi, SHAP, LIME, Skater,
ELI5, and CAPTUM. Explainable AI Recipes provides a problem-solution
approach to demonstrate each machine learning model, and shows how to
use Python’s XAI libraries to answer questions of explainability and build
trust with AI models and machine learning models. All source code can be
downloaded from g­ ithub.com/apress/explainable-ai-recipes.

xxiv
CHAPTER 1

Introducing
Explainability and
Setting Up Your
Development
Environment
Industries in which artificial intelligence has been applied include
banking, financial services, insurance, healthcare, manufacturing, retail,
and pharmaceutical. There are regulatory requirements in some of these
industries where model explainability is required. Artificial intelligence
involves classifying objects, recognizing objects to detect fraud, and so forth.
Every learning system requires three things: input data, processing, and an
output. If the performance of any learning system improves over time by
learning from new examples or data, it is called a machine learning system.
When the number of features for a machine learning task increases or the
volume of data increases, it takes a lot of time to apply machine learning
techniques. That’s when deep learning techniques are used.
Figure 1-1 represents the relationships between artificial intelligence,
machine learning, and deep learning.

© Pradeepta Mishra 2023 1


P. Mishra, Explainable AI Recipes, https://doi.org/10.1007/978-1-4842-9029-3_1
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT

Figure 1-1. Relationships among ML, DL, and AI

After preprocessing and feature creation, you can observe hundreds


of thousands of features that need to be computed to produce output. If
we train a machine learning supervised model, it will take significant time
to produce the model object. To achieve scalability in this task, we need
deep learning algorithms, such as a recurrent neural network. This is how
artificial intelligence is connected to deep learning and machine learning.
In the classical predictive modeling scenario, a function is identified,
and the input data is usually fit to the function to produce the output,
where the function is usually predetermined. In a modern predictive
modeling scenario, the input data and output are both shown to a group of
functions, and the machine identifies the best function that approximates
well to the output given a particular set of input. There is a need to explain
the output of a machine learning and deep learning model in performing
regression- and classification-related tasks. These are the reasons why
explainability is required:

• Trust: To gain users’ trust on the predicted output

• Reliability: To make the user rely on the


predicted output

• Regulatory: To meet regulatory and compliance


requirements

2
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
• Adoption: To increase AI adoption among the users

• Fairness: To remove any kind of discrimination in


prediction
• Accountability: To establish ownership of the
predictions

There are various ways that explainability can be achieved using


statistical properties, probabilistic properties and associations, and
causality among the features. Broadly, the explanations of the models
can be classified into two categories, global explanations and local
explanations. The objective of local explanation is to understand the
inference generated for one sample at a time by comparing the nearest
possible data point; global explanation provides an idea about the overall
model behavior.
The goal of this chapter is to introduce how to install various
explainability libraries and interpret the results generated by those
explainability libraries.

Recipe 1-1. SHAP Installation


P
 roblem
You want to install the SHAP (shapely additive explanations) library.

S
 olution
The solution to this problem is to use the simple pip or conda option.

3
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
How It Works
Let’s take a look at the following script examples. The SHAP Python library
is based on a game theoretic approach that attempts to explain local and
as well as global explanations.

pip install shap

or

conda install -c conda-forge shap

Looking in indexes: https://pypi.org/simple, https://us-python.


pkg.dev/colab-wheels/public/simple/
Collecting shap
  Downloading shap-0.41.0-cp37-cp37m-manylinux_2_12_x86_64.
manylinux2010_x86_64.whl (569 kB)
     |█████████████████████
███████████| 569 kB 8.0 MB/s
Requirement already satisfied: tqdm>4.25.0 in /usr/local/lib/
python3.7/dist-packages (from shap) (4.64.1)
Requirement already satisfied: pandas in /usr/local/lib/
python3.7/dist-packages (from shap) (1.3.5)
Collecting slicer==0.0.7
  Downloading slicer-0.0.7-py3-none-any.whl (14 kB)
Requirement already satisfied: cloudpickle in /usr/local/lib/
python3.7/dist-packages (from shap) (1.5.0)
Requirement already satisfied: scipy in /usr/local/lib/
python3.7/dist-packages (from shap) (1.7.3)
Requirement already satisfied: scikit-learn in /usr/local/lib/
python3.7/dist-packages (from shap) (1.0.2)
Requirement already satisfied: numpy in /usr/local/lib/
python3.7/dist-packages (from shap) (1.21.6)
Requirement already satisfied: numba in /usr/local/lib/
python3.7/dist-packages (from shap) (0.56.2)
4
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
Requirement already satisfied: packaging>20.9 in /usr/local/
lib/python3.7/dist-packages (from shap) (21.3)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /
usr/local/lib/python3.7/dist-packages (from packaging>20.9->
shap) (3.0.9)
Requirement already satisfied: llvmlite<0.40,>=0.39.0dev0 in
/usr/local/lib/python3.7/dist-packages (from numba->shap)
(0.39.1)
Requirement already satisfied: setuptools<60 in /usr/local/lib/
python3.7/dist-packages (from numba->shap) (57.4.0)
Requirement already satisfied: importlib-metadata in /usr/
local/lib/python3.7/dist-packages (from numba->shap) (4.12.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /
usr/local/lib/python3.7/dist-packages (from importlib-metadata->
numba->shap) (4.1.1)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/
python3.7/dist-packages (from importlib-metadata->numba->
shap) (3.8.1)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/
local/lib/python3.7/dist-packages (from pandas->shap) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/
python3.7/dist-packages (from pandas->shap) (2022.2.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/
python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->
shap) (1.15.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/
local/lib/python3.7/dist-packages (from scikit-learn->
shap) (3.1.0)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/
python3.7/dist-packages (from scikit-learn->shap) (1.1.0)
Installing collected packages: slicer, shap
Successfully installed shap-0.41.0 slicer-0.0.7

5
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
Recipe 1-2. LIME Installation
Problem
You want to install the LIME Python library.

Solution
You can install the LIME library using pip or conda.

How It Works
Let’s take a look at the following example script:

pip install lime

or

conda install -c conda-forge lime

Looking in indexes: https://pypi.org/simple, https://us-python.


pkg.dev/colab-wheels/public/simple/
Collecting lime
  Downloading lime-0.2.0.1.tar.gz (275 kB)
     |████████████████████
████████████| 275 kB 7.5 MB/s
Requirement already satisfied: matplotlib in /usr/local/lib/
python3.7/dist-packages (from lime) (3.2.2)
Requirement already satisfied: numpy in /usr/local/lib/
python3.7/dist-packages (from lime) (1.21.6)
Requirement already satisfied: scipy in /usr/local/lib/
python3.7/dist-packages (from lime) (1.7.3)
Requirement already satisfied: tqdm in /usr/local/lib/
python3.7/dist-packages (from lime) (4.64.1)

6
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
Requirement already satisfied: scikit-learn>=0.18 in /usr/
local/lib/python3.7/dist-packages (from lime) (1.0.2)
Requirement already satisfied: scikit-image>=0.12 in /usr/
local/lib/python3.7/dist-packages (from lime) (0.18.3)
Requirement already satisfied: networkx>=2.0 in /usr/local/lib/
python3.7/dist-packages (from scikit-image>=0.12->lime) (2.6.3)
Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/
lib/python3.7/dist-packages (from scikit-image>=0.12->
lime) (1.3.0)
Requirement already satisfied: pillow!=7.1.0,!=7.1.1,>=4.3.0 in
/usr/local/lib/python3.7/dist-packages (from scikit-­
image>=0.12->lime) (7.1.2)
Requirement already satisfied: imageio>=2.3.0 in /usr/local/
lib/python3.7/dist-packages (from scikit-image>=0.12->
lime) (2.9.0)
Requirement already satisfied: tifffile>=2019.7.26 in /usr/
local/lib/python3.7/dist-packages (from scikit-image>=0.12->
lime) (2021.11.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/
lib/python3.7/dist-packages (from matplotlib->lime) (1.4.4)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/
python3.7/dist-packages (from matplotlib->lime) (0.11.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/
local/lib/python3.7/dist-packages (from matplotlib->
lime) (2.8.2)
Requirement already satisfied:
pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/
python3.7/dist-packages (from matplotlib->lime) (3.0.9)
Requirement already satisfied: typing-extensions in /usr/local/
lib/python3.7/dist-packages (from kiwisolver>=1.0.1->
matplotlib->lime) (4.1.1)

7
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
Requirement already satisfied: six>=1.5 in /usr/local/lib/
python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->
lime) (1.15.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/
local/lib/python3.7/dist-packages (from scikit-learn>=0.18->
lime) (3.1.0)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/
python3.7/dist-packages (from scikit-learn>=0.18->lime) (1.1.0)
Building wheels for collected packages: lime
  Building wheel for lime (setup.py) ... done
  Created wheel for lime: filename=lime-0.2.0.1-py3-none-any.
whl size=283857 sha256=674ceb94cdcb54588f66c5d5bef5f6ae0326c7
6e645c40190408791cbe4311d5
  Stored in directory: /root/.cache/pip/wheels/ca/cb/e5/
ac701e12d365a08917bf4c6171c0961bc880a8181359c66aa7
Successfully built lime
Installing collected packages: lime
Successfully installed lime-0.2.0.1

Recipe 1-3. SHAPASH Installation


Problem
You want to install SHAPASH.

Solution
If you want to use a combination of functions from both the LIME library
and the SHAP library, then you can use the SHAPASH library. You just have
to install it, which is simple.

8
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
How It Works
Let’s take a look at the following code to install SHAPASH. This is not
available on the Anaconda distribution; the only way to install it is by
using pip.

pip install shapash

Recipe 1-4. ELI5 Installation


P
 roblem
You want to install ELI5.

S
 olution
Since this is a Python library, you can use pip.

How It Works
Let’s take a look at the following script:

pip install eli5


Looking in indexes: https://pypi.org/simple, https://us-python.
pkg.dev/colab-wheels/public/simple/
Collecting eli5
  Downloading eli5-0.13.0.tar.gz (216 kB)
     |████████████████████
████████████| 216 kB 6.9 MB/s
Requirement already satisfied: attrs>17.1.0 in /usr/local/lib/
python3.7/dist-packages (from eli5) (22.1.0)
Collecting jinja2>=3.0.0

9
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     |████████████████████
████████████| 133 kB 42.7 MB/s
Requirement already satisfied: numpy>=1.9.0 in /usr/local/lib/
python3.7/dist-packages (from eli5) (1.21.6)
Requirement already satisfied: scipy in /usr/local/lib/
python3.7/dist-packages (from eli5) (1.7.3)
Requirement already satisfied: six in /usr/local/lib/python3.7/
dist-packages (from eli5) (1.15.0)
Requirement already satisfied: scikit-learn>=0.20 in /usr/
local/lib/python3.7/dist-packages (from eli5) (1.0.2)
Requirement already satisfied: graphviz in /usr/local/lib/
python3.7/dist-packages (from eli5) (0.10.1)
Requirement already satisfied: tabulate>=0.7.7 in /usr/local/
lib/python3.7/dist-packages (from eli5) (0.8.10)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/
lib/python3.7/dist-packages (from jinja2>=3.0.0->eli5) (2.0.1)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/
python3.7/dist-packages (from scikit-learn>=0.20->eli5) (1.1.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/
local/lib/python3.7/dist-packages (from scikit-learn>=0.20->
eli5) (3.1.0)
Building wheels for collected packages: eli5
  Building wheel for eli5 (setup.py) ... done
  Created wheel for eli5: filename=eli5-0.13.0-py2.py3-none-­
any.whl size=107748 sha256=3e02d416bd1cc21aebce60420712991
9a096a92128d7d27c50be1f3a97d3b1de
  Stored in directory: /root/.cache/pip/wheels/cc/3c/96/3ead31a
8e6c20fc0f1a707fde2e05d49a80b1b4b30096573be
Successfully built eli5
Installing collected packages: jinja2, eli5

10
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
  Attempting uninstall: jinja2
    Found existing installation: Jinja2 2.11.3
    Uninstalling Jinja2-2.11.3:
      Successfully uninstalled Jinja2-2.11.3
ERROR: pip's dependency resolver does not currently take into
account all the packages that are installed. This behavior is
the source of the following dependency conflicts.
flask 1.1.4 requires Jinja2<3.0,>=2.10.1, but you have jinja2
3.1.2 which is incompatible.
Successfully installed eli5-0.13.0 jinja2-3.1.2

Recipe 1-5. Skater Installation


P
 roblem
You want to install Skater.

S
 olution
Skater is an open-source framework to enable model interpretation for
various kinds of machine learning models. The Python-based Skater
library provides both global and local interpretations and can be installed
using pip.

How It Works
Let’s take a look at the following script:

pip install skater

11
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
Recipe 1-6. Skope-rules Installation
Problem
You want to install Skopes-rule.

Solution
Skope-rules offers a trade-off between the interpretability of a decision tree
and the modeling power of a random forest model. The solution is simple;
you use the pip command.

How It Works
Let’s take a look at the following code:

pip install skope-rules


Looking in indexes: https://pypi.org/simple, https://us-python.
pkg.dev/colab-wheels/public/simple/
Collecting skope-rules
  Downloading skope_rules-1.0.1-py3-none-any.whl (14 kB)
Requirement already satisfied: numpy>=1.10.4 in /usr/local/lib/
python3.7/dist-packages (from skope-rules) (1.21.6)
Requirement already satisfied: scikit-learn>=0.17.1 in /usr/
local/lib/python3.7/dist-packages (from skope-rules) (1.0.2)
Requirement already satisfied: pandas>=0.18.1 in /usr/local/
lib/python3.7/dist-packages (from skope-rules) (1.3.5)
Requirement already satisfied: scipy>=0.17.0 in /usr/local/lib/
python3.7/dist-packages (from skope-rules) (1.7.3)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/
python3.7/dist-packages (from pandas>=0.18.1->skope-rules)
(2022.2.1)

12
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/
local/lib/python3.7/dist-packages (from pandas>=0.18.1->skope-­
rules) (2.8.2)
Requirement already satisfied: six>=1.5 in /usr/local/lib/
python3.7/dist-packages (from python-dateutil>=2.7.3->
pandas>=0.18.1->skope-rules) (1.15.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/
local/lib/python3.7/dist-packages (from scikit-learn>=0.17.1->
skope-rules) (3.1.0)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/
python3.7/dist-packages (from scikit-learn>=0.17.1->skope-­
rules) (0.11)
Installing collected packages: skope-rules
Successfully installed skope-rules-1.0.1

Recipe 1-7. Methods of Model Explainability


P
 roblem
There are various libraries and many explanations for how to identify the
right method for model explainability.

S
 olution
The explainability method depends on who is the consumer of the model
output, if it is the business or senior management then the explainability
should be very simple and plain English without any mathematical
formula and if the consumer of explainability is data scientists and
machine learning engineers then the explanations may include the
mathematical formulas.

13
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
    ENVIRONMENT
How It Works
The levels of transparency of the machine learning models can be
categorized into three buckets, as shown in Figure 1-2.

DĞƚŚŽĚƐŽĨ EĂƚƵƌĂů>ĂŶŐƵĂŐĞ'ĞŶĞƌĂƟŽŶ
džƉůĂŝŶĂďŝůŝƚLJ
dĞdžƚƵĂůdžƉůĂŝŶĂďŝůŝƚLJ
^ƵŵŵĂƌLJ'ĞŶĞƌĂƟŽŶ

sŝƐƵĂůdžƉůĂŝŶĂďŝůŝƚLJ dƌĞĞďĂƐĞĚ&ůŽǁĐŚĂƌƚ
ZƵůĞdžƚƌĂĐƟŽŶ

džĂŵƉůĞĂƐĞĚ hƐŝŶŐĐŽŵŵŽŶĞdžĂŵƉůĞƐ
ƵƐŝŶĞƐƐ^ĐĞŶĂƌŝŽƐ

Figure 1-2. Methods of model explainability

Textual explanations require explaining the mathematical formula in


plain English, which can help business users or senior management. The
interpretations can be designed based on model type and model variant
and can draw inferences from the model outcome. A template to draw
inferences can be designed and mapped to the model types, and then
the templates can be filled in using some natural language processing
methods.
A visual explainability method can be used to generate charts, graphs
such as dendrograms, or any other types of graphs that best explain the
relationships. The tree-based methods use if-else conditions on the back
end; hence, it is simple to show the causality and the relationship.
Using common examples and business scenarios from day-to-day
operations and drawing parallels between them can also be useful.
Which method you should choose depends on the problem that needs
to be solved and the consumer of the solution where the machine learning
model is being used.

14
Chapter 1 INTRODUCING EXPLAINABILITY AND SETTING UP YOUR DEVELOPMENT
ENVIRONMENT
C
 onclusion
In various AI projects and initiatives, the machine learning models
generate predictions. Usually, to trust the outcomes of a model, a detailed
explanation is required. Since many people are not comfortable explaining
the machine learning model outcomes, they cannot reason out the
decisions of a model, and thereby AI adoption is restricted. Explainability
is required from regulatory stand point as well as auditing and compliance
point of view. In high-risk use cases such as medical imaging and object
detection or pattern recognition, financial prediction and fraud detection,
etc., explainability is required to explain the decisions of the machine
learning model.
In this chapter, we set up the environment by installing various
explainable AI libraries. Machine learning model interpretability and
explainability are the key focuses of this book. We are going to use Python-­
based libraries, frameworks, methods, classes, and functions to explain
the models.
In the next chapter, we are going to look at the linear models.

15
CHAPTER 2

Explainability for
Linear Supervised
Models
A supervised learning model is a model that is used to train an algorithm
to map input data to output data. A supervised learning model can be of
two types: regression or classification. In a regression scenario, the output
variable is numerical, whereas with classification, the output variable is
binary or multinomial. A binary output variable has two outcomes, such as
true and false, accept and reject, yes and no, etc. In the case of multinomial
output variables, the outcome can be more than two, such as high,
medium, and low. In this chapter, we are going to use explainable libraries
to explain a regression model and a classification model, while training a
linear model.
In the classical predictive modeling scenario, a function has been
identified, and the input data is usually fit to the function to produce
the output, where the function is usually predetermined. In a modern
predictive modeling scenario, the input data and output are both shown
to a group of functions, and the machine identifies the best function that
approximates well to the output given a particular set of input. There is a
need to explain the output of machine learning and deep learning models
when performing regression and classification tasks. Linear regression and
linear classification models are simpler to explain.

© Pradeepta Mishra 2023 17


P. Mishra, Explainable AI Recipes, https://doi.org/10.1007/978-1-4842-9029-3_2
Chapter 2 Explainability for Linear Supervised Models

The goal of this chapter is to introduce various explainability libraries


for linear models such as feature importance, partial dependency plot, and
local interpretation.

 ecipe 2-1. SHAP Values for a Regression


R
Model on All Numerical Input Variables
Problem
You want to explain a regression model built on all the numeric features
of a dataset.

Solution
A regression model on all the numeric features is trained, and then
the trained model will be passed through SHAP to generate global
explanations and local explanations.

How It Works
Let’s take a look at the following script. The Shapely value can be called
the SHAP value. It is used to explain the model. It uses the impartial
distribution of predictions from a cooperative game theory to attribute
a feature to the model’s predictions. Input features from the dataset are
considered as players in the game. The models function is considered the
rules of the game. The Shapely value of a feature is computed based on the
following steps:

1. SHAP requires model retraining on all feature


subsets; hence, usually it takes time if the
explanation has to be generated for larger datasets.

18
Chapter 2 Explainability for Linear Supervised Models

2. Identify a feature set from a list of features (let’s say


there are 15 features, and we can select a subset with
5 features).

3. For any particular feature, two models using the


subset of features will be created, one with the
feature and another without the feature.

4. Then the prediction differences will be computed.

5. The differences in prediction are computed for all


possible subsets of features.

6. The weighted average value of all possible


differences is used to populate the feature
importance.

If the weight of the feature is 0.000, then we can conclude that the
feature is not important and has not joined the model. If it is not equal
to 0.000, then we can conclude that the feature has a role to play in the
prediction process.
We are going to use a dataset from the UCI machine learning
repository. The URL to access the dataset is as follows:
https://archive.ics.uci.edu/ml/datasets/Appliances+energy+
prediction
The objective is to predict the appliances’ energy use in Wh, using the
features from sensors. There are 27 features in the dataset, and here we are
trying to understand what features are important in predicting the energy
usage. See Table 2-1.

19
Chapter 2 Explainability for Linear Supervised Models

Table 2-1. Feature Description from the Energy Prediction Dataset


Feature Name Description Unit

Appliances Energy use In Wh


Lights Energy use of light fixtures in In Wh
the house
T1 Temperature in kitchen area In Celsius
RH_1 Humidity in kitchen area In %
T2 Temperature in living room area In Celsius
RH_2 Humidity in living room area In %
T3 Temperature in laundry room area
RH_3 Humidity in laundry room area In %
T4 Temperature in office room In Celsius
RH_4 Humidity in office room In %
T5 Temperature in bathroom In Celsius
RH_5 Humidity in bathroom In %
T6 Temperature outside the building In Celsius
(north side)
RH_6 Humidity outside the building (north In %
side)
T7 Temperature in ironing room In Celsius
RH_7 Humidity in ironing room In %
T8 Temperature in teenager room 2 In Celsius
RH_8 Humidity in teenager room 2 In %
T9 Temperature in parents room In Celsius
RH_9 Humidity in parents room In %
(continued)

20
Chapter 2 Explainability for Linear Supervised Models

Table 2-1. (continued)

Feature Name Description Unit

To Temperature outside (from the In Celsius


Chievres weather station)
Pressure (from Chievres In mm Hg
weather station)
aRH_out Humidity outside (from the Chievres In %
weather station)
Wind speed (from Chievres In m/s
weather station)
Visibility (from Chievres In km
weather station)
Tdewpoint (from Chievres °C
weather station)
rv1 Random variable 1 Nondimensional
rv2 Random variable 2 Nondimensional

import pandas as pd
df_lin_reg = pd.read_csv('https://archive.ics.uci.edu/ml/
machine-­learning-databases/00374/energydata_complete.csv')
del df_lin_reg['date']
df_lin_reg.info()
df_lin_reg.columns
Index(['Appliances', 'lights', 'T1', 'RH_1', 'T2', 'RH_2',
'T3', 'RH_3', 'T4', 'RH_4', 'T5', 'RH_5', 'T6', 'RH_6', 'T7',
'RH_7', 'T8', 'RH_8', 'T9', 'RH_9', 'T_out', 'Press_mm_hg',
'RH_out', 'Windspeed', 'Visibility', 'Tdewpoint', 'rv1',
'rv2'], dtype='object')

21
Chapter 2 Explainability for Linear Supervised Models

#y is the dependent variable, that we need to predict


y = df_lin_reg.pop('Appliances')
# X is the set of input features
X = df_lin_reg

import pandas as pd
import shap
import sklearn

# a simple linear model initialized


model = sklearn.linear_model.LinearRegression()

# linear regression model trained


model.fit(X, y)

print("Model coefficients:\n")
for i in range(X.shape[1]):
    print(X.columns[i], "=", model.coef_[i].round(5))

Model coefficients:

lights = 1.98971
T1 = -0.60374
RH_1 = 15.15362
T2 = -17.70602
RH_2 = -13.48062
T3 = 25.4064
RH_3 = 4.92457
T4 = -3.46525
RH_4 = -0.17891
T5 = -0.02784
RH_5 = 0.14096
T6 = 7.12616
RH_6 = 0.28795

22
Chapter 2 Explainability for Linear Supervised Models

T7 = 1.79463
RH_7 = -1.54968
T8 = 8.14656
RH_8 = -4.66968
T9 = -15.87243
RH_9 = -0.90102
T_out = -10.22819
Press_mm_hg = 0.13986
RH_out = -1.06375
Windspeed = 1.70364
Visibility = 0.15368
Tdewpoint = 5.0488
rv1 = -0.02078
rv2 = -0.02078

# compute the SHAP values for the linear model


explainer = shap.Explainer(model.predict, X)

# SHAP value calculation


shap_values = explainer(X)
Permutation explainer: 19736it [16:15, 20.08it/s]

This part of the script takes time as it is a computationally intensive


process. The explainer function calculates permutations, which means
taking a feature set and generating the prediction difference. This
difference is the presence of one feature and the absence of the same
feature. For faster calculation, we can reduce the sample size to a smaller
set, let’s say 1,000 or 2,000. In the previous script, we are using the entire
population of 19,735 records to calculate the SHAP values. This part of
the script can be improved by applying Python multiprocessing, which is
beyond the scope of this chapter.

23
Chapter 2 Explainability for Linear Supervised Models

The SHAP value for a specific feature 𝑖 is just the difference between
the expected model output and the partial dependence plot at the feature’s
value 𝑥𝑖. One of the fundamental properties of Shapley values is that they
always sum up to the difference between the game outcome when all
players are present and the game outcome when no players are present.
For machine learning models, this means that SHAP values of all the
input features will always sum up to the difference between the baseline
(expected) model output and the current model output for the prediction
being explained.
SHAP values have three objects: (a) the SHAP value for each feature,
(b) the base value, and (c) the original training data. As there are 27
features, we can expect 27 shap values.

pd.DataFrame(np.round(shap_values.values,3)).head(3)

# average prediction value is called as the base value


pd.DataFrame(np.round(shap_values.base_values,3)).head(3)

pd.DataFrame(np.round(shap_values.data,3)).head(3)

24
Chapter 2 Explainability for Linear Supervised Models

 ecipe 2-2. SHAP Partial Dependency Plot


R
for a Regression Model
Problem
You want to get a partial dependency plot from SHAP.

Solution
The solution to this problem is to use the partial dependency method
(partial_dependence_plot) from the model.

How It Works
Let’s take a look at the following example. There are two ways to get the
partial dependency plot, one with a particular data point superimposed
and the other without any reference to the data point. See Figure 2-1.

# make a standard partial dependence plot for lights on


predicted output for row number 20 from the training dataset.
sample_ind = 20
shap.partial_dependence_plot(
    "lights", model.predict, X, model_expected_value=True,
    feature_expected_value=True, ice=False,
    shap_values=shap_values[sample_ind:sample_ind+1,:]
)

25
Chapter 2 Explainability for Linear Supervised Models

Figure 2-1. Correlation between feature light and predicted output of


the model

The partial dependency plot is a way to explain the individual


predictions and generate local interpretations for the sample selected from
the dataset; in this case, the sample 20th record is selected from the training
dataset. Figure 2-1 shows the partial dependency superimposed with the
20th record in red.

shap.partial_dependence_plot(
    "lights", model.predict, X, ice=False,
    model_expected_value=True, feature_expected_value=True
)

26
Other documents randomly have
different content
Whilst an ordinary curse readily develops into a prayer when the
name of a god is brought in for the purpose of giving magic efficacy
to the curse, a prayer may contrariwise assume a magic character by
being addressed to a god—just as a sacrifice becomes endowed with
magic energy in consequence of its contact or communion with the
supernatural being to which it is offered; and the constraining force
in the prayer or sacrifice may then be directed even against the god
himself. But there can be little doubt that the extreme importance
which the magic element in the cult attained among the nations of
ancient civilisation was chiefly due to the prevalence of a powerful
priesthood or class of persons well versed in sacred texts. A
successful incantation presupposes a certain knowledge in him who
utters it. The words of the formulæ are fixed and may not suffer the
slightest modification under penalty of losing their potency. Right
intonation is equally important.117 The Brahmanic mantras “must be
pronounced according to certain mystic forms and with absolute
accuracy, or their efficacy is destroyed”; nay, if in the repetition of a
mantra the slightest mistake is made, either by omission of a syllable
or defective pronunciation, the calamity which it was intended to
bring down on an enemy will inevitably recoil on the head of the
repeater.118 The potency of the incantation largely lies in the voice,
which is the magical instrument par excellence.119 A Buddhist priest
who was asked what advantage he could expect to derive from
merely repeating a number of words with the sense of which he was
entirely unacquainted, gave the answer that the advantage of often
repeating the sounds was incalculable, infinite;120 and a
Muhammedan writer argues that prayers which are offered in any
other language than Arabic are profane and useless, because “the
sounds of this language”—whether understood or not—“illuminate
the darkness of men” and “purify the hearts of the faithful.”121 Ideas
of this sort are of course most strongly advocated by those who
derive the greatest profit from them—priests or scribes. And it is
easy to understand that with their increasing influence among a
superstitious and credulous people the magic significance which is so
readily ascribed to a religious act also has a tendency to grow in
importance.
117 Maspero, Études, i. 109; Idem, Dawn of Civilization, pp. 146,
213 (ancient Egyptians). Sayce, Hibbert Lectures on the Religion
of the Andent Babylonians, p. 319. Darmesteter, Ormazd et
Ahriman, p. 9. Sell, Faith of Islám, pp. 53, 79, 334, 341.

118 Monier-Williams, Brāhmanism and Hindūism, p. 199.

119 Yasts, iv. 5. Maspero, Études, ii. 373 sq.; Idem, Dawn of
Civilization, p. 146 (ancient Egyptians). Sell, op. cit. p. 318
(Muhammedans).

120 Indo-Chinese Gleaner, iii. 145.

121 Indo-Chinese Gleaner, iii. 146.

Among all sins there is none which gods resent more severely
than disobedience to their commandments. Mr. Macdonald says of
the Efatese, in the New Hebrides, that no people under the sun is
more obedient to what they regard as divine mandates than these
savages, who believe that an offence against a spiritual being means
calamity and death.122 The Chaldeans had a lively sense of the risks
entailed upon the sinner by disobedience to the gods.123 According
to the Bible disobedience was the first sin committed by man, and
death was introduced into the world as its punishment. “Rebellion is
as the sin of witchcraft, and stubbornness is as iniquity and
idolatry.”124 On the history of morals this demand of obedience has
exercised considerable influence. It gives emphasis to moral rules
which are looked upon as divine injunctions, and it helps to preserve
such rules after the conditions from which they sprang have ceased
to exist. The fact that they have become meaningless does not
render them less binding; on the contrary, the mystery surrounding
them often increases their sanctity. The commandments of a god
must be obeyed independently of their contents, simply because
disobedience to him is a sin. Acts totally different in character, crimes
of the worst description and practices by themselves perfectly
harmless, are grouped together as almost equally offensive to the
deity because they have been forbidden by him.125 And moral
progress is hampered by a number of precepts which, though rooted
in obsolete superstitions or antiquated ideas about right and wrong,
have an obstinate tendency to persist on account of their supposed
divine origin.126
122 Macdonald, Oceania, p. 201.

123 Maspero, Dawn of Civilization, p. 682. Delitzsch, Wo lag das


Paradies? p. 86.

124 1 Samuel, xv. 23. Schultz, Old Testament Theology, ii. 286.
For other instances see Rig-Veda, vii. 89. 5; Geiger, Civilization of
the Eastern Irānians, i. p. li.; Schmidt, Die Ethik der alten
Griechen, ii. 51 sq.

125 Cf. supra, i. 193 sqq.

126 Cf. Pollock, Essays on Jurisprudence and Ethics, p. 306 sq.

Duties to gods are in the first place based on prudential


considerations. Supernatural beings, even when on the whole of a
benevolent disposition, are no less resentful than men, and, owing
to their superhuman power, much more dangerous. On the other
hand, they may also bestow wonderful benefits upon those who
please them. The general rule that prudence readily assumes a
moral value holds particularly true of religious matters, where great
individual interests are at stake. Waterland says in his Sermon on
Self-love:—“The wisest course for any man to take is to secure an
interest in the life to come…. He may love himself, in this instance,
as highly and as tenderly as he pleases. There can be no excess of
fondness, or self-indulgence, in respect of eternal happiness. This is
loving himself in the best manner, and to the best purposes. All
virtue and piety are thus resolvable into a principle of self-love…. It
is with reference to ourselves, and for our own sakes, that we love
even God himself.”127
127 Waterland, ‘On Self-Love,’ in The English Preacher, i. 101 sq.
Cf. Paley’s definition of virtue in his Principles of Moral and
Political Philosophy, i. 7 (Complete Works, ii. 38; supra, i. 300).

At the same time it may be not only in people’s own interests, but
in the interests of their fellow men as well, for them to be on friendly
terms with supernatural beings. These beings often visit the iniquity
of fathers or forefathers upon children or descendants, or punish the
community for the sins of one of its members;128 and, on the other
hand, they reward the whole family or group for the virtues of a
single individual.129 So also, when the members of a community join
in common acts of worship, each worshipper promotes not only his
own welfare, but the welfare of his people. In early religion it is of
the utmost importance for the tribe or nation that the established
cult should be strictly observed. This is a fact which cannot be too
much emphasised when we have to explain how conduct which is
pleasing to a god has come to be regarded as a moral duty; for, if
the latest stages of religious development be excepted, the relations
between men and their gods are communal rather than individual in
character. Ahura Mazda said, “If men sacrifice unto Verethraghna,
made by Ahura, if the due sacrifice and prayer is offered unto him
just as it ought to be performed in the perfection of holiness, never
will a hostile horde enter the Aryan countries, nor any plague, nor
leprosy, nor venomous plants, nor the chariot of a foe, nor the
uplifted spear of a foe!”130 Thus the duties to gods are at the same
time social duties of the first order, owing to the intensely social
character of religious relationships.
128 Supra, i. 48 sqq.

129 Supra, i. 96 sqq.

130 Yasts, xiv. 48.

Another circumstance which has contributed to the moral


condemnation of offences against gods is that people are anxious to
punish such offences in order to prevent the divine wrath from
turning against themselves;131 for punishment, as we have seen,
easily leads to moral disapproval. But although prudential
considerations of some kind or other be the chief cause of the
obligatory character attached to men’s conduct towards their gods,
they are not the only cause. We must also remember that gods are
regarded with genuine reverence by their worshippers; and where
this is the case offences against religion naturally excite sympathetic
resentment in the latter, whilst great piety calls forth sympathetic
approval and is praised as a virtue.
131 Supra, i. 194.

I have here spoken of duties which men consider they owe to


their gods, not of duties to supernatural beings in general. This
distinction, though not always easy to follow in detail, is yet of vital
importance. People may no doubt be afraid to offend and even
anxious to please other spirits besides their gods, but religious duties
chiefly arise where there are established relationships between men
and supernatural beings; indeed, it may even be a duty to refrain
from worshipping or actually to persecute other spirits, as is the case
in monotheistic religions. Men depend for their welfare on their gods
more than on any other members of the spiritual world. They select
as their gods those supernatural beings from whom they think they
have most to fear or most to hope. Hence it is generally in the
relations to them only that those factors, prudential and reverential,
are to be found which lead to the establishment of religious duties.
CHAPTER L
GODS AS GUARDIANS OF MORALITY

AS men are concerned about the conduct of their fellow men


towards their gods, so gods are in many cases concerned about
men’s conduct towards one another—disapproving of vice and
punishing the wicked, approving of virtue and rewarding the good.
But this is by no means a universal characteristic of gods. It is a
quality attributed to certain deities only and, as it seems, in most
instances slowly acquired.
We are told by competent observers that the supernatural beings
of savage belief frequently display the utmost indifference to all
questions of worldly morality. According to Messrs. Spencer and
Gillen, the Central Australian natives, though they assume the
existence of both friendly and mischievous spirits, “have not the
vaguest idea of a personal individual other than an actual living
member of the tribe who approves or disapproves of their conduct,
so far as anything like what we call morality is concerned.”1 The
Society Islanders maintained that “the only crimes that were visited
by the displeasure of their deities were the neglect of some rite or
ceremony.”2 The religious belief of the Gonds of Central India is said
to be wholly unconnected with any idea of morality; a moral deity
demanding righteous conduct from his creatures, our informant
adds, is a religious conception far beyond the present capacity either
of the Indian savage or the ordinary Hindu.3 Of the Ew̔ e-, Yoruba-,
and Tshi-speaking peoples of the West African Slave and Gold Coasts
Major Ellis writes:—“Religion, at the stage of growth in which we find
it among these three groups of tribes, has no connection with
morals, or the relations of men to one another. It consists solely of
ceremonial worship, and the gods are only offended when some rite
or ceremony has been neglected or omitted…. Murder, theft, and all
offences against the person or against property, are matters in which
the gods have no immediate concern, and in which they take no
interest, except in the case when, bribed by a valuable offering, they
take up the quarrel in the interests of some faithful worshipper.”4 So
also among the Bambala, a Bantu tribe in the Kasai, south of the
River Congo, “there is no belief that the gods or spirits punish
wrong-doing by afflicting the criminal or his family, nor are the acts
of a man supposed to affect his condition after death.”5 The Indians
of Guiana, says Sir E. F. Im Thurn, observe an admirable code of
morality, which exists side by side with a simple animistic form of
religion, but the two have absolutely no connection with one
another.6 With reference to the Tarahumares of Mexico Dr. Lumholtz
states that the only wrong towards the gods of which an Indian may
consider himself guilty is that he does not dance enough. “For this
offence he asks pardon. Whatever bad thoughts or actions toward
man he may have on his conscience are settled between himself and
the person offended.”7 In the primitive Indian’s conception of a god,”
Mr. Parkman observes, “the idea of moral good has no part. His deity
does not dispense justice for this world or the next.”8
1 Spencer and Gillen, Northern Tribes of Central Australia, p.
491.

2 Ellis, Polynesian Researches, i. 397.


3 Forsyth, Highlands of Central India, p. 145. See also Hodgson,
Miscellaneous Essays, i. 124 (Bódo and Dhimáls); Caldwell,
Tinnevelly Shanars, p. 36; Lyall, Asiatic Studies, p. 45; Radloff,
Das Schamanenthum, p. 13 (Turkish tribes of the Altai).

4 Ellis, Yoruba-speaking Peoples of the Slave Coast, p. 293.


Idem, Tshi-speaking Peoples of the Gold Coast, p. 10. The Ew̔ e
god Mawu is represented as an exception to this rule (infra, p.
686).

5 Torday and Joyce, ‘Ethnography of the Ba-Mbala,’ in Jour.


Anthr. Inst. xxxv. 415.

6 Im Thurn, Indians of Guiana, p. 342.

7 Lumholtz, Unknown Mexico, i. 332.

8 Parkman, Jesuits in North America, p. lxxviii. See also Eastman,


Dacotah, p. xx.; Schoolcraft, Indian Tribes of the United States, ii.
195 (Dacotahs).

That many savage gods are so thoroughly selfish as to care about


nothing else than what concerns their own interests, may also be
inferred from the character attributed to them. We have seen that
the altruistic sentiment is the chief source from which moral
emotions spring, and of the gods of various uncivilised peoples we
hear not only that they are totally destitute of benevolent feelings,
but that they are of a malicious nature and mostly intent on doing
harm to mankind.9
9 See Meiners, Geschichte der Religionen, i. 405; Tylor, Primitive
Culture, ii. 329; Avebury, Origin of Civilisation, p. 232 sqq.;
Roskoff, Geschichte des Teufels, i. 20 sq.; Frazer, Golden Bough,
iii. 40 sqq.; Karsten, Origin of Worship, p. 46 sqq.

The Maoris of New Zealand regarded their deities as the causes of pain,
misery, and death, as mighty enemies from whom nobody ever thought of
getting any aid or good, but who were to be rendered harmless by means of
charms or spells or by sacrifices offered to appease their wrath.10 The
Tahitians “supposed their gods were powerful spiritual beings, in some degree
acquainted with the events of this world, and generally governing its affairs;
never exercising any thing like benevolence towards even their most devoted
followers, but requiring homage and obedience, with constant offerings;
denouncing their anger, and dispensing destruction on all who either refused
or hesitated to comply.”11 The Fijians “formed no idea of any voluntary
kindness on the part of their gods, except the planting of wild yams, and the
wrecking of strange canoes and foreign vessels on their coast”;12 and that
some of these beings were conceived as positively wicked is indicated by the
names given them—“the adulterer,” “the rioter,” “the murderer,” and so
forth.13 The people of Aneiteum, in the New Hebrides, maintained that “earth
and air and ocean were filled with natmasses, spiritual beings, but all
malignant, who ruled over everything that affected the human race…. Their
deities, like themselves, were all selfish and malignant; they breathed no spirit
of benevolence.”14

10 Taylor, Te Ika a Maui, pp. 104, 148. Colenso, Maori Races of


New Zealand, p. 62. Cf. Dieffenbach, Travels in New Zealand, ii.
118.

11 Ellis, Polynesian Researches, i. 336.

12 Williams and Calvert, Fiji, p. 195.

13 Ibid. p. 185.

14 Inglis, In the New Hebrides, pp. 30, 32.

The Santal of India believes in no god from whose benignity he may expect
favour, but in “a multitude of demons and evil spirits, whose spite he
endeavours by supplications to avert.” Even his family god “represents the
secret principle of evil, which no bolts can shut out, and which dwells in
unseen but eternally malignant presence beside every hearth.”15 The
Kamchadales do not seem to have hoped for anything good from their deities;
Kutka himself, the creator of the universe and the greatest of the gods, was
once caught in adultery and castrated.16

15 Hunter, Annals of Rural Bengal, i. 181 sq.


16 Klemm, Cultur-Geschichte der Menschheit, ii. 318 sq. Steller,
Beschreibung von Kamtschatka, p. 264.

According to the beliefs of the Koksoagmyut, or Hudson Bay Eskimo, all the
minor spirits are under the control of the great spirit whose name is Tung ak,
and this being “is nothing more or less than death, which ever seeks to
torment and harass the lives of people that their spirits may go to dwell with
him.”17 Nay, even the special guardian spirit by which each person is
supposed to be attended is malignant in character and ever ready to seize
upon the least occasion to work harm upon the individual whom it
accompanies; its good offices can be obtained by propitiation only.18 Among
the Nenenot, or Indians of Hudson Bay, “the rule seems to be that all spirits
are by nature bad, and must be propitiated to secure their favour.”19 Of
various Brazilian tribes we are likewise told that they do not believe in the
existence of any benevolent spirits. Thus the Coroado Indian acknowledges
only an evil principle, which sometimes meets him in the form of a lizard or a
crocodile or an ounce or a man with the feet of a stag, sometimes transforms
itself into a swamp, and leads him astray, vexes him, brings him into difficulty
and danger, and even kills him.20 The Mundrucus of the Cuparí have no notion
of a good supreme being, but believe in an evil spirit, regarded merely as a
kind of hobgoblin, who is at the bottom of all their little failures and gives
them troubles in fishing, hunting, and so forth.21 The Uaupés, says Mr.
Wallace, “appear to have no definite idea of a God…. They have much more
definite ideas of a bad spirit, ‘Juruparí,’ or Devil, whom they fear and
endeavour through their pagés [or medicine men] to propitiate. When it
thunders, they say the ‘Juruparí’ is angry, and their idea of natural death is
that the ‘Juruparí’ kills them.”22

17 Turner, ‘Ethnology of the Ungava District,’ in Ann. Rep. Bur.


Ethn. xi. 272.

18 Ibid. p. 194.

19 Ibid. p. 193 sq.

20 von Spix and von Martius, Travels in Brazil, ii. 243.

21 Bates, The Naturalist on the River Amazons, ii. 137.


22 Wallace, Travels on the Amazon, p. 500.

In Eastern Africa, according to Burton, “the sentiment generally elicited by a


discourse upon the subject of the existence of a Deity is a desire to see him,
in order to revenge upon him the deaths of relatives, friends, and cattle.”23
The only quality of a moral character which the Wanika are said to ascribe to
the supreme being, Mulungu, is that of vindictiveness and cruelty.24 To the
Matabele the idea of a benevolent deity is utterly foreign, but they have a
vague notion of a number of evil spirits always ready to do harm, and the
chief among these are the spirits of their ancestors.25 All the good the
Bechuanas enjoy they ascribe to rainmakers, but “all the evil that comes they
attribute to a supernatural being”;26 of their principal god, Morimo, Mr. Moffat
never once, in the course of twenty-five years spent in missionary labour,
heard that he did good or was capable of doing so.27 Among various other
African peoples, travellers assure us, supernatural beings are supposed to
exercise a potent influence for evil rather than for good, or beneficent spirits
are, at any rate, almost unknown.28 On the Gold Coast, according to Major
Ellis, the majority of spirits are malignant, and every misfortune is ascribed to
their action. “I believe,” he adds, “that originally all were conceived as
malignant, and that the indifference, or the beneficence (when propitiated by
sacrifice and flattery), which are now believed to be characteristics of some of
these beings, are later modifications of the original idea.”29

23 Burton, Lake Regions of Central Africa, ii. 348.

24 New, Life, Wanderings, and Labours in Eastern Africa, p. 103


sq.

25 Decle, Three Years in Savage Africa, p. 153.

26 Campbell, Second Journey in the Interior of South Africa, ii.


204.

27 Moffat, Missionary Labours in Southern Africa (ed. 1842), p.


262.

28 Rowley, Religion of the Africans, p. 55. Kingsley, Travels in


West Africa, p. 443. Mockler-Ferryman, British Nigeria, p. 255 sq.
29 Ellis, Tshi-speaking Peoples, pp. 12, 18, 20. Cf. Cruickshank,
Eighteen Years on the Gold Coast, ii. 134.

Of many savages it is reported that they have notions of good, as


well as of evil spirits, but that they chiefly or exclusively worship the
evil ones, since the others are supposed to be so good that they
require no offerings or homage.30 But adoration of supernatural
beings which are considered at least occasionally beneficent is also
very prevalent among uncivilised peoples.31 The gods of the pagan
Lapps were all good, although they took revenge upon those who
offended them.32 Among the Navaho Indians of New Mexico “the
gods who are supposed to love and help men the most receive the
greatest honour”; whereas the evil spirits are not worshipped
except, rumour says, by the witches.33 The belief in guardian or
tutelary spirits of tribes, clans, villages, families, or individuals, is
extremely widespread.34 These spirits may be exacting enough—
they are often greatly feared by their own worshippers, and
sometimes described as distinctly malignant by nature;35 but their
general function is nevertheless to afford assistance to the person or
persons with whom they are associated. At the same time it should
be noticed that the goodness of many savage gods only consists in
their readiness to help those who please them by offerings or
adoration; and in no case does their benevolence prove that they
take an active interest in morality at large. A friendly supernatural
being is not necessarily a guardian of men’s behaviour towards their
fellow men. In Morocco the patron saint of a town, village, or tribe is
not in the least concerned about any kind of conduct which has not
immediate reference to himself.36 It is believed that even the robber
may, by invoking a dead saint, secure his assistance in an unlawful
enterprise.
30 Wilken, Het Animisme bij de volken van den Indischen
Archipel, p. 207 sq. Perham, ‘Sea Dyak Religion,’ in Jour. Straits
Branch Roy. Asiatic Soc. no. 10, p. 220; St. John, Life in the
Forests of the Far East, i. 69 sq. (Sea Dyaks). Blumentritt, ‘Der
Ahnencultus und die religiösen Anschauungen der Malaien des
Philippinen-Archipels,’ in Mittheil. d. kais. u. kön. Geograph.
Gesellsch. in Wien, xxv. 166 sqq. Prain, ‘Angami Nagas,’ in Revue
coloniale internationale, v. 489. Forsyth, op. cit. pp. 141, 143
(Gonds). Hooker, Himalayan Journals, i. 126 (Lepchas).
Robertson, History of America, i. 383; Müller, Geschichte der
Amerikanischen Urreligionen, pp. 150, 151, 232, 260; Dorman,
Origin of Primitive Superstition, p. 30 (American Indians). Sproat,
Scenes and Studies of Savage Life, p. 212 (Ahts). Falkner,
Description of Patagonia, p. 116; Prichard, Through the Heart of
Patagonia, p. 97.

31 See supra, ii. 615 sq.

32 von Düben, Lappland, pp. 227, 285. Friis, Lappisk Mythologi,


p. 106. Jessen, Norske Finners og Lappers Hedenske Religion, p.
33.

33 Matthews, Navaho Legends, p. 40. See also ibid. p. 33.

34 Ellis, Tshi-speaking Peoples of the Gold Coast, pp. 17, 18, 77,
92. Idem, Ew̔ e-speaking Peoples of the Slave Coast, p. 75.
Wilson, Western Africa, p. 387 (Mpongwe). Tuckey, River Zaire, p.
375. Ellis, History of Madagascar, i. 395 sq. Ratzel, History of
Mankind, i. 321 (various South Sea Islanders). Turner, Samoa, p.
17 sq. Williams and Calvert, Fiji, p. 185 sq. Inglis, op. cit. p. 30
(people of Aneiteum). Christian, Caroline Islands, p. 75. Wilken,
Het Animisme, pp. 231 sqq. (Minahassers, Macassars, and Bugis
of Celebes), 243 (Javanese). Selenka, Sonnige Welten, p. 103 sq.
(Dyaks). Forbes, Insulinde, p. 203 (natives of Tenimber). von
Brenner, Besuch bei den Kannibalen Sumatras, p. 221 (Bataks).
Mason, ‘Religion, &c. among the Karens,’ in Jour. Asiatic Soc.
Bengal, xxxiv. 196. Hunter, Annals of Rural Bengal, i. 182, 186 sq.
(Santals). Hodgson, Miscellaneous Essays, i. 128 (Bódo and
Dhimáls). Bailey, ‘Veddahs of Ceylon,’ in Trans. Ethn. Soc. N.S. ii.
301; Nevill, ‘Vaeddas of Ceylon,’ in Taprobanian, i. 194. Schmidt,
Ceylon, p. 291 sq. (Tamils). Bergmann, Nomadische Streifereien
unter den Kalmüken, iii. 182 sq. Abercromby, Pre- and Proto-
historic Finns, i. 160 (Ostiaks). Buch, ‘Die Wotjaken,’ in Acta Soc.
Scient. Fennicæ, xii. 595 sq. Castrén, Nordiska resor och
forskningar, iii. 106, 107, 174 sq. (Finnish tribes). Boas, ‘Central
Eskimo,’ in Ann. Rep. Bur. Ethn. vi. 591. Turner, ibid. xi. 193 sq.
(Hudson Bay Eskimo), 272 (Hudson Bay Indians). Hoffman,
‘Menomini Indians,’ ibid. xiv. 65. McGee, ‘Siouan Indians,’ ibid. xv.
179; Parkman, op. cit. p. lxx; Dorman, op. cit. p. 227 (North
American Indians). Müller, Geschichte der Amerikanischen
Urreligionen, pp. 72 (North American Indians), 171 (Indians of
the Great Antilles). Couto de Magalhães, Trabalho preparatorio
para aproveitamento do selvagem no Brazil—O selvagem, p. 128
sqq. Tylor, op. cit. ii. 199 sqq.

35 Schmidt, Ceylon, p. 291 sq. (Tamils). Turner, in Ann. Rep. Bur.


Ethn. xi. 193 sq. (Hudson Bay Eskimo), 272 (Hudson Bay
Indians). McGee, ibid. xv. 179; Müller, op. cit. p. 72 (North
American Indians).

36 For a singular exception to this rule see supra, ii. 67 sq.

On the other hand, instances are not wanting in which savage


gods are supposed to punish the transgression of rules relating to
worldly morality. Occasionally, as we have noticed above, such gods
are represented as avengers of some special kind of wrong-doing—
murder,37 theft,38 niggardliness,39 want of hospitality,40 or lying.41 Of
certain Negro tribes we are told that, “when a man is about to
commit a crime, or do that which his conscience tells him he ought
not to do, he lays aside his fetiche, and covers up his deity, that he
may not be privy to the deed.”42 The Tonga Islanders “firmly believe
that the gods approve of virtue, and are displeased with vice; that
every man has his tutelar deity, who will protect him as long as he
conducts himself as he ought to do; but, if he does not, will leave
him to the approaches of misfortune, disease, and death…. All
rewards for virtue or punishments for vice happen to men in this
world only, and come immediately from the gods.”43 The Ainu of
Japan are heard to say, “We could not go contrary to the customs of
our ancestors without bringing down upon us the wrath of the
gods.”44 And of various savages we are told that they believe in the
existence of a supreme being who is a moral lawgiver or judge.
37 Supra, i. 378 sq.

38 Supra, ii. 59 sq.

39 Supra, i. 561 sq.

40 Supra, i. 578.

41 Supra, ii. 114 sq.

42 Tuckey, op. cit. p. 377. Cf. Monrad, Skildring af Guinea-Kysten,


p. 27, n. *

43 Mariner, Natives of the Tonga Islands, ii. 149, 107.

44 Batchelor, Ainu of Japan, p. 243 sq.

In Australia, especially in New South Wales and Victoria but also in other
parts of the continent, many of the native tribes have the notion of an “All-
father,” called Baiame, Daramulun, Mungan-ngalla, Bunjil, Nurelli, Nurundere,
or by some other name.45 He is represented as an anthropomorphic,
supernatural being and as the father of the race or the maker of everything,
who at one time dwelt on the earth but afterwards ascended to a land beyond
the sky, where he still remains. He is of a kindly disposition, and requires no
worship; in a very few cases only we meet with some faint traces of a cult
offered him.46 He is frequently believed to have instituted the initiation
ceremonies,47 and to have given the people their laws.48 Thus Nurundere is
said to have taught the Narrinyeri all the rites and ceremonies whether
connected with life or death; on inquiry why they adhere to any custom, the
reply is that Nurundere commanded it.49 At the boorah, or initiation, of the
Euahlayi tribe, Byamee is proclaimed as “Father of All, whose laws the tribes
are now obeying”; and in one of their myths he is described as the original
source of all the totems and of the law that persons of the same totem may
not intermarry.50 Bunjil taught the Kulin the arts of life, and told them to
divide themselves into two intermarrying classes so as to prevent marriages
between kindred.51 Daramulun instructed the Yuin what to do and gave them
laws which the old people have handed down from father to son to the
present time.52 And in several instances the Australian “All-father” is
represented as a guardian of morality who punishes the wicked and rewards
the good. Bunjil “very frequently sent his sons to destroy bad men and bad
women … who had killed and eaten blacks.”53 Daramulun, or Tharamulun,
who from his residence in the sky watches the actions of men, “is very angry
when they do things that they ought not to do, as when they eat forbidden
food.”54 The natives of the Herbert River, in Queensland, believe that anybody
who takes a wife from the prohibited sub-class, or who does not wear the
morning necklace for the prescribed period, or who eats forbidden food, will
sooner or later die in consequence, since his behaviour is offensive to Kohin, a
supernatural being who is supposed to have his dwelling in the Milky Way but
to roam about at night on earth as a gigantic warrior killing those whom he
meets.55 Most commonly, however, the retribution is said to come after death.
The tribes about Maryborough, in Queensland, maintain that the ghosts of
those who are good or those who have a high degree of excellence in any
particular line—fishing, hunting, fighting, dancing, and so forth—are directed
by Birral to an island in the Far North, where he resides.56 Among the Cape
River tribes, “when a Blackfellow dies whose actions during life have been
what they hold to be good, he is said to ascend to Boorala (i.e., to the
Creator, literally ‘good’), where he lives much as he did on earth, less the
usual terrestrial discomforts”; whereas to the man who has led a bad life
death is thought to be simple annihilation.57 The Kulin said that when they die
they will be subjected to a sort of trial by Binbeal, “the good being rewarded
in a better land, the bad driven away, but where they seemed to have no
idea.”58 According to another account, again, Binbeal, after he has subjected
the spirits of the deceased to an ordeal of fire to try whether they are good or
bad, liberates the good at once, whereas the bad are confined and
punished.59 The Illawarra, who lived from thirty to a hundred miles south of
Sidney, believed that when people die they are brought up to a large tree
where Mirirul, the supreme ruler, examines and judges them. The good he
takes up to the sky, the bad he sends to another place to be punished. The
women said to their children when they were naughty, “Mirirul will not allow
it.”60 Among the Wathiwathi, in New South Wales, the belief prevails that if
the spirit of a bad man escapes the traps which are set for it on its course in
the sky, it is sure to fall into the hell of fire. The good spirit, on the other
hand, is received by two old women who take care of it till it becomes
accustomed to its new abode; and after a time the great God, Tha-tha-puli,
comes with a host of spirits to see the newcomer and try his strength.61
According to a report written by Archdeacon Günther in 1839, Baiame is
supposed to like the blacks who are good; and “there is also an idea
entertained by the more thoughtful that good natives will go to Baiame when
they die.”62 Later authorities state that Baiame is believed not only to reward
the good after death, but also to punish the wicked—that is, persons who tell
lies or kill men by striking them secretly or who are unkind towards the old
and sick or, generally, who break his laws.63 A very elaborate theory of
retribution is communicated by Mr. Manning, whose notes date from 1844 or
1845. Boyma (Baiame) is said to be seated far away in the north-east on an
immense throne made of transparent crystal and standing in a great lake. He
has a son, Grogoragally, equal with him in omniscience, who acts as mediator
for the souls to the Great God. His office is to watch over the actions of
mankind and to bring to life the dead to appear before the judgment-seat of
his Father, who alone pronounces the judgment of eternal happiness in
heaven or eternal misery in a hell of everlasting fire. Women and boys dying
before the initiation, however, do not go to heaven; the men have a vague
idea that another world is reserved for them. There is also a third person, half
human, half divine, called Moodgeegally, who makes Boyma’s will known to
mankind and is the avowed enemy of all wicked people, transmitting their
misdeeds to Grogoragally.64

45 Henderson, Colonies of New South Wales, p. 147. de


Strzelecki, New South Wales, p. 339. Manning, ‘Aborigines of New
Holland,’ in Jour. and Proceed. Roy. Soc. N.S. Wales, xvi. 157 sqq.
Ridley, Kámilarói, p. 135 sqq. Cameron, ‘Some Tribes of New
South Wales,’ in Jour. Anthr. Inst. xiv. 364 sq. Langloh Parker,
Euahlayi Tribe, p. 4 sqq. Threlkeld, An Australian Language as
spoken by the Awabakal, p. 47. Mathews, Aboriginal Tribes of
New South Wales and Victoria, p. 138 sqq. Mathew, Eagle-hawk
and Crow, p. 146 sqq. Fountain and Ward, Rambles of an
Australian Naturalist, p. 296. Missions-Blatt aus der
Brüdergemeine, xvi. 101, 143; Parker, Aborigines of Australia, p.
24; Dawson, Australian Aborigines, p. 49 (tribes in Victoria).
Brough Smyth, Aborigines of Victoria, i. 423 sqq. Taplin,
‘Narrinyeri,’ in Woods, Native Tribes of South Australia, p. 55 sqq.
Howitt, Native Tribes of South-East Australia, p. 489 sqq. Spencer
and Gillen, Northern Tribes of Central Australia, p. 498 sq.
(Kaitish). Strehlow, quoted by Thomas, ‘Religious Ideas of the
Arunta,’ in Folk-Lore, xvi. 429 sq. Idem, quoted by von Leonhardi,
‘Religiöse und totemistische Vorstellungen der Aranda und Loritja
in Zentralaustralien,’ in Globus, xci. 286 sq. Curr, The Australian
Race, i. 253 (Larrakīa); ii. 465, 475 (some Cape River natives).
Lang, Cooksland, p. 459 sq.; Idem, Queensland, p. 379 sq. Roth,
Ethnol. Studies among the North-West-Central Queensland
Aborigines, pp. 16, 153. 158. Salvado, Mémoires historiques sur
l’Australie, p. 258 (natives of West Australia).

46 When the natives of Cooksland, in North-Eastern Australia,


rob a wild bees’ hive they generally leave a little of the honey for
Buddai, the supernatural ancestor of their race (Lang, Cooksland,
p. 460; Idem, Queensland, p. 380). Mrs. Langloh Parker (op. cit.
pp. 8, 9, 79, 89) was told that in the Euahlayi tribe prayers are
addressed to Byamee at funerals for the souls of the dead, and
that at some initiatory rites the oldest medicine-man present
addresses a prayer to him asking him to give the people long life
as they have kept his law; but they do not profess to pray or to
have prayed to Byamee on any other occasions (cf. Manning, loc.
cit. p. 164). The natives inhabiting the neighbourhood of Lake
Boga in Victoria have to placate Pei-a-mei by dances (Missions-
Blatt aus der Brüdergemeine, xvi. 143). Of the South-Eastern
Australian Daramulun Mr. Howitt says (op. cit. p. 507 sq.) that,
although there is no worship of him, “the dances round the figure
of clay and the invocating of his name by the medicine-men
certainly might have led up to it.”

47 Manning, loc. cit. p. 165; Ridley, op. cit. pp. 141, 155;
Langloh Parker, op. cit. p. 7 (Boyma, Baiame, Byamee). Howitt,
op. cit. p. 495 (Daramulun). M’Kinlay, quoted ibid. p. 496. Mr.
Threlkeld says (op. cit. p. 47) that Koin, an imaginary male being
who has the appearance of a black, is supposed to precede the
coming of the natives from distant parts when they assemble to
celebrate certain of their ceremonies.

48 Howitt, op. cit. p. 489 (Nurelli of the Wiimbaio). M’Kinlay,


quoted ibid. p. 496.
49 Taplin, in Woods, op. cit. p. 55.

50 Langloh Parker, op. cit. p. 7 sq.

51 Howitt, op. cit. p. 491.

52 Ibid. p. 495.

53 Brough Smyth, op. cit. i. 423.

54 Howitt, op. cit. p. 495.

55 Ibid. p. 499.

56 Howitt, op. cit. p. 498.

57 Curr, op. cit. ii. 475.

58 Parker, Aborigines of Australia, p. 24.

59 Ridley, op. cit. p. 137.

60 Ibid. p. 137.

61 Cameron, in Jour. Anthr. Inst. xiv. 364 sq.

62 Günther, quoted by Thomas, in Man, 1905, p. 51.

63 Ridley, op. cit. pp. 135, 136, 140. Langloh Parker, op. cit. p.
70.

64 Manning, loc. cit. p. 159 sqq.

It seems probable that these statements represent a mixture of Christian


ideas and genuine aboriginal beliefs. There is reason to believe that the
Australian notion of an “All-father” is not in the first instance due to
missionary influence;65 we have records of it from a comparatively early date,
it is spread over a wide area, it has been found among natives who live in a
state of great isolation, and the multitude of different names by which the
“All-father” is called in different tribes does not suggest a recent origin from a
common source. He may very well be a mythical ancestor. Mr. Howitt observes
that the master in the sky-country represents the Australian idea of a
headman—“a man who is skilful in the use of weapons of offence and
defence, all-powerful in magic, but generous and liberal to his people, who
does no injury or violence to any one, yet treats with severity any breaches of
custom or morality.”66 But he may also be a personification of supernatural
force in general, or a being who has been invented to account for all kinds of
marvellous phenomena. The word altjira, by which the Arunta call their great
god, is apparently not a proper name; according to Kempe, it is applied to five
gods, whose names he gives, as also to the sun, moon, and remarkable
things generally.67 And Mulkari, who figures in the beliefs of some Queensland
tribes, is described not only as “a benevolent, omnipresent, supernatural
being,” but as “anything incomprehensible,” as the supernatural power who
makes everything which the blacks cannot otherwise account for.68 On the
other hand, it is hardly possible to doubt that in various instances Christian
conceptions have been infused into the aboriginal belief either by the natives
themselves or by our informants.69 Biblical traits are conspicuous in some of
the legends. Bishop Salvado tells us that, according to West Australian beliefs,
the Creator, Motogon, “employa ces paroles: ‘Terre, parais dehors’: et il
souffla, et la terre fut créée. ‘Eau, parais dehors’; et il souffla, et l’eau fut
créée.”70 The believers in Nourelle give the following account of the origin of
death:—The first created man and woman were told not to go near a certain
tree in which a bat was living, as the bat was not to be disturbed. But one day
the woman, while gathering firewood, went near the forbidden tree; the bat
flew away and after that came death.71 And the same natives also believe
that Nourelle created a great serpent, to which he gave power over all
created things.72 So also the doctrine of a hell with everlasting fire has almost
certainly a foreign origin; and in some other points the genuineness of the
Australian theories of retribution is at least open to doubt, even though the
function of a judge cannot be regarded as incompatible with the notion of a
mythical headman in the sky. Messrs. Spencer and Gillen observe that it
would be a very easy matter indeed to form, as the result of a general
statement such as might be made by any individual native in reply to a
question, a perfectly wrong impression with regard to the native’s idea as to
the existence of anything like a supreme being inculcating moral rules.73 Of
the Central Australian aborigines they say:—“Any such idea as that of a future
life of happiness or the reverse, as a reward for meritorious or as a
punishment for blameworthy conduct, is quite foreign to them…. We know of
no tribe in which there is a belief of any kind in a supreme being who rewards
or punishes the individual according to his moral behaviour, using the word
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookmasss.com

You might also like