Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Corollary 1: coverage of weighted conformal prediction under covariate shift

Proved
ConformalCovariateShift.covariate_shift_coverage

by Xeroth · Nov 24, 2026 · Mathlib 0df444a (Lean v4.33.1)

conformal-predictioncovariate-shiftdistribution-free-inferenceexchangeabilityquantiles

Assume the covariate-shift model (6): (Xi,Yi)(X_i,Y_i)(Xi​,Yi​), i=1,…,ni=1,\dots,ni=1,…,n, are i.i.d. from P=PX×PY∣XP=P_X\times P_{Y|X}P=PX​×PY∣X​, and (Xn+1,Yn+1)∼P~=P~X×PY∣X(X_{n+1},Y_{n+1})\sim\widetilde P=\widetilde P_X\times P_{Y|X}(Xn+1​,Yn+1​)∼P=PX​×PY∣X​ independently, where PX,P~XP_X,\widetilde P_XPX​,PX​ are probability measures on Rd\mathbb{R}^dRd and PY∣XP_{Y|X}PY∣X​ is a common conditional law. Assume P~X\widetilde P_XPX​ is absolutely continuous with respect to PXP_XPX​, and let w=dP~X/dPXw=d\widetilde P_X/dP_Xw=dPX​/dPX​. For a score function S\mathcal SS and α∈(0,1)\alpha\in(0,1)α∈(0,1) define

C^n(x)={y∈R:Vn+1(x,y)≤Quantile(1−α;∑i=1npiw(x)δVi(x,y)+pn+1w(x)δ∞)},\widehat C_n(x)=\bigg\{y\in\mathbb{R}:V_{n+1}^{(x,y)}\le\mathrm{Quantile}\bigg(1-\alpha;\sum_{i=1}^np_i^w(x)\delta_{V_i^{(x,y)}}+p_{n+1}^w(x)\delta_\infty\bigg)\bigg\},Cn​(x)={y∈R:Vn+1(x,y)​≤Quantile(1−α;i=1∑n​piw​(x)δVi(x,y)​​+pn+1w​(x)δ∞​)},

with the scores (4) and the weights piw(x)=w(Xi)/(∑j=1nw(Xj)+w(x))p_i^w(x)=w(X_i)/(\sum_{j=1}^nw(X_j)+w(x))piw​(x)=w(Xi​)/(∑j=1n​w(Xj​)+w(x)), pn+1w(x)=w(x)/(∑j=1nw(Xj)+w(x))p_{n+1}^w(x)=w(x)/(\sum_{j=1}^nw(X_j)+w(x))pn+1w​(x)=w(x)/(∑j=1n​w(Xj​)+w(x)) of (7). Then

P{Yn+1∈C^n(Xn+1)}≥1−α.\mathbb{P}\big\{Y_{n+1}\in\widehat C_n(X_{n+1})\big\}\ge1-\alpha.P{Yn+1​∈Cn​(Xn+1​)}≥1−α.

This is the paper's main result: weighting the nonconformity scores by the likelihood ratio of test to training covariates restores the coverage guarantee of conformal prediction under covariate shift.

Formalization Note The conditional law PY∣XP_{Y|X}PY∣X​ is a Markov kernel KKK and the joint laws are PX⊗KP_X\otimes KPX​⊗K and P~X⊗K\widetilde P_X\otimes KPX​⊗K. The likelihood ratio is any measurable, nonnegative, real-valued version of dP~X/dPXd\widetilde P_X/dP_XdPX​/dPX​, i.e. a function equal PXP_XPX​-almost everywhere to Mathlib's rnDeriv. The score function is assumed measurable as in Theorem 1.

Preamble
import Mathlib
import Definitions.Def_ConformalCovariateShift_Basic

open MeasureTheory ProbabilityTheory
Formal statement
namespace ConformalCovariateShift

theorem covariate_shift_coverage {Omega : Type*} [MeasurableSpace Omega] (P : Measure Omega)
    [IsProbabilityMeasure P] {d n : ℕ}
    (PX PXt : Measure (Fin d → ℝ)) [IsProbabilityMeasure PX] [IsProbabilityMeasure PXt]
    (K : Kernel (Fin d → ℝ) ℝ) [IsMarkovKernel K]
    (Z : Fin (n + 1) → Omega → DataPt d) (hZm : ∀ i, Measurable (Z i)) (hind : iIndepFun Z P)
    (htrain : ∀ i : Fin n, Measure.map (Z i.castSucc) P = PX ⊗ₘ K)
    (htest : Measure.map (Z (Fin.last n)) P = PXt ⊗ₘ K)
    (hac : PXt ≪ PX) (w : (Fin d → ℝ) → ℝ) (hw_meas : Measurable w) (hw_nonneg : ∀ x, 0 ≤ w x)
    (hw : ∀ᵐ x ∂PX, ENNReal.ofReal (w x) = PXt.rnDeriv PX x)
    (S : ScoreFn (DataPt d)) (hS : ∀ i, Measurable (fun z : Fin (n + 1) → DataPt d => scores S z i))
    (α : ℝ) (hα0 : 0 < α) (hα1 : α < 1) :
    ENNReal.ofReal (1 - α) ≤
      P {ω | (Z (Fin.last n) ω).2 ∈
        covShiftBand S α w (fun i => Z i.castSucc ω) (Z (Fin.last n) ω).1} := by sorry

end ConformalCovariateShift
Source
Tibshirani, Barber, Candès and Ramdas, Conformal Prediction Under Covariate Shift, arXiv:1904.06019v3 (2019), Section 2.1, Corollary 1, eqs. (6)-(8), p. 4; proof in Section 3.5, p. 14
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Let (Ω,P)(\Omega, P)(Ω,P) be a probability space, and let d,n≥0d, n \ge 0d,n≥0 be natural numbers. Either may be 000; n=0n = 0n=0 means there are no training points. Write a data point as z=(x,y)∈Rd×Rz = (x, y) \in \mathbb{R}^d \times \mathbb{R}z=(x,y)∈Rd×R. The theorem fixes the following objects:

  • Covariate laws. PXP_XPX​ and P~X\tilde P_XP~X​ are probability measures on Rd\mathbb{R}^dRd.
  • Response kernel. KKK is a Markov kernel from Rd\mathbb{R}^dRd to R\mathbb{R}R, so K(x,⋅)K(x, \cdot)K(x,⋅) is a probability measure on R\mathbb{R}R for each xxx. PX⊗KP_X \otimes KPX​⊗K denotes the joint law on Rd×R\mathbb{R}^d \times \mathbb{R}Rd×R of a pair (X,Y)(X, Y)(X,Y) with X∼PXX \sim P_XX∼PX​ and Y∣X=x∼K(x,⋅)Y \mid X = x \sim K(x, \cdot)Y∣X=x∼K(x,⋅). P~X⊗K\tilde P_X \otimes KP~X​⊗K is defined the same way.
  • Data. Z1,…,Zn+1:Ω→Rd×RZ_1, \dots, Z_{n+1} : \Omega \to \mathbb{R}^d \times \mathbb{R}Z1​,…,Zn+1​:Ω→Rd×R are random variables with Zi=(Xi,Yi)Z_i = (X_i, Y_i)Zi​=(Xi​,Yi​).
  • Weight function. w:Rd→Rw : \mathbb{R}^d \to \mathbb{R}w:Rd→R.
  • Score function. SSS assigns a real number S(z,M)S(z, M)S(z,M) to a data point zzz and a finite multiset MMM of data points.
  • Level. α\alphaα is a real number.

The hypotheses are:

  1. each ZiZ_iZi​ is measurable, and Z1,…,Zn+1Z_1, \dots, Z_{n+1}Z1​,…,Zn+1​ are mutually independent under PPP;
  2. for every i≤ni \le ni≤n, the law of ZiZ_iZi​ is PX⊗KP_X \otimes KPX​⊗K;
  3. the law of Zn+1Z_{n+1}Zn+1​ is P~X⊗K\tilde P_X \otimes KP~X​⊗K;
  4. P~X\tilde P_XP~X​ is absolutely continuous with respect to PXP_XPX​;
  5. www is measurable and w(x)≥0w(x) \ge 0w(x)≥0 for all xxx;
  6. w(x)=dP~XdPX(x)w(x) = \dfrac{d\tilde P_X}{dP_X}(x)w(x)=dPX​dP~X​​(x) (the Radon–Nikodym derivative) for PXP_XPX​-almost every xxx;
  7. for each index i∈{1,…,n+1}i \in \{1, \dots, n+1\}i∈{1,…,n+1}, the map (z1,…,zn+1)↦S(zi,{zj:j≠i})(z_1, \dots, z_{n+1}) \mapsto S\big(z_i, \{z_j : j \ne i\}\big)(z1​,…,zn+1​)↦S(zi​,{zj​:j=i}) is measurable on (Rd×R)n+1(\mathbb{R}^d \times \mathbb{R})^{n+1}(Rd×R)n+1, where {zj:j≠i}\{z_j : j \ne i\}{zj​:j=i} is the multiset of the other nnn points;
  8. 0<α<10 < \alpha < 10<α<1.

The conclusion is

P({ω:Yn+1(ω)∈C^(Xn+1(ω))})  ≥  1−α.P\big(\{\omega : Y_{n+1}(\omega) \in \hat C(X_{n+1}(\omega))\}\big) \;\ge\; 1 - \alpha .P({ω:Yn+1​(ω)∈C^(Xn+1​(ω))})≥1−α.

Measurability of this event is not assumed. If it is not measurable, PPP of it means outer measure.

The band C^(x)\hat C(x)C^(x) is built from the training points Z1,…,ZnZ_1, \dots, Z_nZ1​,…,Zn​ (evaluated at ω\omegaω) and a test covariate xxx, as follows.

Scores. For a candidate y∈Ry \in \mathbb{R}y∈R, form the n+1n+1n+1 points z1=Z1,…,zn=Znz_1 = Z_1, \dots, z_n = Z_nz1​=Z1​,…,zn​=Zn​ and zn+1=(x,y)z_{n+1} = (x, y)zn+1​=(x,y). Their scores are

Vi(x,y)=S(zi,{zj:j≠i}),i=1,…,n+1.V_i^{(x,y)} = S\big(z_i, \{z_j : j \ne i\}\big), \qquad i = 1, \dots, n+1.Vi(x,y)​=S(zi​,{zj​:j=i}),i=1,…,n+1.

Weights. With X1,…,XnX_1, \dots, X_nX1​,…,Xn​ the training covariates, set

pi(x)=w(Xi)∑j=1nw(Xj)+w(x)(i≤n),pn+1(x)=w(x)∑j=1nw(Xj)+w(x).p_i(x) = \frac{w(X_i)}{\sum_{j=1}^n w(X_j) + w(x)} \quad (i \le n), \qquad p_{n+1}(x) = \frac{w(x)}{\sum_{j=1}^n w(X_j) + w(x)}.pi​(x)=∑j=1n​w(Xj​)+w(x)w(Xi​)​(i≤n),pn+1​(x)=∑j=1n​w(Xj​)+w(x)w(x)​.

Division by zero yields 000. So if the denominator is 000, all weights are 000.

Weighted distribution. On the extended real line [−∞,+∞][-\infty, +\infty][−∞,+∞], form the measure

F=∑i=1npi(x) δVi(x,y)+pn+1(x) δ+∞.F = \sum_{i=1}^{n} p_i(x)\, \delta_{V_i^{(x,y)}} + p_{n+1}(x)\, \delta_{+\infty}.F=i=1∑n​pi​(x)δVi(x,y)​​+pn+1​(x)δ+∞​.

Quantile. For a level β\betaβ,

Quantile(β;F)=inf⁡{t∈[−∞,+∞]:max⁡(β,0)≤F([−∞,t])},\mathrm{Quantile}(\beta; F) = \inf\{ t \in [-\infty, +\infty] : \max(\beta, 0) \le F([-\infty, t]) \},Quantile(β;F)=inf{t∈[−∞,+∞]:max(β,0)≤F([−∞,t])},

where the infimum is taken in the extended reals and the infimum of the empty set is +∞+\infty+∞.

Band. Then

C^(x)={y∈R:Vn+1(x,y)≤Quantile(1−α;F)}.\hat C(x) = \Big\{ y \in \mathbb{R} : V_{n+1}^{(x,y)} \le \mathrm{Quantile}\big(1 - \alpha; F\big) \Big\}.C^(x)={y∈R:Vn+1(x,y)​≤Quantile(1−α;F)}.

Degenerate cases.

  • All weights vanish. If ∑jw(Xj)+w(x)=0\sum_{j} w(X_j) + w(x) = 0∑j​w(Xj​)+w(x)=0, then FFF is the zero measure. Since 1−α>01 - \alpha > 01−α>0, the defining set is empty, the quantile is +∞+\infty+∞, and C^(x)=R\hat C(x) = \mathbb{R}C^(x)=R.
  • No training points (n=0n = 0n=0). In this case F=δ+∞F = \delta_{+\infty}F=δ+∞​ if w(x)>0w(x) > 0w(x)>0 and F=0F = 0F=0 otherwise. Either way the quantile is +∞+\infty+∞ and C^(x)=R\hat C(x) = \mathbb{R}C^(x)=R.
  • Quantile at +∞+\infty+∞ in general. Whenever the quantile equals +∞+\infty+∞, every yyy belongs to the band.
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me