> For the complete documentation index, see [llms.txt](https://maheshwarappa-a.gitbook.io/explainable-ai-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maheshwarappa-a.gitbook.io/explainable-ai-1/implementation-of-these-techniques-on-different-models/untitled.md).

# Random Forest - LIME

[Code Implementation Here](https://colab.research.google.com/drive/1MeTcEe5bV2eFPoxQZ1jtfX0MXhc7a4kb?usp=sharing)

### **What is a Random Forest?**

* Random Forest is an ensemble learning method used for classification and regression&#x20;
* Random Forests are a modification of bagging technique that builds a large collection of non-correlated trees and then averages them
* This technique is sometimes even called "feature bagging".

### **Making the Model**

**Dataset:** Automotive marketing  ; **Target:** Customer lifetime value

The data is passed through pre-processing and then trained using Scikit learn Library with RandomForestRegressor function.

**R2 score:** 0.70

### **Implementation of Interpretability**

For this model we will be using LIME for interpretation. In particular, we use the LimeTabularExplainer which is part of the open source lime package.

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEfTt8rKrk18miTRf2E%2F-MEfVeTNOpZiS0Ne9grL%2Fimage.png?alt=media\&token=6705ee06-dc7f-4912-a53a-22462a136dcc)

We feed some data as shown above and then request the explainer to generate an explanation for a particular row. In the code, we have generated an explanation for 4th row and kept a cap on the number of features as 6.

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEfTt8rKrk18miTRf2E%2F-MEfWn1lF6dgoZ-6Etlh%2Fimage.png?alt=media\&token=043ed40a-ab85-460b-8629-ff2d29eff7d6)

### Visualizations

**Row Prediction**

![Predicted Customer Lifetime Value](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEfTt8rKrk18miTRf2E%2F-MEfX9q90zRfUMwp4_8N%2Fimage.png?alt=media\&token=13644291-d05b-47dc-ab38-1c655ba4bc2f)

**Positive/Negative Effects**

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEfTt8rKrk18miTRf2E%2F-MEfXNOUJg-RbQLjh90k%2Fimage.png?alt=media\&token=68822745-a69c-4900-8958-414e30c6449a)

The above plot gives us an idea of the features that impact the prediction positively and negatively. By positive impact, we say that the feature brought the prediction closer to the predicted value. Negative effect implies the feature took the prediction away from the predicted value. The length of the bars also show the impact. Longer the bar, higher the impact.&#x20;

**Individual Feature Values**

![](https://1181649628-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5Vxy9PzQFOZjhyK8YP%2F-MEfTt8rKrk18miTRf2E%2F-MEfY2sym2Tfbi5EUBj3%2Fimage.png?alt=media\&token=f58d3d6a-d512-4b1c-a36b-8670d332a3da)

The above plot shows the feature values for that particular row.
