Lift.lean

Lean 4 source, lean/DataMiningAsObservation/Lift.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Lift.lean. Equations 5.1 and 5.2, lift.

Lift is confidence over the consequent's support, the joint support over the product of the
two supports. It is one under independence, symmetric in the two itemsets, and bounded by
the reciprocal of the consequent's support, so a rare consequent lets a single co-occurrence
reach a lift equal to the number of transactions. That is the sense in which lift fails at
low support, and why chapter 5 sends pattern evaluation to chapter 8.
-/
import Mathlib

namespace DMO.Lift

/-- **Equation 5.2.** The lift of the rule from supports `sx`, `sy`, and joint support `sxy`. -/
noncomputable def lift (sx sy sxy : ℝ) : ℝ := sxy / (sx * sy)

/-- **Independence gives lift one.** -/
theorem lift_indep (sx sy : ℝ) (hx : 0 < sx) (hy : 0 < sy) : lift sx sy (sx * sy) = 1 := by
  unfold lift
  exact div_self (by positivity)

/-- **Lift is symmetric** in the two itemsets. -/
theorem lift_symm (sx sy sxy : ℝ) : lift sx sy sxy = lift sy sx sxy := by
  unfold lift
  rw [mul_comm]

/-- **Lift is bounded by the reciprocal of the consequent's support**, since the joint support
is at most the antecedent's. -/
theorem lift_le_inv (sx sy sxy : ℝ) (hx : 0 < sx) (hy : 0 < sy) (h : sxy ≤ sx) :
    lift sx sy sxy ≤ 1 / sy := by
  unfold lift
  rw [div_le_div_iff₀ (by positivity) hy]
  nlinarith

/-- **Lift fails at low support.** One transaction of `N` containing both items, and neither
elsewhere, gives lift `N`. -/
theorem lift_single (N : ℕ) (hN : 0 < N) : lift (1 / N) (1 / N) (1 / N) = N := by
  unfold lift
  have : (N : ℝ) ≠ 0 := by exact_mod_cast hN.ne'
  field_simp

end DMO.Lift