Skip to content

Interpretability, attribution, and explanation audits · Interpretability, explanations, and model-mechanism analysis · EXP008 · Algorithm

Training-example influence functions

Approximate how a fitted model or a selected test loss changes when the weight of a training observation changes infinitesimally.

Partly runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method covers part of this entry; some options or variants aren't built yet.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Partly runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.linear. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Approximate how a fitted model or a selected test loss changes when the weight of a training observation changes infinitesimally.

Question / hypotheses

Which training cases locally increase or decrease this test loss through the fitted optimum? This differs from input-feature attribution.

Architecture / computational structure

At an optimum, per-example gradients and an empirical-risk Hessian define a linear-response calculation. In large models, Hessian-vector products and iterative linear solvers avoid explicitly storing the full Hessian. A damped solve changes the approximation.

Assumptions

The classical derivative assumes a differentiable objective, an isolated regular optimum, and an invertible relevant Hessian. Nonconvex deep models, incomplete convergence and singular curvature weaken that interpretation. Removing a whole example is a finite change, not the infinitesimal perturbation itself.

Formula / computational definition

dθ^ϵdϵ∣0=−H−1∇ℓi(θ^),Ii→t=−∇ℓt(θ^)⊤H−1∇ℓi(θ^).\left.\frac{d\widehat\theta_\epsilon}{d\epsilon}\right|_0=-H^{-1}\nabla\ell_i(\widehat\theta),\qquad I_{i\to t}=-\nabla\ell_t(\widehat\theta)^\top H^{-1}\nabla\ell_i(\widehat\theta).

Parameters and notation

Learned predictor parameter θ is held at its fitted optimum for the derivative. Numerical choices include loss normalization, damping, solver tolerance, selected layers, approximation samples, and test target. Sign and factors of n depend on whether perturbations upweight, remove, or replace observations. Here ell_i and ell_t are training-point and test-point losses, epsilon is infinitesimal additive loss upweighting, theta-hat the fitted optimum, and H the Hessian of the full fitted objective at that optimum, including its regularizer.

Fitting, fine-tuning, and adaptation

Recompute gradients/curvature after fine-tuning. A new training objective, weight decay, or loss scaling changes influence. Compare the approximation against actual small upweighting/refits before using it for data review.

How to use and calibrate

Validate on convex small models where exact refits are feasible. Report linear-solver residuals, convergence, damping sensitivity, and agreement for finite perturbations. Use influential examples to investigate data quality, not to conclude they are necessarily wrong.

Example application

Identify which synthetic ridge-regression cases most change a chosen test residual, and verify an infinitesimal upweighting with an exact refit.

Interpretation / pitfalls

Watch out

The inverse Hessian can be unstable. Gradient similarity alone is not this influence function. Large deletions, retraining randomness and optimizer-path dependence can invalidate a local approximation.

Python and R code examples

Scope: Complete ridge-regression influence derivative with a finite-upweighting verification. Python: NumPy; R: base R.

Validation: Python executed successfully on the supplied fixture; R reviewed but unexecuted. Full implementations and supported operation details are provided in the linked primary/official sources.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Complete ridge-regression influence derivative with a finite-upweighting verification. Python: NumPy; R: base R. · needs numpy

import numpy as np
X=np.array([[1.,0.],[1.,1.],[1.,2.],[1.,3.]]);y=np.array([0.,1.2,1.8,3.1]);n=len(y);lam=.2
H=X.T@X/n+lam*np.eye(2);theta=np.linalg.solve(H,X.T@y/n)
i=1;xt=np.array([1.,1.5]);yt=1.4;gi=(X[i]@theta-y[i])*X[i];gt=(xt@theta-yt)*xt
influence=-gt@np.linalg.solve(H,gi);eps=1e-5
te=np.linalg.solve(H+eps*np.outer(X[i],X[i]),X.T@y/n+eps*X[i]*y[i])
fd=(.5*(xt@te-yt)**2-.5*(xt@theta-yt)**2)/eps
assert abs(fd-influence)<1e-6;print(influence,fd)
R

Complete calculation — Complete ridge-regression influence derivative with a finite-upweighting verification. Python: NumPy; R: base R.

X<-cbind(1,0:3);y<-c(0,1.2,1.8,3.1);n<-length(y);lam<-.2
H<-crossprod(X)/n+lam*diag(2);theta<-solve(H,crossprod(X,y)/n)
i<-2;xt<-c(1,1.5);yt<-1.4;gi<-(sum(X[i,]*theta)-y[i])*X[i,];gt<-(sum(xt*theta)-yt)*xt
influence<--sum(gt*solve(H,gi));eps<-1e-5
te<-solve(H+eps*tcrossprod(X[i,]),crossprod(X,y)/n+eps*X[i,]*y[i])
fd<-(.5*(sum(xt*te)-yt)^2-.5*(sum(xt*theta)-yt)^2)/eps
stopifnot(abs(fd-influence)<1e-6);print(c(influence,fd))

Sources

From the CodeSplash reference, entry EXP008.