Categorical Model Explanation using the Python Client
This is a sample code to use our EXPAI Client for a Categorical Model step by step
Download the files
You can access the complete code here.
Download the dataset here.
Download the model here. Remember we have a guide for Creating a Pipeline model.
We highly recommend using Jupyter Lab to work with EXPAI Client
Imports
Remember to install our Python client by using pip install -U expai
Login to your account
Create a Project
The first step to interact with your account is creating a Project.
Interact with your Project
We will first obtain a Project object that will allow us to interact with its content and generate explanations.
Create a model
In this step, we use the model provided here. All parameters and their descriptions can be found in the Python client docs.
Create a sample
In this step, we use the dataset provided here. All parameters and their descriptions can be found in the Python client docs.
Explain the model
Once we have included a model and a sample to our project, we can execute all available explanations. First of all, we must generate a Model Explainer object for our model.
Defining a subgroup for explanations
This step can be skipped if you are not interested on defining a subgroup.
Sometimes, we don't want to study how our model works for the whole dataset but for a specific meaningful subgroup. In this case, we could be interested on studying how the model behaves for people under 40 years old.
Generate Explanations and Plots
Once we obtained the Model Explainer, we can use it to generate all possible explanations for our model. When an explanation is generated an Explanation object will be returned.
Model Explanation
This explanation represents the importance of each variable in the predictions. It is computed as the increase in the prediction error when this variable is removed.
Variable Explanation
In this case, we will explore the effect of a given variable in our predictions. In other words, we will represent the average prediction of the model in terms of the variable.
Explain a unique entry
In this explanation, we will be able to understand which was the impact of each variable for the prediction of a unique entry in our dataset.
WHAT IF
This explanation will allow you to see what would happen if we change only one variable in the entry while all remaining variables are kept the same. It will plot all possible values for a variable and the prediction for them.
WHAT IF BATTLE
This explanation is similar to the previous one but now we can replace all the values we want at the same time and study how predictions will change.
Last updated