# 局部可解释的模型无关解释

局部可解释的模型无关解释（LIME）是一种事后解释方法：它针对单个样本，用一个简单、人类可读的模型去拟合该样本的扰动，以此近似黑箱机器学习模型的预测。对一次预测，它的输出是一份简短的清单，列出对人类有意义的成分——文档中的词、图像中的超像素，或表格特征——每一项都带有一个带符号的权重，表明它如何把预测推向或推离某个类别。LIME 的提出是为了解决一个信任问题：一个分类器可以总体上很准确，却依赖虚假的线索，因此仅凭聚合指标无法告诉用户某一次单独的预测是否可靠。在一项演示中，一个 RBF 核 SVM 在 20 newsgroups 数据集上取得了 94% 的留出准确率，但其预测依据却是与主题毫无关系的邮件头词汇。<sup>[1](https://aclanthology.org/N16-3020.pdf)</sup> 这个名字拆解开来就是它的三项设计承诺：围绕被解释样本的**局部**保真，诸如词而非嵌入这类**可解释**的表示，以及把分类器当作黑箱对待的**模型无关**运行方式。<sup>[2](https://homes.cs.washington.edu/~marcotcr/blog/lime/)</sup>

| 关键事实 | 取值 |
|---|---|
| 提出者 | 马尔科·图利奥·里贝罗（Marco Tulio Ribeiro）、萨米尔·辛格（Sameer Singh）与卡洛斯·格斯特林（Carlos Guestrin），华盛顿大学（University of Washington），2016<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> |
| 代理模型 | 稀疏线性模型，默认 \( K = 10 \) 个特征，由 K-LASSO 选取<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> |
| 默认采样数（Python） | 每次解释 5,000 个扰动样本，岭回归<sup>[4](https://lime-ml.readthedocs.io/en/stable/lime.html)</sup> |
| 运行时间 | 1,000 棵树的随机森林（\( N = 5{,}000 \)）不到 3 秒；Inception 每张图像预测约 10 分钟<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> |
| 保真度 | 在情感数据集上，对逻辑回归与决策树，真正重要特征的召回率超过 90%<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> |
| 已知弱点 | 重复运行不稳定；扰动偏离流形；易受对抗性脚手架影响<sup>[5](https://ar5iv.labs.arxiv.org/html/2305.12351)</sup> |
| 官方 Python 包 | BSD 2-Clause，最新版本 0.2.0.1<sup>[6](https://www.github.com/marcotcr/lime)</sup> |

## 工作原理

LIME 基于这样一个直觉：用简单模型去近似黑箱模型，在单次预测的邻域内要比全局容易得多。<sup>[7](https://www.oreilly.com/content/introduction-to-local-interpretable-model-agnostic-explanations-lime/)</sup> 该方法在输入样本的邻域内施加扰动，观察模型预测如何变化，按扰动点与原样本的接近程度加权，再对这些加权点拟合一个可解释模型。由此得到的解释只在局部保真，而非全局：它只描述某一点附近的决策边界。<sup>[2](https://homes.cs.washington.edu/~marcotcr/blog/lime/)</sup>

形式上，解释是下式的解：

\[ \xi(x) = \operatorname{argmin}_{g \in G} \; L(f, g, \pi_{x}) + \Omega(g), \]

其中 \( f \) 是被解释的模型，\( g \) 是可解释模型，\( \pi_{x} \) 是定义 \( x \) 附近局部性的接近度度量，\( \Omega(g) \) 是复杂度惩罚。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 损失为局部加权的平方损失，

\[ L(f, g, \pi_{x}) = \sum_{z} \pi_{x}(z) \left( f(z) - g(z') \right)^{2}, \]

配以指数接近度核

\[ \pi_{x}(z) = \exp \left( -\frac{D(x, z)^{2}}{\sigma^{2}} \right), \]

其中 \( D \) 是距离，例如文本可用余弦距离，图像可用 L2 距离，\( \sigma \) 是核宽。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup>

## 具体做法

无论何种模态，实践者都运行同样的五步循环：扰动样本，用扰动去查询黑箱，按相似度给扰动加权，拟合一个稀疏的可解释模型，然后读取其权重作为特征归因。<sup>[8](https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html)</sup>

模态决定可解释表示与扰动方案。对文本，表示是词袋，扰动随机隐藏词；返回的解释包含截距、排序后的特征权重，以及局部模型的 \( R^{2} \)。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup><sup> • </sup><sup>[4](https://lime-ml.readthedocs.io/en/stable/lime.html)</sup> 对表格数据，数值特征通过从标准正态分布采样、并反演从训练数据学到的均值中心化与缩放来扰动，连续特征默认按四分位数离散化。<sup>[4](https://lime-ml.readthedocs.io/en/stable/lime.html)</sup> 对图像，样本被分割为 \( d \) 个超像素，作为二值可解释特征（1 = 原超像素，0 = 置灰）；被关闭的像素替换为参考值，如平均像素强度。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup><sup> • </sup><sup>[9](https://link.springer.com/chapter/10.1007/978-3-032-08324-1_2)</sup>

三个超参数主导着解释的行为。**核宽** \( \sigma \) 控制扰动对拟合的影响范围：Python 与 R 实现默认为特征数平方根的 0.75 倍，而 MATLAB 无论特征多少都使用固定的默认 KernelWidth 0.75；已发表的文献在这一点上并无统一约定。<sup>[8](https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html)</sup><sup> • </sup><sup>[10](https://www.mathworks.com/help/releases/R2024a/stats/lime.html)</sup> **样本数**在成本与稳定性之间权衡：Python 默认为 5,000。<sup>[4](https://lime-ml.readthedocs.io/en/stable/lime.html)</sup> **特征数** K 限制稀疏性；原始论文除另有说明外将 K 设为 10，但后来有一篇论文称默认为 6，因此该值取决于所参考的实现。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup><sup> • </sup><sup>[11](https://ar5iv.labs.arxiv.org/html/2208.01510)</sup> 对文本，随包发布的代码中的带宽对应 ν = 0.25，其作者表示没有选择 ν 的原则性方法；其他带宽可能改变系数的符号。<sup>[12](https://proceedings.mlr.press/v130/mardaoui21a/mardaoui21a.pdf)</sup>

## 起源

LIME 由马尔科·图利奥·里贝罗（Marco Tulio Ribeiro）、萨米尔·辛格（Sameer Singh）与卡洛斯·格斯特林（Carlos Guestrin）在《“我为什么要相信你？”：解释任意分类器的预测》一文中提出，2016 年发布于 arXiv，并在 KDD 2016 上发表。<sup>[13](https://doi.org/10.48550/arxiv.1602.04938)</sup><sup> • </sup><sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 一篇配套的 NAACL 2016 演示论文介绍了这个开源系统，它对大多数数据集与分类器都能在 3 秒内给出解释。<sup>[1](https://aclanthology.org/N16-3020.pdf)</sup> 该方法建立在更早的工作之上：贝伦斯（Baehrens）及其同事的论文《How to Explain Individual Classification Decisions》发表于 2010 年，用在该样本处求值的局部梯度向量来解释单个决策。<sup>[14](https://doi.org/10.48550/arxiv.0912.1128)</sup><sup> • </sup><sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> K-LASSO 特征选择步骤用 Lasso 沿正则化路径选出 K 个特征，再用最小二乘学习权重。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 原始论文中的图像实验解释了塞格迪（Szegedy）及其同事（2014）的 [Inception](https://www.edgepedia.org/zh/inception-network) 网络。<sup>[15](https://doi.org/10.48550/arxiv.1409.4842)</sup>

## 变体

原始论文中已包含 **SP-LIME**，它通过子模挑选选出一组有代表性、不冗余的样本供人检视；覆盖问题是 NP 难的，贪心算法带有 \( 1 - 1/e \) 的常数因子近似保证。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 一份 2025 年的综述梳理了数十个针对特定模态与机制的衍生方法，包括 BayLIME、GLIME、s-LIME、OptiLIME、DSEG-LIME、SLICE、LIMESegment、audioLIME、AttentionLIME、GraphLIME，以及 LIMETREE、LORE 等代理模型替代方案。<sup>[9](https://link.springer.com/chapter/10.1007/978-3-032-08324-1_2)</sup> 代表性例子：

- **BayLIME** 用贝叶斯线性回归器取代加权最小二乘拟合，整合先验知识，以提升重复解释的一致性以及对核设置的稳健性。<sup>[16](https://proceedings.mlr.press/v161/zhao21a/zhao21a.pdf)</sup>
- **DLIME**（扎法尔（Zafar）与汗（Khan），2019）用确定性的、基于聚类的邻域取代随机扰动，用于计算机辅助诊断。<sup>[17](https://doi.org/10.48550/arxiv.1906.10263)</sup>
- **OptiLIME**（维萨尼（Visani）、巴利（Bagli）与凯萨尼（Chesani），2020）自动确定在解释稳定性与保真度之间取得平衡的核宽。<sup>[18](https://doi.org/10.48550/arxiv.2006.05714)</sup><sup> • </sup><sup>[9](https://link.springer.com/chapter/10.1007/978-3-032-08324-1_2)</sup>
- **GLIME**（Tan、Tian 与 Li，2023）以局部性为重点重构采样分布，使解释更稳定。<sup>[19](https://doi.org/10.48550/arxiv.2311.15722)</sup>
- **GraphLIME**（黄（Huang）及其同事，2022）将该方法推广到图神经网络。<sup>[20](https://doi.org/10.1109/tkde.2022.3187455)</sup>
- **SurvLIME**（科瓦列夫（Kovalev）、乌特金（Utkin）与卡西莫夫（Kasimov），2020）将 LIME 适配到生存模型。<sup>[21](https://doi.org/10.1016/j.knosys.2020.106164)</sup>
- **LIME-LLM** 用假设驱动的 LLM 填空取代随机删除词元，在情感、毒性、句法任务上的 ROC-AUC 均优于标准 LIME。<sup>[22](https://arxiv.org/abs/2601.11746v1)</sup>
- **LIMETREE** 通过多输出回归树引入多类局部代理解释，报告称在表格与图像数据上，其解释比 LIME 更保真，而复杂度只有后者的 2/3。<sup>[23](https://www.mdpi.com/2079-9292/14/5/929)</sup>

## 应用

综述层面的证据表明，LIME 被用于医疗、金融与制造业，并可与神经网络、CNN、LSTM、Transformer、决策树和随机森林兼容。<sup>[9](https://link.springer.com/chapter/10.1007/978-3-032-08324-1_2)</sup> 在最初的人类受试实验中，使用 LIME 的非专家能够从一对分类器中挑出泛化更好的那个，而以 LIME 为指导的特征工程大幅改善了一个不可信的 20 newsgroups 分类器，支持了它用于模型调试的用途。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 经典的图像例子很能说明问题：对 Inception 给出的“树蛙”预测，解释显示分类器关注的是蛙的脸，而与之竞争的“台球桌”概率之所以出现，是因为蛙的手和眼睛像绿色背景上的台球。<sup>[7](https://www.oreilly.com/content/introduction-to-local-interpretable-model-agnostic-explanations-lime/)</sup>

## 局限与替代方法

在最初的基准测试中，LIME 的保真度很强：在情感数据集上，对逻辑回归与决策树，真正重要特征的召回率超过 90%。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 理论研究对此有所限定。加罗（Garreau）与冯·卢克斯堡（von Luxburg）对表格 LIME 的分析表明，当被解释的模型是线性的时候，代理系数近似正比于 \( f \) 在该样本处的偏导数，但糟糕的参数选择会让 LIME 漏掉重要特征，而且代理模型一般来说并不准确。<sup>[24](https://hal.science/hal-02935171v1/file/main.pdf)</sup> 对文本，马尔达维（Mardaoui）与加罗（Garreau）表明，当扰动样本很多时，系数以高概率集中在一个固定向量附近，该向量只取决于模型、样本与超参数。<sup>[12](https://proceedings.mlr.press/v130/mardaoui21a/mardaoui21a.pdf)</sup>

**不稳定**是记录最多的失效模式：在相同设置下对同一样本重复运行，可能产生不同的解释，因为扰动样本是随机的，而样本量越小，这种不确定性越大。<sup>[16](https://proceedings.mlr.press/v161/zhao21a/zhao21a.pdf)</sup> **偏离流形采样**是第二个弱点：删除词元会产生分布外的文本，使黑箱对扰动的预测不可靠。<sup>[22](https://arxiv.org/abs/2601.11746v1)</sup> **对抗性操纵**是第三个：一种脚手架技术可以掩盖有偏分类器的行为，使解释看起来无害，而预测仍然有偏；针对 LIME 构造的对抗分类器在留出数据上 100% 复现了那个有偏分类器。<sup>[25](https://arxiv.org/html/1911.02508v2)</sup> LIME 还把特征当作相互独立的，因此共线数据会破坏系数的解释。<sup>[26](https://advanced.onlinelibrary.wiley.com/doi/10.1002/aisy.202400304)</sup>

每次解释的成本对表格模型不高，对图像则很高：在笔记本电脑上，1,000 棵树的随机森林取 \( N = 5{,}000 \) 个样本时不到 3 秒，而 Inception 每张图像预测约需 10 分钟，因为每次扰动都是一次昂贵的网络完整前向传播。<sup>[3](https://dl.acm.org/doi/10.1145/2939672.2939778)</sup> 与 **SHAP** 相比，LIME 只做局部解释，而 SHAP 同时提供全局与局部解释；LIME 无法捕捉非线性关联，因为它的代理模型是局部线性的，但它一般并不比 SHAP 快，尤其是对基于树的模型，SHAP 的 TreeExplainer 是一种快速而精确的方法。<sup>[26](https://advanced.onlinelibrary.wiley.com/doi/10.1002/aisy.202400304)</sup><sup> • </sup><sup>[30](https://shap.readthedocs.io/en/stable/generated/shap.TreeExplainer.html)</sup> 一个结构性差异在于接近度核：LIME 中它是启发式选定的，而 KernelSHAP 从博弈论原理中导出；两种方法都没有给出选择扰动数量的指导。<sup>[27](https://papers.nips.cc/paper/2021/file/4e246a381baf2ce038b3b0f82c7d6fb4-Paper.pdf)</sup> 与 **anchors** 相比——后者用“如果……那么……”规则解释预测，其精确率以高概率得到保证——在 UCI adult 与医院再入院数据上的实验显示，anchors 在每一个覆盖水平上的精确率都优于线性 LIME。<sup>[28](https://ucinlp.github.io/files/papers/anchor-nipsws16.pdf)</sup> [SmoothGrad](https://www.edgepedia.org/zh/smoothgrad) 等基于梯度的方法通过加噪来解决显著图的噪声问题，但需要接触模型内部，而 LIME 不需要。<sup>[29](https://doi.org/10.48550/arxiv.1706.03825)</sup> 工具生态已经分化：MATLAB 的实现仍在维护，而官方 Python 包的最新版本是 0.2.0.1。<sup>[10](https://www.mathworks.com/help/releases/R2024a/stats/lime.html)</sup><sup> • </sup><sup>[6](https://www.github.com/marcotcr/lime)</sup>

## References

1. ["Why Should I Trust You?": Explaining the Predictions of Any Classifier (NAACL 2016 demonstration paper; author-hosted copy merged)](https://aclanthology.org/N16-3020.pdf)
2. [LIME - Local Interpretable Model-Agnostic Explanations (author's blog post, April 2, 2016)](https://homes.cs.washington.edu/~marcotcr/blog/lime/)
3. ["Why Should I Trust You?": Explaining the Predictions of Any Classifier (KDD '16; arXiv:1602.04938 and author-hosted PDF copies merged here)](https://dl.acm.org/doi/10.1145/2939672.2939778)
4. [lime Python package documentation (readthedocs)](https://lime-ml.readthedocs.io/en/stable/lime.html)
5. ["Are Your Explanations Reliable?" XAIFooler: stability of LIME for text classifiers](https://ar5iv.labs.arxiv.org/html/2305.12351)
6. [marcotcr/lime (official open-source package)](https://www.github.com/marcotcr/lime)
7. [LIME: An Introduction (O'Reilly, by the LIME authors)](https://www.oreilly.com/content/introduction-to-local-interpretable-model-agnostic-explanations-lime/)
8. [Understanding lime (R package vignette)](https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html)
9. [Which LIME Should I Trust? Concepts, Challenges, and Solutions (Springer chapter; arXiv:2503.24365 version merged)](https://link.springer.com/chapter/10.1007/978-3-032-08324-1_2)
10. [lime, Local interpretable model-agnostic explanations (MathWorks documentation, R2024a; R2023b copy merged)](https://www.mathworks.com/help/releases/R2024a/stats/lime.html)
11. [s-LIME: Reconciling Locality and Fidelity in Linear Explanations](https://ar5iv.labs.arxiv.org/html/2208.01510)
12. [An Analysis of LIME for Text Data (Mardaoui & Garreau, AISTATS 2021)](https://proceedings.mlr.press/v130/mardaoui21a/mardaoui21a.pdf)
13. [Ribeiro, Marco Tulio, Singh, Sameer, Guestrin, Carlos (2016). "Why Should I Trust You?": Explaining the Predictions of Any Classifier. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1602.04938)
14. [Baehrens, David and colleagues (2009). How to Explain Individual Classification Decisions. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.0912.1128)
15. [Szegedy, Christian and colleagues (2014). Going Deeper with Convolutions. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1409.4842)
16. [BayLIME: Bayesian Local Interpretable Model-Agnostic Explanations (UAI/PMLR v161)](https://proceedings.mlr.press/v161/zhao21a/zhao21a.pdf)
17. [Zafar, Muhammad Rehman, Khan, Naimul Mefraz (2019). DLIME: A Deterministic Local Interpretable Model-Agnostic Explanations Approach for Computer-Aided Diagnosis Systems. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1906.10263)
18. [Visani, Giorgio, Bagli, Enrico, Chesani, Federico (2020). OptiLIME: Optimized LIME Explanations for Diagnostic Computer Algorithms. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2006.05714)
19. [Tan, Zeren, Tian, Yang, Li, Jian (2023). GLIME: General, Stable and Local LIME Explanation. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2311.15722)
20. [Qiang Huang and colleagues (2022). GraphLIME: Local Interpretable Model Explanations for Graph Neural Networks. IEEE Transactions on Knowledge and Data Engineering.](https://doi.org/10.1109/tkde.2022.3187455)
21. [Maxim S. Kovalev, Lev V. Utkin, Ernest M. Kasimov (2020). SurvLIME: A method for explaining machine learning survival models. Knowledge-Based Systems.](https://doi.org/10.1016/j.knosys.2020.106164)
22. [LIME-LLM: Probing Models with Fluent Counterfactuals, Not Broken Text](https://arxiv.org/abs/2601.11746v1)
23. [LIMETREE: Consistent and Faithful Surrogate Explanations of Multiple Classes (Electronics, MDPI, 2025)](https://www.mdpi.com/2079-9292/14/5/929)
24. [Theoretical Analysis of Tabular LIME (Garreau & von Luxburg)](https://hal.science/hal-02935171v1/file/main.pdf)
25. [Fooling LIME and SHAP: Adversarial Attacks on Post hoc Explanation Methods](https://arxiv.org/html/1911.02508v2)
26. [A Perspective on Explainable Artificial Intelligence Methods: SHAP and LIME (Advanced Science, Wiley, 2024/2025)](https://advanced.onlinelibrary.wiley.com/doi/10.1002/aisy.202400304)
27. [Reliable Post hoc Explanations: Modeling Uncertainty in Explainability (BayesLIME/BayesSHAP, NeurIPS 2021)](https://papers.nips.cc/paper/2021/file/4e246a381baf2ce038b3b0f82c7d6fb4-Paper.pdf)
28. ["Nothing Else Matters": Model-Agnostic Explanations By Identifying Prediction Invariance (anchors/aLIME)](https://ucinlp.github.io/files/papers/anchor-nipsws16.pdf)
29. [Smilkov, Daniel and colleagues (2017). SmoothGrad: removing noise by adding noise. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1706.03825)
30. [shap.TreeExplainer, SHAP latest documentation](https://shap.readthedocs.io/en/stable/generated/shap.TreeExplainer.html)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › 机器学习与神经计算 › 机器学习方法

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/local-interpretable-model-agnostic-explanations

English original: https://www.edgepedia.org/local-interpretable-model-agnostic-explanations
