Local Interpretable Model-Agnostic Explanations (R port of original Python package)
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
There once was a package called lime,
Whose models were simply sublime,
It gave explanations for their variations,
one observation at a time.
lime-rick by Mara Averick
This is an R port of the Python lime package (https://github.com/marcotcr/lime) developed by the authors of the lime (Local Interpretable Model-agnostic Explanations) approach for black-box model explanations. All credits for the invention of the approach goes to the original developers.
The purpose of
limeis to explain the predictions of black box classifiers. What this means is that for any given prediction and any given classifier it is able to determine a small set of features in the original data that has driven the outcome of the prediction. To learn more about the methodology of
limeread the paper and visit the repository of the original implementation.
limepackage for R does not aim to be a line-by-line port of its Python counterpart. Instead it takes the ideas laid out in the original code and implements them in an API that is idiomatic to R.
Out of the box
limesupports a long range of models, e.g. those created with caret, parsnip, and mlr. Support for unsupported models are easy to achieve by adding a
model_typemethod for the given model.
The following shows how a random forest model is trained on the iris data set and how
limeis then used to explain a set of new observations:
Split up the data set
iris_test # A tibble: 10 x 13 #> model_type case label label_prob model_r2 model_intercept #> #> 1 classific… 1 seto… 1 0.680 0.120 #> 2 classific… 1 seto… 1 0.680 0.120 #> 3 classific… 2 seto… 1 0.675 0.125 #> 4 classific… 2 seto… 1 0.675 0.125 #> 5 classific… 3 seto… 1 0.682 0.122 #> 6 classific… 3 seto… 1 0.682 0.122 #> 7 classific… 4 seto… 1 0.667 0.128 #> 8 classific… 4 seto… 1 0.667 0.128 #> 9 classific… 5 seto… 1 0.678 0.121 #> 10 classific… 5 seto… 1 0.678 0.121 #> # … with 7 more variables: model_prediction , feature , #> # feature_value , feature_weight , feature_desc , #> # data , prediction
And can be visualised directly
limealso supports explaining image and text models. For image explanations the relevant areas in an image can be highlighted:
Here we see that the second most probably class is hardly true, but is due to the model picking up waxy areas of the produce and interpreting them as wax-light surface.
For text the explanation can be shown by highlighting the important words. It even includes ashinyapplication for interactively exploring text models:
Installationlimeis available on CRAN and can be installed using the standard approach:install.packages('lime')
To get the development version, install from GitHub instead:# install.packages('devtools') devtools::install_github('thomasp85/lime')
Code of Conduct
Please note that the ‘lime’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.