lime

Local Interpretable Model-Agnostic Explanations (R port of original Python package)

https://github.com/thomasp85/lime

Science Score: 20.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    1 of 16 committers (6.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.4%) to scientific vocabulary

Keywords

caret model-checking model-evaluation modeling r

Keywords from Contributors

tidy-data setup tidyverse parsing fwf csv documentation-tool package-creation http-mock visualisation
Last synced: 6 months ago · JSON representation

Repository

Local Interpretable Model-Agnostic Explanations (R port of original Python package)

Basic Info
Statistics
  • Stars: 488
  • Watchers: 30
  • Forks: 109
  • Open Issues: 51
  • Releases: 0
Topics
caret model-checking model-evaluation modeling r
Created almost 9 years ago · Last pushed over 3 years ago
Metadata Files
Readme License Code of conduct

README.Rmd

---
output: github_document
---



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
```

# lime 


[![R-CMD-check](https://github.com/thomasp85/lime/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/thomasp85/lime/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/thomasp85/lime/branch/main/graph/badge.svg)](https://app.codecov.io/gh/thomasp85/lime?branch=main)
[![CRAN_Release_Badge](http://www.r-pkg.org/badges/version-ago/lime)](https://CRAN.R-project.org/package=lime)
[![CRAN_Download_Badge](http://cranlogs.r-pkg.org/badges/lime)](https://CRAN.R-project.org/package=lime)


> 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 `lime` is 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 `lime` 
read the [paper](https://arxiv.org/abs/1602.04938) and visit the repository of
the [original implementation](https://github.com/marcotcr/lime).

The `lime` package 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.

## An example
Out of the box `lime` supports 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 `predict_model` and `model_type` method for the given model.

The following shows how a random forest model is trained on the iris data set 
and how `lime` is then used to explain a set of new observations:

```{r, message=FALSE, fig.asp=1}
library(caret)
library(lime)

# Split up the data set
iris_test <- iris[1:5, 1:4]
iris_train <- iris[-(1:5), 1:4]
iris_lab <- iris[[5]][-(1:5)]

# Create Random Forest model on iris data
model <- train(iris_train, iris_lab, method = 'rf')

# Create an explainer object
explainer <- lime(iris_train, model)

# Explain new observation
explanation <- explain(iris_test, explainer, n_labels = 1, n_features = 2)

# The output is provided in a consistent tabular format and includes the
# output from the model.
explanation

# And can be visualised directly
plot_features(explanation)
```

`lime` also supports explaining image and text models. For image explanations 
the relevant areas in an image can be highlighted:

```{r, fig.asp=0.5}
explanation <- .load_image_example()

plot_image_explanation(explanation)
```

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 a `shiny` application for interactively exploring text models:

![interactive text explainer](man/figures/shine_text_explanations.gif)

## Installation
`lime` is available on CRAN and can be installed using the standard approach:

```{r, eval=FALSE}
install.packages('lime')
```

To get the development version, install from GitHub instead:

```{r, eval=FALSE}
# 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](https://lime.data-imaginist.com/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.

Owner

  • Name: Thomas Lin Pedersen
  • Login: thomasp85
  • Kind: user
  • Location: Copenhagen
  • Company: @posit-pbc, part of @tidyverse team

Maker of tools focusing on data science and data visualisation

GitHub Events

Total
  • Watch event: 6
Last Year
  • Watch event: 6

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 181
  • Total Committers: 16
  • Avg Commits per committer: 11.313
  • Development Distribution Score (DDS): 0.127
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Lin Pedersen t****5@g****m 158
Michaël Benesty p****e 7
nielsenmarkus11 n****1 2
Jeroen Ooms j****s@g****m 2
millerjoey a****0@g****m 1
Sam Lee s****l@a****u 1
Philipp Kopper 4****r 1
Maëlle Salmon m****n@y****e 1
Matt Dancho m****4 1
Martin Jullum j****m@n****o 1
Mara Averick m****k@g****m 1
Ledger West l****t@g****m 1
Jon Calder j****r@g****m 1
Emil Hvitfeldt e****t@g****m 1
Christoph Molnar c****r@g****m 1
Chris Muir C****r 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 86
  • Total pull requests: 15
  • Average time to close issues: 3 months
  • Average time to close pull requests: 5 months
  • Total issue authors: 70
  • Total pull request authors: 12
  • Average comments per issue: 2.44
  • Average comments per pull request: 0.93
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Make42 (5)
  • pkopper (3)
  • timcdlucas (3)
  • alanault (3)
  • mstaniak (3)
  • DiliSR (2)
  • nielsenmarkus11 (2)
  • thomasp85 (2)
  • ms1948 (2)
  • JLB9791 (1)
  • mirka-henninger (1)
  • kennysong (1)
  • hrampadarath (1)
  • ruizcrp (1)
  • sfd99 (1)
Pull Request Authors
  • nielsenmarkus11 (2)
  • pkopper (2)
  • jeroen (2)
  • NienkeVanTKlooster (1)
  • EmilHvitfeldt (1)
  • Ncalverley (1)
  • jmatias (1)
  • ChrisMuir (1)
  • samleegithub (1)
  • ledgerW (1)
  • tomazweiss (1)
  • talgalili (1)
Top Labels
Issue Labels
bug (1)
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • cran 49,240 last-month
  • Total docker downloads: 36,199
  • Total dependent packages: 3
    (may contain duplicates)
  • Total dependent repositories: 4
    (may contain duplicates)
  • Total versions: 17
  • Total maintainers: 1
proxy.golang.org: github.com/thomasp85/lime
  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago
cran.r-project.org: lime

Local Interpretable Model-Agnostic Explanations

  • Versions: 8
  • Dependent Packages: 3
  • Dependent Repositories: 3
  • Downloads: 49,240 Last month
  • Docker Downloads: 36,199
Rankings
Forks count: 0.6%
Docker downloads count: 0.6%
Stargazers count: 0.8%
Average: 6.3%
Downloads: 8.5%
Dependent packages count: 10.9%
Dependent repos count: 16.5%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: r-lime
  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Forks count: 17.2%
Stargazers count: 17.9%
Dependent repos count: 24.3%
Average: 27.8%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • Matrix * imports
  • Rcpp * imports
  • assertthat * imports
  • ggplot2 * imports
  • glmnet * imports
  • gower * imports
  • grDevices * imports
  • methods * imports
  • stats * imports
  • stringi * imports
  • tools * imports
  • MASS * suggests
  • covr * suggests
  • h2o * suggests
  • htmlwidgets * suggests
  • keras * suggests
  • knitr * suggests
  • magick * suggests
  • mlr * suggests
  • ranger * suggests
  • rmarkdown * suggests
  • sessioninfo * suggests
  • shiny * suggests
  • shinythemes * suggests
  • testthat * suggests
  • text2vec * suggests
  • xgboost * suggests