6.3.10 · HinglishInterpretability & Explainability

Counterfactual explanations

2,404 words11 min readRead in English

6.3.10 · AI-ML › Interpretability & Explainability

Counterfactual Explanations HAIN KYA?

Yeh teen criteria kyun?

  • Proximity: Agar changes bahut zyada hain, toh explanation useful nahi hai ("Approve hone ke liye, ek alag insaan ban jao").
  • Validity: ko actually produce karna chahiye (sirf close hona kaafi nahi).
  • Plausibility: realistic hona chahiye (age negative nahi ho sakti, aap koi degree "un-complete" nahi kar sakte).

Counterfactuals KAISE Generate Karein

First Principles Se Derivation

Problem setup: Hamare paas hai aur black-box hai jiske liye (loan denied) hai. Hum chahte hain jahan (approved) ho.

Step 1: Loss function define karo

Humein teen competing goals ko balance karna hai:

Har term kyun?

  1. distance (): Encourage karta hai ki kam features change hon. sparse solutions deta hai (kaafi components zero change par rehte hain). kyun nahi? change ko kaafi features mein spread karta hai; ise concentrate karta hai.

  2. Prediction par Hinge loss: Binary classifier ke liye jo probability output karta hai: Yeh zero hota hai jab (desired class), otherwise positive. Hinge kyun? Differentiable hai, ko decision boundary ke paar push karta hai.

  3. Manifold distance: Unrealistic combinations ko penalize karta hai. Yeh ho sakta hai:

    • Nearest training point se distance:
    • VAE reconstruction error:
    • Feature validity constraints (age , categorical levels)

Step 2: Optimization

Gradient-based (Wachter et al. 2017):

se start karo, tab tak iterate karo jab tak na ho jaaye ya max steps tak.

Categorical features ke liye: One-hot encoding use karo, phir optimization ke baad nearest valid category par round karo.

Constraints ke liye (jaise age ): Har step ke baad ko feasible set par project karo:



YEH KYU Kaam Karta Hai: Decision Boundaries ki Geometry

Ek linear classifier socho: .

Decision boundary hai . Agar negative side par hai, toh boundary par closest point yeh hai:

Derivation: Hum minimize karna chahte hain subject to . Lagrange multipliers use karo:

lo.

Constraint mein substitute karo: .

Is tarah: . ✓

Neural networks ke liye: Boundary nonlinear hai, isliye hum gradient descent use karte hain uski taraf "walk" karne ke liye.




Counterfactuals Generate Karne ke Methods

1. Gradient-Based (Wachter et al.)

Algorithm:

Initialize x' = x
for t = 1 to max_iter:
    loss = ||x' - x||₁ + λ·hinge(f(x')) + γ·plausibility(x')
    x' = x' - α·∇(loss)
    x' = project_to_valid(x')  # enforce constraints
    if f(x') == y_target: break
return x'

Pros: Fast hai, kisi bhi differentiable model ke saath kaam karta hai. Cons: Adversarial (implausible) examples dhundh sakta hai.

2. DiCE (Diverse Counterfactual Explanations)

Idea: Sirf ek ki jagah multiple diverse counterfactuals generate karo.

Kyun? Users ko options chahiye: "Ya toh income $10k badhao YA credit score 40 points improve karo."

Method: Loss mein diversity term add karo:

Last term counterfactuals ke ek-doosre se similar hone ko penalize karta hai. Hum chahte hain ki ek-doosre se door hon.

3. FACE (Feasible and Actionable Counterfactuals)

Causal constraints add karta hai: Kuch features change nahi ho sakti (race, gender) ya sirf increase ho sakti hain (education level).

Directed acyclic graph (DAG) causal structure encode karta hai. Sirf wahi changes allow karo jo ke saath consistent hain.




Counterfactuals ke Liye Evaluation Metrics

Hum counterfactual quality kaise measure karte hain?

Metric Formula Desirable Value
Validity 1 (prediction flip honi chahiye)
Proximity Chhota (kam changes)
Sparsity Chhota (kam features change huyein)
Plausibility Chhota (training data ke close)
Diversity (sets ke liye) Bada (alag-alag options)

Trade-offs: Proximity vs. plausibility (closest counterfactual unrealistic ho sakta hai). Sparsity vs. validity (1 feature change karna kaafi nahi ho sakta).


Recall 12-Saal Ke Bachche Ko Explain Karo

Socho tumne ek club mein apply kiya aur reject ho gaye. Tum poochho, "Kyun?" Woh kehte hain, "Kyunki reasons." Helpful nahi!

Ab socho woh kehte hain: "Agar club mein pehle se 2 aur dost hote, toh tum accept ho jaate." Yeh ek counterfactual hai—yeh batata hai ki andar aane ke liye exactly kya change karna hai.

AI ke liye counterfactual explanations waisi hi hain: computer kehta hai "Tumhara loan reject hua. Lekin agar income $5k zyada hoti, toh approve ho jaata." Yeh apna poora decision process explain nahi kar raha—yeh tumhe ek specific action de raha hai jo tum le sakte ho.

Yeh "Tumhari income important thi" se better kyun hai? Kyunki "important" nahi batata ki kitna change karna hai. Counterfactual tumhe ek concrete goal deta hai.



Connections LIME: Dono local explanations provide karte hain, lekin LIME linear model se approximate karta hai, counterfactuals specific input changes dikhate hain

  • SHAP: SHAP explain karta hai "yeh prediction kyun?", counterfactuals explain karte hain "kya change karein?"
  • Adversarial Examples: Counterfactuals "achhe" adversarial examples hain (realistic, interpretable); adversarials "bure" hain (minimal imperceptible noise)
  • Causal Inference: Counterfactuals causal structure respect karte hain (do-calculus), correlation-based methods ke unlike
  • Recourse: Algorithmic recourse = actionable counterfactuals subject to constraints (cost, feasibility)
  • Model Debugging: Out-of-distribution counterfactuals model flaws aur biases reveal karte hain

#flashcards/ai-ml

Ek counterfactual explanation ko kaunsi teen key properties satisfy karni chahiye? :: (1) Validity: (alag prediction), (2) Proximity: close hai ke (minimal change), (3) Plausibility: realistic/actionable hai

Tabular data mein counterfactual proximity ke liye norm ki jagah norm kyun use karte hain?
sparse changes encourage karta hai (kam features modify hote hain), jabki chhote changes ko kaafi features mein spread karta hai. Interpretability ke liye, hum jitna ho sake utne kam features change karna chahte hain.

Counterfactual generate karne ka optimization objective se likhko :: $$\min_{\mathbf{x}'} |\mathbf{x}' - \mathbf{x}|1 + \lambda \cdot \text{hinge}(f(\mathbf{x}')) + \gamma \cdot d{\text{manifold}}(\mathbf{x}') \text{ where the three terms balance proximity, prediction validity, and realism.}

Counterfactual explanations mein "actionability" problem kya hai?
Kuch features immutable hote hain (age, race, past events) ya change karna mushkil hota hai. Ek counterfactual jo suggest kare "apni age 25 se 45 karo" mathematically valid hai lekin user ke liye useless hai. Solution: immutable features ko infinite cost ya hard constraints se mark karo.

DiCE (Diverse Counterfactual Explanations) single-counterfactual methods se kaise alag hai? :: DiCE multiple diverse counterfactuals generate karta hai ek diversity term -\gamma \sum_{i<j} |\mathbf{x}_i' - \mathbf{x}_j'| add karke jo counterfactuals ke beech similarity ko penalize karta hai. Isse users ko options milte hain: "Ya toh income badhao YA credit score improve karo."

Linear classifier f(\mathbf{x}) = \text{sign}(\mathbf{w}^\top \mathbf{x} + b) ke liye, \mathbf{x} se decision boundary par closest point kya hai? ::: Yeh Lagrange multipliers use karke subject to minimize karke derive kiya jaata hai.

Counterfactual generation mein plausibility constraint kya hai aur ise kaise enforce karte hain?
Plausibility ensure karta hai ki data manifold mein lie kare (realistic ho). Enforce hota hai: (1) nearest training point se distance, (2) VAE reconstruction error, (3) feature validity constraints (jaise age ), ya (4) generative model se generate karke.
Counterfactuals SHAP ya LIME explanations se zyada actionable kyun hain?
SHAP/LIME explain karte hain "kaun se features prediction mein contribute kiye" (attribution), jabki counterfactuals specify karte hain "feature X ko value A se value B karo outcome Y ke liye" (prescription). Counterfactuals directly "mujhe kya karna chahiye?" ka jawab dete hain, jo end users ke liye zyada actionable hai.

Concept Map

answers

provides

requires

requires

requires

encoded by

encoded by

encoded by

term of

term of

term of

minimized in

yields

Counterfactual explanation

What minimal change flips prediction

Actionable and contrastive

Proximity - close to x

Validity - different prediction

Plausibility - on data manifold

Optimization loss function

L1 distance - sparsity

Hinge loss on prediction

Manifold distance - realism

Minimize loss to find x prime