6.3.2 · HinglishInterpretability & Explainability

Feature attribution (SHAP, LIME)

2,840 words13 min readRead in English

6.3.2 · AI-ML › Interpretability & Explainability

Core concepts

Feature attribution har input feature ko ek single prediction ke liye numerical importance score assign karta hai. Global feature importance (jaise permutation importance) se alag, attribution instance-specific hota hai: wahi feature ek prediction ke liye critical ho sakta hai aur doosre ke liye irrelevant.

Challenge yeh hai: modern models (deep nets, ensembles) non-linear, interactive compositions hain. Kisi feature ka contribution doosre features ki values par depend karta hai. Hume ek principled tarika chahiye ko additive contributions mein decompose karne ka.

Figure — Feature attribution (SHAP, LIME)

LIME: Local Interpretable Model-agnostic Explanations

Core idea

LIME model ko ek black box maanta hai aur ek locally faithful linear approximation banata hai.

Linear kyun? Humans linear models ko aasani se interpret karte hain: "feature prediction ko per unit badhata hai." Chahe globally non-linear ho, ke paas woh roughly linear ho sakta hai.

Yeh kaise kaam karta hai:

  1. Perturbations generate karo: ke paas naaye instances randomly features toggle/perturb karke sample karo.
  2. Proximity se weigh karo: Weight assign karo taaki close neighbors zyada matter karein.
  3. Local linear model fit karo: Solve karo

jahan linear models ki class hai, weighted squared loss hai, complexity ko penalize karta hai (jaise, L1 se kuch features select hote hain).

ke coefficients LIME explanations hain: .


SHAP: SHapley Additive exPlanations

Game-theoretic foundation

SHAP cooperative game theory ke Shapley values par based hai. Socho features ek coalition mein players hain, aur "payout" model ki prediction hai.

Sawaal: Har player (feature) aur average prediction ke beech ke difference mein kitna contribute karta hai?

Scratch se DERIVATION:

  1. Setup: Hamare paas features hain. Subset ke liye, define karo expected prediction ke roop mein jab hum ke features observe karte hain aur baaki ko marginalize karte hain:

Marginalize kyun? Missing features ko zeros ke bajaye unki typical distribution se replace karte hain.

  1. Marginal contribution: Jab hum feature ko coalition mein add karte hain, gain hai:

  2. Saari orderings par average karo: Features ki orderings hoti hain. Har ordering mein, kuch set ke baad aata hai. Un orderings ki sankhya jahan exactly ke features ke baad aata hai: . Toh us configuration ki probability hai:

Saare par ka weighted average Shapley value deta hai.

Result: feature ko fair credit hai baseline se tak prediction move karne ke liye.

SHAP compute karna: challenge

Exact Shapley values ke liye evaluations chahiye (saare subsets). High-dimensional data ke liye yeh intractable hai.

Solutions:

  1. KernelSHAP (model-agnostic): Shapley values ko ek weighted linear model fit karke approximate karta hai (LIME jaisa, lekin specific Shapley weights ke saath). Samples →∞ hone par true Shapley par converge karta hai.

  2. TreeSHAP (tree models ke liye): Tree structure exploit karta hai exact Shapley values polynomial time mein compute karne ke liye. Kaise: Tree traverse karo, feature splits track karo, aur paths par expectations compute karo.

  3. DepSHAP (neural nets ke liye): Backpropagation + reference values use karke approximate karta hai.


LIME vs SHAP: tradeoffs

Aspect LIME SHAP
Foundation Locally faithful linear model Shapley values (game theory)
Guarantees Koi nahi (approximation-dependent) Efficiency, symmetry, dummy axioms
Compute cost , flexible exact; TreeSHAP , KernelSHAP approx
Stability Kam samples ke saath high variance Zyada stable (principled)
Additivity Koi guarantee nahi Exact:
Use case Quick, interpretable, jab consistency critical nahi Jab theoretically sound, consistent explanations chahiye

LIME kyun use karein? Speed + simplicity. Tum ek one-off prediction ko reasonable samples ke saath seconds mein explain kar sakte ho. Prototyping aur user-facing apps ke liye badhiya jahan "roughly right" kaafi ho.

SHAP kyun use karein? Jab decisions high-stakes hoon (healthcare, finance) aur tumhe defensible, consistent explanations chahiye. SHAP ki additivity ka matlab hai tum ek prediction ko exactly decompose kar sakte ho. TreeSHAP tree models ke liye fast bhi hai.

Recall Ek 12-saal ke bachche ko explain karo

Socho tumhara teacher tumhe ek group project par grade deta hai. Tum jaanna chahte ho: "Maine kitna contribute kiya vs mere teammates ne?"

LIME aisa hai jaise paas ke kuch classmates se poochho: "Agar main group mein nahi hota, toh kya grade kam hota?" Phir unke jawaabon ka average lo. Yeh quick hai, lekin agar alag logon se poochho, toh alag jawab mil sakte hain.

SHAP aisa hai jaise teacher carefully calculate kare: "Agar main imagine karun saare possible groups with aur without tumhare, aur average karun ki grade kitna badlta hai jab tum add hote ho, wahi tumhara exact contribution hai." Yeh fair hai, sab isse agree karte hain, lekin compute karne mein zyada time lagta hai.

Dono tumhe samajhne mein help karte hain kyun grade (prediction) woh hai jo hai, ek feature (person) ek baar mein.


Connections

6.301-Global-vs-local-interpretability – Feature attribution canonical local method hai.

  • 6.2.03-Attention-mechanisms – Attention weights feature attribution ka ek form hain (halanki Shapley-based nahi).
  • 5.4.02-Permutation-importance – Global feature importance; SHAP ko aggregate karke similar rankings recover ki ja sakti hain.
  • 6.3.03-Counterfactual-explanations – Alternative local explanation: " ko mein badlo prediction flip karne ke liye."
  • 3.5.04-Tree-ensembleinterpretation – TreeSHAP fast exact computation ke liye tree structure leverage karta hai.

#flashcards/ai-ml

Feature attribution kya hai? :: Har input feature ko ek single prediction ke liye numerical importance score assign karna, yeh dikhate hue ki har feature ne us specific output mein kitna contribute kiya.

LIME "local" kyun hai?
LIME instance ke aas-paas ek chote neighborhood mein ek simple interpretable model (linear) fit karta hai, proximity se weighted.

LIME objective function derive karo :: Weighted squared loss se shuru karo ( ke paas ke closeness ke liye), complexity penalty (sparsity) add karo, unka sum minimize karo locally faithful sparse linear paane ke liye.

Shapley values kya hain?
Unique fair attribution jo efficiency (), symmetry, dummy, aur linearity satisfy karta hai. Feature ke liye: , saari coalitions par averaged marginal contribution.
SHAP values prediction mein kyun sum hote hain?
Shapley values ke efficiency axiom se: , jahan base rate hai. Yeh exact hai, approximate nahi.
TreeSHAP polynomial time kaise achieve karta hai?
Tree structure exploit karta hai: har split ke liye, training data ka fraction compute karo jo har direction jaata hai, use alternative branch ki expectation weight karne ke liye use karo. Saare subsets explicitly enumerate karne ki zaroorat nahi.
LIME high variance mistake aur fix
Bahut kam perturbations use karna (jaise 10) linear fit ko unstable banata hai; explanations ek run se doosre mein wildly vary karte hain. Fix: 1,000–10,000 samples use karo aur multiple runs mein stability check karo.

Key difference: LIME vs SHAP guarantees :: LIME ek approximation hai jisme fidelity ya additivity ki koi theoretical guarantee nahi. SHAP mein axiom-based guarantees hain: efficiency, symmetry, dummy player, jo ise theoretically sound aur consistent banate hain.

SHAP pe LIME kab use karein?
Jab prototyping ya low-stakes user-facing explanations ke liye speed aur simplicity chahiye, aur approximate local fidelity kaafi ho. LIME flexible sampling ke saath kisi bhi model type ko explain kar sakta hai.
Shapley derivation mein kya hai?
Expected prediction jab subset ke features par observe kiye jaate hain aur mein nahi hone wale features marginalize kiye jaate hain: . Yeh marginal contributions compute karne ke liye baseline define karta hai.

Concept Map

assigns

contrasts with

relies on

approximates f near x

step 1

step 2

step 3 fit

penalized by

yields

are the

also computed by

Feature attribution

Local explanation

Global importance

Instance-specific score

LIME

Generate perturbations

Weigh by proximity

Local linear model

LIME coefficients

L1 sparsity penalty

SHAP