← Back to Classic ML Mind Map
📊 Classic MLID: shap-lime

SHAP & LIME

可解释性 SHAP 与 LIME
🎯Core Definition
SHAP and LIME are the two most common model explainability methods. SHAP performs strictly additive feature attribution based on the game-theoretic Shapley value: ϕi=∑S⊆N∖{i}∣S∣!(∣N∣−∣S∣−1)!∣N∣![v(S∪{i})−v(S)]\phi_i = \sum_{S \subseteq N\setminus\{i\}} \frac{|S|!(|N|-|S|-1)!}{|N|!}[v(S\cup\{i\}) - v(S)], where v(S)v(S) is the expected prediction given feature subset SS and the weight ∣S∣!(∣N∣−∣S∣−1)!∣N∣!\frac{|S|!(|N|-|S|-1)!}{|N|!} is the ordering share of feature ii among coalition permutations; Shapley values are the unique attribution satisfying efficiency, symmetry, dummy and additivity, decomposing the output exactly as ∑iϕi=f(x)−E[f]\sum_i \phi_i = f(x) - E[f]. TreeSHAP exploits the tree structure to compute exact values in O(TLD2)O(TLD^2) without sampling, while LIME fits a local interpretable surrogate min⁡gL(f,g,πx)\min_g \mathcal{L}(f, g, \pi_x) — a sparse linear/decision model gg approximating ff in a πx\pi_x-weighted neighborhood around xx.
💡Use Cases
feature explanation for production risk/credit/recommendation models; interview questions like "SHAP vs LIME, how do you choose" or "how to attribute a black-box model"; global explanations via SHAP importance/dependence plots, local ones via force plots or LIME weights; in industry TreeSHAP is the default for tree ensembles.
⚡Key Problems Solved
linear coefficients only explain additive-linear relationships, while SHAP decomposes any nonlinear model's output fairly across features — additivity guarantees ∑iϕi=f(x)−E[f]\sum_i \phi_i = f(x) - E[f], so attributions exactly sum to prediction minus baseline and stay comparable across models and samples; unlike LIME whose random sampling is non-reproducible, TreeSHAP is exact, fast and deterministic for trees.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of SHAP & LIME.
Use Cases
In production engineering, what are the primary use cases for SHAP & LIME and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Write the Shapley formula ϕi=∑S⊆N∖{i}∣S∣!(∣N∣−∣S∣−1)!∣N∣![v(S∪{i})−v(S)]\phi_i = \sum_{S \subseteq N\setminus\{i\}} \frac{|S|!(|N|-|S|-1)!}{|N|!}[v(S\cup\{i\}) - v(S)], explain the weight ∣S∣!(∣N∣−∣S∣−1)!∣N∣!\frac{|S|!(|N|-|S|-1)!}{|N|!}, and why it is the unique attribution satisfying efficiency/symmetry/dummy/additivity?
2
SHAP's additivity: why does ∑iϕi=f(x)−E[f]\sum_i \phi_i = f(x) - E[f]? How does it fundamentally differ from linear-model coefficients (LIME weights)?
3
Why can TreeSHAP compute exact values for trees? Decode O(TLD2)O(TLD^2) and explain why no sampling is needed.
4
Write LIME's surrogate objective min⁡gL(f,g,πx)\min_g \mathcal{L}(f, g, \pi_x): what are gg, πx\pi_x, L\mathcal{L}? Why are LIME results unstable?
5
SHAP vs LIME: global vs local explanations, when to use which; applicability on tabular/image/text tasks?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "SHAP & LIME"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardData LeakageNext Card →Data Drift & PSI

🔗 More Classic ML Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/ML/card/shap-lime
中文速览与面试要点

可解释性 SHAP 与 LIME (SHAP & LIME)

定义: SHAP 与 LIME 是最常用的两类模型可解释性方法。SHAP 基于博弈论 Shapley 值做严格加性的特征归因: _i = _S N \i\ |S|!(|N|-|S|-1)!|N|![v(S \i\) - v(S)],其中 v(S) 是特征子集 S 的预测期望,权重 |S|!(|N|-|S|-1)!|N|! 是特征 i 在联盟序列中的排列占比;Shapley 值是唯一同时满足效率性、对称性、虚拟性与可加性的归因解,输出被精确分解为 _i _i = f(x) - E[f]。TreeSHAP 利用树结构在 O(TLD^2) 内精确计算(无需采样),LIME 则拟合局部可解释替代模型 _g L(f, g, _x),在实例 x 的 _x 加权邻域内用稀疏线性/决策树 g 近似 f。 使用场景: 风控/信贷/推荐模型上线后做特征解释;面试常问“SHAP 和 LIME 怎么选”“给黑盒模型做归因用什么”;全局解释看 SHAP 特征重要性排序与依赖图,单样本解释看 force plot 或 LIME 局部权重;树模型(如 XGBoost/LightGBM)在工业界一律用 TreeSHAP。 解决的问题: 相比线性模型系数只能解释可加线性关系,SHAP 把任意非线性模型的输出公平分解到各特征——加性属性保证 _i _i = f(x) - E[f]、归因和恒等于预测与基线之差,且跨模型、跨样本可比较;相比 LIME 随机采样导致的不可复现(扰动范围与采样种子都会改变结果),TreeSHAP 对树模型精确、快速且结果唯一确定。

核心要点

  • 写出 Shapley 值公式 _i = _S N \i\ |S|!(|N|-|S|-1)!|N|![v(S \i\) - v(S)],解释权重 |S|!(|N|-|S|-1)!|N|! 的含义,并说明它是唯一满足效率/对称/虚拟/可加性的归因?
  • SHAP 的加性属性: 为什么 _i _i = f(x) - E[f]?这与线性模型系数(LIME 的权重)有何本质区别?
  • TreeSHAP 为什么能对树模型精确计算?复杂度 O(TLD^2) 各符号的含义,为什么不需要采样?
  • 写出 LIME 的局部替代目标 _g L(f, g, _x): g、 _x、 L 分别是什么?为什么 LIME 的结果不稳定?
  • SHAP vs LIME 对比: 全局 vs 局部解释分别怎么选?在表格/图像/文本任务上的适用性?