# LIME (Local Interpretable Model-Agnostic Explanations)

Code Implementation here

[Regression](https://drive.google.com/file/d/1wLg_vicpzFD_4dOdwbV7G8RY1M6I4iMD/view?usp=sharing)\
[Classification](https://drive.google.com/file/d/1tNOxXfmAiap6lW0CXyvZP1cIrPgtvMLM/view?usp=sharing)

### Introduction

In general, black-box models are highly complex and to be able to generate an overall global explanation for the model’s prediction is actually a very difficult job. The LIME algorithm was first brought into light for its ability to help understand image classification in 2016. With this algorithm, we could identify the parts of the input that triggered or affected our output the most.

LIME is short for Local Interpretable Model-Agnostic Explanations. It is a technique that can be applied to understand the predictions of a black-box model, by understanding the individual predictions with the help of a simpler, and directly interpretable model.&#x20;

LIME can be used in the case of tabular, text and even image data. It generates a local explanation for a particular row, input word vector or a superpixel in all three cases respectively. From the name, we can deduce that it is a model agnostic method - which means that this technique can be applied to any model. Also from the name, we can see that this generates Local Explanations. This means that this technique helps generate explanations for a single instance/row in our data set.

This technique is highly impactful when we want to focus on understanding individual predictions rather than a group of predictions made by a model. An example of such a use case would be the healthcare industry, wherein each individual has a unique biological body mechanism. It would be wrong to generalize a model and assume the model would predict correctly for every human. Since every individual is unique, we would want to understand the single predictions and ensure that our model has not made a mistake.&#x20;

In the image below (taken from the original [paper](https://arxiv.org/abs/1602.04938)), we have a model that predicts if a person has the flu or not. For this particular individual, LIME indicates that sneeze and headache had contributed to the “flu” prediction, while “no fatigue” is evidence against it. With these, a doctor can make an informed decision about whether to trust the model’s prediction.

![LIME highlights the symptoms that led to the prediction (pic presented in paper)](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-ME4C-JaK9LIvK7Es55S%2F-ME50Di4XcFMHQlvIxnl%2Fimage.png?alt=media\&token=dcfce5c0-e120-40d5-a6e0-59269cdabc1e)

LIME uses the local fidelity criterion. This means that any explanation generated using LIME must correspond to the vicinity of the instance being predicted. To create this vicinity, LIME perturbs the instance being predicted.&#x20;

&#x20;

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-ME4C-JaK9LIvK7Es55S%2F-ME4Tc_JHzUHMGh5p8gK%2Fimage.png?alt=media\&token=28dc5680-b462-4288-adff-1d7b9cd4ac0f)

The above image is a toy example presented in the original [paper](https://arxiv.org/abs/1602.04938). In the example, LIME is used to generate an explanation for a single instance marked as a "bold cross". The other red cross and blue circles are sample instances in our data set that are in the vicinity of the instance corresponding to the prediction explanation (the bold cross).&#x20;

In the image, the proximity is represented by the size of the cross and the circles. The larger the cross or the circle, the closer it is to the instance under investigation. The dashed line represents a linear explanation that is locally true.&#x20;

We have to understand that features that may seem important locally need not be important globally. By global importance, we mean that a feature is important for all the instance predictions in the data set. But in local importance, the features may or may not be the same as global because only a single instance prediction is taken into consideration.

### Visualizations

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEkRdkCfblzeMoEMhgO%2F-MEkT90pru2ZoFDz1Z1T%2Fimage.png?alt=media\&token=28e9b871-8fef-4da7-bf29-6452e268b8c8)

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEkRdkCfblzeMoEMhgO%2F-MEkTCeDpnCRHw7wkwhr%2Fimage.png?alt=media\&token=89d9e662-6147-4e1c-aa01-a86f5bcc53f5)

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEkRdkCfblzeMoEMhgO%2F-MEkTFxwqoQTLnx4lhFY%2Fimage.png?alt=media\&token=f4f9d046-d849-4032-882e-3b7dbf79644c)

### **Pros**&#x20;

* The technique can be applied to tabular, text and image data
* The technique can be easily used as it is implemented in a Python library ([lime.py](https://github.com/marcotcr/lime))

### **Cons**

* The vicinity of a prediction can vary and find the right  kernel width that generates an accurate local explanation is a difficult job
* The technique is inconsistent and there is often instability in the explanations

**References**

1. ["Why Should I Trust You?": Explaining the Predictions of Any Classifier](https://arxiv.org/abs/1602.04938) - Marco Tulio Ribeiro, Sameer Singh, Carlos Guestrin
