The Integrated Gradients Formula
What you'll learn: How Integrated Gradients (IG) mathematically computes attribution by integrating gradients along a straight path from baseline to input.
The Core Formula
Integrated Gradients answers a fundamental question: how much does each feature contribute to a model's prediction relative to a baseline? The answer comes from accumulating gradients along the path connecting these two points.
The formula for the attribution of feature i is:
IG_i(x) = (x_i - x'_i) × ∫₀¹ ∂F(x' + α(x - x'))/∂x_i dα
Where:
- x is your input
- x' is your baseline
- F is your model
- α ranges from 0 to 1, parameterizing the straight-line path
Understanding the Components
Think of this as a road trip analogy: you're driving from baseline (x') to input (x). At each point along the highway, you check your speedometer (the gradient). The integral sums up all these instantaneous rates over the entire journey.
The (x_i - x'_i) term is the scaling factor—the total distance traveled by feature i. The integral ∫₀¹ accumulates how sensitive the model is to that feature at every intermediate point x' + α(x - x').
In practice, you approximate this integral using a Riemann sum with m steps:
IG_i(x) ≈ (x_i - x'_i) × Σₖ₌₁ᵐ [∂F(x' + k/m(x - x'))/∂x_i × 1/m]
This means computing gradients at evenly-spaced points and averaging them.
Key Takeaway: Integrated Gradients derives attribution by scaling the input difference with the average gradient along a straight path from baseline to input, satisfying both sensitivity and implementation invariance axioms through calculus.