ChanceLevel.lean
Lean 4 source, lean/DataMiningAsObservation/ChanceLevel.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
ChanceLevel.lean. Chapter 0 section 0.8, chance level.
Chance level is the value a rank statistic reaches under a ranking that carries no
information. A constant score ties every pair, so its AUROC as equation 0.16 defines it is
one half whenever both classes are present, its Kendall correlation with any other score is
zero, and its reliability weight is zero. These are the baselines the book's gates subtract.
-/
import Mathlib
import DataMiningAsObservation.MonotoneInvariance
import DataMiningAsObservation.Kendall
import DataMiningAsObservation.ReliabilityWeight
namespace DMO.ChanceLevel
open Finset DMO.MonotoneInvariance
variable {ι : Type*} [Fintype ι] [DecidableEq ι]
omit [Fintype ι] [DecidableEq ι] in
/-- A constant score ties every pair, and each pair contributes one half. -/
theorem aurocNum_const (pos neg : Finset ι) (c : ℝ) :
aurocNum pos neg (fun _ => c) = pos.card * neg.card / 2 := by
unfold aurocNum
simp [Finset.sum_const, nsmul_eq_mul]
ring
omit [Fintype ι] [DecidableEq ι] in
/-- **A constant score has AUROC one half** when both classes are present. -/
theorem auroc_const (pos neg : Finset ι) (hp : pos.Nonempty) (hn : neg.Nonempty) (c : ℝ) :
auroc pos neg (fun _ => c) = 1 / 2 := by
unfold auroc
rw [aurocNum_const]
have : (0 : ℝ) < pos.card * neg.card := by
have := hp.card_pos; have := hn.card_pos; positivity
field_simp
omit [Fintype ι] [DecidableEq ι] in
/-- **A constant score has reliability weight zero.** -/
theorem weight_const (pos neg : Finset ι) (hp : pos.Nonempty) (hn : neg.Nonempty) (c : ℝ) :
DMO.ReliabilityWeight.weight pos neg (fun _ => c) = 0 :=
DMO.ReliabilityWeight.weight_eq_zero_of_le_half pos neg _ (by rw [auroc_const pos neg hp hn])
/-- **A constant score has Kendall correlation zero** with any other score, since it forms no
concordant and no discordant pair. -/
theorem tau_const (t : ι → ℝ) (c : ℝ) : DMO.Kendall.tau (fun _ => c) t = 0 := by
unfold DMO.Kendall.tau
have h1 : (DMO.Kendall.pairs.filter (DMO.Kendall.concordant (fun _ => c) t)) = ∅ := by
rw [Finset.filter_eq_empty_iff]
intro p _ h
unfold DMO.Kendall.concordant at h
rcases h with ⟨h, _⟩ | ⟨h, _⟩ <;> exact lt_irrefl _ h
have h2 : (DMO.Kendall.pairs.filter (DMO.Kendall.discordant (fun _ => c) t)) = ∅ := by
rw [Finset.filter_eq_empty_iff]
intro p _ h
unfold DMO.Kendall.discordant at h
rcases h with ⟨h, _⟩ | ⟨h, _⟩ <;> exact lt_irrefl _ h
rw [h1, h2]
simp
end DMO.ChanceLevel