Leakage.lean
Lean 4 source, lean/DataMiningAsObservation/Leakage.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Leakage.lean. Chapter 8 section 8.1, leakage by identifier.
The glossary's second kind of leakage is an identifier that lets the model recognize a row it
will be tested on. The consumer that looks its answer up by identifier reproduces every
training label exactly, whatever the labels are, so on a test set whose identifiers were seen
in training its error is zero for every labeling, including one drawn independently of the
features. A score of zero on such a test set therefore measures recall of the labels and
not generalization. That is the statement checked here.
-/
import Mathlib
namespace DMO.Leakage
open Finset
variable {ι : Type*} [DecidableEq ι]
/-- The lookup consumer, which answers a training row by its stored label and any other row
by a default. -/
def lookup (train : Finset ι) (y : ι → Bool) (d : Bool) (i : ι) : Bool :=
if i ∈ train then y i else d
/-- The error count of a consumer against the labels on a test set. -/
def errors (test : Finset ι) (f y : ι → Bool) : ℕ := (test.filter fun i => f i ≠ y i).card
/-- **Leakage by identifier.** If every test identifier was seen in training, the lookup
consumer has zero test error for every labeling. -/
theorem errors_lookup_eq_zero (train test : Finset ι) (y : ι → Bool) (d : Bool)
(hleak : test ⊆ train) : errors test (lookup train y d) y = 0 := by
unfold errors lookup
rw [Finset.card_eq_zero, Finset.filter_eq_empty_iff]
intro i hi
simp [hleak hi]
/-- Without the overlap the lookup consumer knows nothing. On a test row outside the training
set it returns the default, whatever the label. -/
theorem lookup_default (train : Finset ι) (y : ι → Bool) (d : Bool) (i : ι) (hi : i ∉ train) :
lookup train y d i = d := by
simp [lookup, hi]
end DMO.Leakage