{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial to invoke SHAP explainers via aix360\n", "\n", "There are two ways to use [SHAP](https://github.com/slundberg/shap) explainers after installing aix360:\n", "- [Approach 1 (aix360 style)](#approach1): SHAP explainers can be invoked in a manner similar to other explainer algorithms in aix360 via the implemented wrapper classes.\n", "- [Approach 2 (original style)](#approach2): Since SHAP comes pre-installed in aix360, the explainers can simply be invoked directly.\n", "\n", "This notebook showcases both these approaches to invoke SHAP. The notebook is based on the following example from the original SHAP tutorial: \n", "https://slundberg.github.io/shap/notebooks/Iris%20classification%20with%20scikit-learn.html\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Approach 1 (aix360 style)\n", "\n", "- Note the import statement related to KernelExplainer" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function\n", "import sklearn\n", "from sklearn.model_selection import train_test_split\n", "import sklearn.datasets\n", "import sklearn.ensemble\n", "import numpy as np\n", "import time\n", "np.random.seed(1)\n", "\n", "# Importing shap KernelExplainer (aix360 style)\n", "from aix360.algorithms.shap import KernelExplainer\n", "\n", "# the following import is required for access to shap plotting functions and datasets\n", "import shap" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Supress jupyter warnings if required for cleaner output\n", "import warnings\n", "warnings.simplefilter('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### K-nearest neighbors" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "