lime README

The project's README from github.com/marcotcr/lime. As one markdown file: README.md.

lime

Build Status Binder

This project is about explaining what machine learning classifiers (or models) are doing. At the moment, we support explaining individual predictions for text classifiers or classifiers that act on tables (numpy arrays of numerical or categorical data) or images, with a package called lime (short for local interpretable model-agnostic explanations). Lime is based on the work presented in this paper (bibtex here for citation). Here is a link to the promo video:

KDD promo video

Our plan is to add more packages that help users understand and interact meaningfully with machine learning.

Lime is able to explain any black box classifier, with two or more classes. All we require is that the classifier implements a function that takes in raw text or a numpy array and outputs a probability for each class. Support for scikit-learn classifiers is built-in.

Installation

The lime package is on PyPI. Simply run:

pip install lime

Or clone the repository and run:

pip install .

We dropped python2 support in 0.2.0, 0.1.1.37 was the last version before that.

Screenshots

Below are some screenshots of lime explanations. These are generated in html, and can be easily produced and embedded in ipython notebooks. We also support visualizations using matplotlib, although they don't look as nice as these ones.

Two class case, text

Negative (blue) words indicate atheism, while positive (orange) words indicate christian. The way to interpret the weights by applying them to the prediction probabilities. For example, if we remove the words Host and NNTP from the document, we expect the classifier to predict atheism with probability 0.58 - 0.14 - 0.11 = 0.31.

twoclass

Multiclass case

multiclass

Tabular data

tabular

Images (explaining prediction of 'Cat' in pros and cons)

Tutorials and API

For example usage for text classifiers, take a look at the following two tutorials (generated from ipython notebooks):

For classifiers that use numerical or categorical data, take a look at the following tutorial (this is newer, so please let me know if you find something wrong):

For image classifiers:

For regression:

Submodular Pick:

The raw (non-html) notebooks for these tutorials are available here.

The API reference is available here.

What are explanations?

Intuitively, an explanation is a local linear approximation of the model's behaviour. While the model may be very complex globally, it is easier to approximate it around the vicinity of a particular instance. While treating the model as a black box, we perturb the instance we want to explain and learn a sparse linear model around it, as an explanation. The figure below illustrates the intuition for this procedure. The model's decision function is represented by the blue/pink background, and is clearly nonlinear. The bright red cross is the instance being explained (let's call it X). We sample instances around X, and weight them according to their proximity to X (weight here is indicated by size). We then learn a linear model (dashed line) that approximates the model well in the vicinity of X, but not necessarily globally. For more information, read our paper, or take a look at this blog post.

Contributing

Please read this.

lime (marcotcr/lime)

Searching Database…

12.2K ·GitHub
这是什么?LIME(Local Interpretable Model-agnostic Explanations,局部可解释的模型无关解释)是一个 Python 包,可以解释任意机器学习分类器的单次预测结果,无论它处理的是文本、表格数据还是图像。
这是我要导入的库,还是独立的应用程序?它是一个 Python 库,用 pip 安装后,可以在你自己的代码或 Jupyter Notebook 中调用;解释结果可以渲染为 HTML 或 matplotlib 图表。
我的模型需要特定的框架吗?不绑定任何框架:你的分类器只需要一个函数,接收原始文本或 numpy 数组,并返回每个类别的概率。scikit-learn 分类器开箱即用,教程中还涵盖了 Keras、PyTorch 和 H2O。
安装时有哪些需要注意的坑?从 0.2.0 版本开始不再支持 Python 2,因此你需要使用 Python 3;0.1.1.37 是最后一个支持 Python 2 的版本。
LIME 的解释结果具体会展示什么?它是对模型在某个特定预测附近行为的局部线性近似,例如,展示是哪些加权词语把文本分类结果推向了某一类别或另一类别。
它只适用于分类问题吗?主要是分类,但教程中也包含一个简单的回归示例,所以它并不局限于分类器。
什么是 Submodular Pick?这是该包中的一种额外技术,用于挑选一组具有代表性且互不冗余的已解释样本供你审查,而不必逐条检查预测结果。
我能不从头写代码就试用它吗?可以。仓库中提供了现成的 Jupyter Notebook 教程,涵盖文本、表格和图像分类器(包括 Keras、PyTorch 和 H2O 的示例),你可以直接拿来修改使用。
Creator
marcotcr
Size
20.6 MB
Stars
12.2K
Age
10y
Commits · 90 Days