Explainable AI Recipes: Implement Solutions to Model Explainability andInterpretability 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 orders-ny@springer-sbm.com, 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 booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
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 lovelywife, Prajna; and my daughters, Priyanshi (Aarya) andAdyanshi (Aadya).
This work would not have been possiblewithout 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.
Next page