August 30, 2024
A guest post from Fabrício Ceolin, DevOps Engineer at Comet. Inspired by the growing demand…
Source: datarevenue
If you haven’t already had a read of the other parts in this series, check them out:
To recap from Part 1:
Local Interpretability aims to capture individual predictions. It focuses on the specific understanding of a data point and be exploring the feature space around it. This allows us to understand the model’s decisions, allowing for better interpretability.
Local interpretability cares little or not at all about the structure of the model, and is treated as a black-box model. Understanding the distribution of data and its feature space at a local level, rather than a global can give us a more accurate explanation.
In this article, I will be going through three different types of local model agnostic methods.
If you read Part 2 of the Model Interpretability series, you will remember Global Surrogate. Global Surrogate is a type of interpretable modeling that is trained to approximate the predictions of a black-box model.
However, Local Surrogate, also known as LIME, which stands for Local Interpretable Model-agnostic Explanations is different from Global Surrogate. Where Global aims to explain the whole model, local trains interpretable models to approximate the individual predictions.
The idea of LIME originates from a paper published in 2016: “Why Should I Trust You?” Explaining the Predictions of Any Classifier, in which the authors perturb the original data points, feed these data points into the black-box model, and then make observations on the outputs.
The method then uses those new data points and weights them, using it as a function of their proximity to the original point. Each of the original data points can be explained with the new trained explained model.
The learned model can be used as a good approximation of the machine learning model predictions locally, calling this type of accuracy local fidelity.
This can be mathematically expressed as:
Let’s look at the bike sharing dataset, which can be downloaded from UCI Machine Learning Repository. The dataset contains daily counts of rented bicycles from Capital-Bikeshare, a bicycle rental company in Washington D.C. It also includes data on weather and seasonal information, where the overall goal is to predict how many bikes will be rented depending on the weather and day.
In this example, a random forest has been trained with 100 trees on the classification task, aiming to answer this question: Is there a particular day where the number of rental bikes is above the trend-free average, based on weather and calendar information?
The results show that the warmer temperature and good weather features have a positive effect on the prediction. The x-axis is defined as ‘effect,’ this is the weight times by the actuarial feature value, calculating the feature effect.
Advantages:
Disadvantages:
Real-time model analysis allows your team to track, monitor, and adjust models already in production. Learn more lessons from the field with Comet experts.
Our second local method is Individual Conditional Expectation, which is very similar to the Partial Dependence Plot (PDP). However, instead of plotting an average which PDP does, ICE displays one line per instance that shows how the instance’s prediction changes as a feature changes.
PDP is a global method, as it focuses on the overall average, not on the specific instances. ICE is more intuitive than PDP due to its locality, exploring how each line represents the prediction for one instance if a feature varies. The overall aim of ICE is to explain what happens to a prediction in the model if the feature changes.
Another way to remember the difference between PDP and ICE is that PDP is the average of the lines of an ICE plot.
ICE plot shows the dependence between the target function and a particular feature of interest, where it visualizes the dependence of the prediction on a feature for each sample; one line per sample. Only one feature of interest is supported for ICE plots.
An ICE plot has the ability to unravel the curve that PDP fails to do so. Each ICE curve shows the predictions of the feature value for an instance when the features have been varied. When presented in a single plot, we are able to see the relationships between the subsets of the instances and the differences in how the individual instances behave.
To keep this blog consistent, using the same dataset from the LIME example: The bike sharing dataset, from UCI Machine Learning Repository. Using the underlying prediction model a random forest, which has been trained with 100 trees, aims to predict how many bikes will be rented depending on the weather and the day.
The ICE plots shown below are the predicted bicycle rentals based on weather conditions. Looking at each feature, all the curves follow the same course, lacking to present any obvious interactions.
Therefore, from this interpretation, we can explore using PDP to see if we can get a better explanation between the features and the predicted number of bicycles.
Advantages:
Disadvantages:
Shapley Values aims to explain with a machine learning model produces the outputs it does. Shapley value was named in honor of Lloyd Shapley, a concept that was borrowed from the cooperative game theory literature.
Shapley Values were originally used to fairly attribute a player’s contribution to the end result of a game. For example, if there are a set of players which each collaborate to create some values, we can then measure the total outcome of the game. Shapley values represent the marginal contribution of each player to the end result. In a simpler example, it is the split of a bill between friends; it tells us how to distribute the “payout” fairly among the features.
The Shapley value of a feature is the contribution its value has to the payout, which is then weighted and summed over all the possible feature value combinations. This can be expressed as:
The Shapley Value method satisfies the following properties: Efficiency, symmetry, dummy, and additivity. It is the only model which has these properties which work together to define a fair payout.
Advantages:
Disadvantages:
SHAP is based on the game theory Shapley Values to explain the output of any machine learning model. It differs from Shapley Values due to its kernel-based estimation approach. The aim of SHAP is to explain the prediction of an instance, which is done by computing the contribution of each feature to the prediction.
Shapley values distribute the predictions fairly among the features. Each player of the game can be considered as an individual feature or a group of features. SHAP combines both LIME and Shapley Values in one, and can be expressed as:
Using the cervical cancer dataset which explores and indicates the risk factors of whether a woman will get cervical cancer. The below SHAP figures explain the features and their correlation to two women from the cervical cancer dataset:
The baseline, which is the average predicted probability is 0.066. The first woman, which is the first SHAP plot has a low predicted risk of 0.06. The second woman, which is the second SHAP plot has a high predicted risk of 0.71.
For the first woman, factors such as STD have balanced out the effects of age. For the second woman, factors such as age and the year of smoking have increased her predicted cancer risk.
If you have kept up to date with this series of Model Interpretability, we have covered:
If you would like to know more about Model Interpretability, I would highly recommend reading Interpretable Machine Learning by Christoph Molnar. He has given me the guidance and better understanding to write this three-part series about Model Interpretability.