Explainable AI : The Next Level

Explainable AI (XAI) refers to methods and techniques in the ML/AI such that the results of the solution can be understood by humans. It contrasts with the concept of the “black box” in machine learning where even their designers cannot explain why the AI arrived at a specific decision.

Vishal Solanki
Analytics Vidhya
8 min readJul 31, 2020

--

Why do we need XAI ?

I will keep this section short but informative because as a Data Scientist we know very well why do we need to explain our models.

· Trust Buildup

· Justification

· Speed up the widespread adoption

Lets understand the need of XAI form below scenario.

I think from above two images, it is all clear why do we need XAI layer in our pipeline while making predictions.

Service/Libraries Available For XAI

There are many services available for XAI but I would say only three are matured enough to use.

Below are the services which I have explored related to XAI.

Independent Libraries

Today, I will be covering ELI5 and LIME to explain the models.

ELI5: is a python package which helps to understand the models prediction in an intuitive way, however it doesn’t support true model-agnostic interpretations and support for models are mostly limited to tree-based and other parametric\linear models.

For Independent libraries I m using Telecom Customer Churn dataset.

Dataset Details: Shape: (7032,20), Target Variable: Churn( 1:Yes, 0:No)

Dataset Columns=[‘gender’, ‘SeniorCitizen’, ‘Partner’, ‘Dependents’, ‘tenure’, ‘PhoneService’, ‘MultipleLines’, ‘InternetService’, ‘OnlineSecurity’, ‘OnlineBackup’, ‘DeviceProtection’, ‘TechSupport’, ‘StreamingTV’, ‘StreamingMovies’, ‘Contract’, ‘PaperlessBilling’, ‘PaymentMethod’, ‘MonthlyCharges’, ‘TotalCharges’, ‘Churn’]

I am using XG boost classifier to classify the data points in Churn(Yes/No), complete code available at my GitHub repo.

After applying XG boost and ELI5, I’m getting below results:

Let’s understand each figure:

Fig (1): Shows the independent features importance on the model, all these features are arranged in descending order.

Fig (2): Shows the feature contribution on single data point for predicting the class. As we can see Actual label is 1 and model has also predicted 1, it means customer is going to Churn and if we see feature contribution then we can understand because of high monthly charges (102.250), User has only month contract (0: “Month-to-month”, 1: “One year” , 2: “Two year”) and high total charges are the three factors which are impacting the most to classify the datapoint as 1 (Churn-yes).

LIME: Local interpretable model-agnostic explanations, as it is clear from the name itself we can use this library only for local interpretation not for global like we did in ELI5 section (Fig 1).

Again I m using the same data set and even same model XG boost but this time I m going to explain data point for class 0 (Churn-No).

Actual 0 (Churn- No) , Predicted 0 (Churn -No)

As we can see probability for class 0 is 0.93 and actual label is also 0 so we can say yes our model is working fine now let’s check explanation as well. We can see user has only month contract (0: “Month-to-month”, 1: “One year” , 2: “Two year”) like is previous case but monthly charges are too low also user is not a senior Citizen so these two factors are impacting the most during prediction to predict the data point as 0 (Churn-No) however contract is still impacting in opposite way to make it 1(Churn-Yes).

Actual 1 (Churn- Yes) , Predicted 1 (Churn -Yes)

Now let’s understand the same data point which we explained using ELI5, we can see clearly results are almost similar to ELI5.

Because of high monthly charges (102.250), monthly contract (0: “Month-to-month”, 1: “One year” , 2: “Two year”) model is classifying the datapoint as 1 (Churn-Yes).

Important Links: Independent Libraries

IBM AI Explainability 360

AI 360 is open source toolkit provided by IBM, in this we have variety of algorithms. I have explored all of these algorithms but I like the most BRCG and Protodash so we will be discussing these two algorithms today. You can have a look at other algorithms as well, IBM has very intuitive tutorial on their GitHub.

How To Use IBM AI Explainability 360 Toolkit

BRCG

Boolean Rule Column Generation explainer, which implements a directly interpretable supervised learning method for binary classification that learns a Boolean rule in disjunctive normal form (DNF) or conjunctive normal form (CNF) using column generation (CG).

This directly learns accurate and interpretable “or” -of- “and” logical classification rules and this works with only tabular data.

In this I am using Breast Cancer dataset, where we need to predict a person having cancer or not.

Dataset Columns=Index([‘mean radius’, ‘mean texture’, ‘mean perimeter’, ‘mean area’, ‘mean smoothness’, ‘mean compactness’, ‘mean concavity’, ‘mean concave points’, ‘mean symmetry’, ‘mean fractal dimension’, ‘radius error’, ‘texture error’, ‘perimeter error’, ‘area error’, ‘smoothness error’, ‘compactness error’, ‘concavity error’, ‘concave points error’, ‘symmetry error’, ‘fractal dimension error’, ‘worst radius’, ‘worst texture’, ‘worst perimeter’, ‘worst area’, ‘worst smoothness’, ‘worst compactness’, ‘worst concavity’, ‘worst concave points’, ‘worst symmetry’, ‘worst fractal dimension’], dtype=’object’)

Before passing model directly to the BRCG model we need to transform the data accordingly for this we will be using “FeatureBinarizer".

FeatureBinarizer: The standard FeatureBinarizer creates thresholds by binning the data into a user-specified number of quantiles. The default threshold value is 9.

After preparing data we will pass this to BRCG model and find the rules for our classification. Code for both BRCG and ProtoDash is available at my GitHub repo.

We got four rules to explain our classification, if our input data satisfy any of the four rules then model will predict as 1 (Having Cancer).

ProtoDash

ProtoDash provides prototypical examples from dataset. Suppose if you have any customer and he applies for loan and you use ML model to approve/deny the loan. Now if loan gets rejected then you may want to see the previous cases similar to the current one in which loan was rejected so that you can verify. Below image showing the two most similar cases having target variable 0.

Now lets assume you have list of customers having all details and their loan status as well, you want two exactly unique customers one is from approved class and another is from denied class then you can use Protodash to have these details.

Below image showing the two most unique customers.

Explainable AI — Google

There are three services provide by the google for Explainable AI.

· AI Explanations

· What-If-Tool

· Continuous evaluation

Explainable AI tools (other than WIT) require customers to build and implement their models within the Google Cloud. Though, they are provided at no extra charge to users of AutoML Tables or AI Platform.

WIT is an open-source tool and is compatible with TensorBoard, Jupyter and Colaboratory notebooks.

AI Explanations

AI Explanations helps understand model’s outputs for classification and regression tasks. It tells how much each feature in the data contributed to the predicted result. This information can be used to verify that the model is behaving as expected, recognize bias in models, and get ideas for ways to improve model and training data.

What-If-Tool

For this amazing tool, I have already written one article.

You can have a look, I would say this tool has all functionalities which i have explained till now in this tutorial.

Continuous evaluation (Beta)

Continuous evaluation regularly samples prediction input and output from trained machine learning models that have been deployed to AI Platform Prediction. AI Platform Data Labeling Service then assigns human reviewers to provide ground truth labels for prediction input; alternatively, user can provide their own ground truth labels. Data Labeling Service compares your models’ predictions with the ground truth labels to provide continual feedback on how your model is performing over time.

To implement AI Explanations and Continuous evaluation we need GCP access which I don’t so I am skiping implementation of these two however links are provided below if you wish you can explore.

Important Links: Explainable AI by Google

The code used in this article is available on GitHub.

--

--