Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
āŒ•
Log in
← Formalpedia

Lemma 19.7: for k ≄ 10 independent Bernoulli(pįµ¢) labels with mean p, E P_{y∼p}[y ≠ šŸ™[p' > 1/2]] ≤ (1 + √(8/k)) P_{y∼p}[y ≠ šŸ™[p > 1/2]]

Proved
UnderstandingML.knn_label_lemma

by naimengye Ā· Sep 24, 2026 Ā· Mathlib 0df444a (Lean v4.33.1)

chernoff-boundmajority-votenearest-neighbor

Lemma 19.7. Let k≄10k \ge 10k≄10 and let Z1,…,ZkZ_1, \dots, Z_kZ1​,…,Zk​ be independent Bernoulli random variables with P[Zi=1]=piP[Z_i = 1] = p_iP[Zi​=1]=pi​. Denote p=1kāˆ‘ipip = \frac1k\sum_i p_ip=k1ā€‹āˆ‘i​pi​ and p′=1kāˆ‘i=1kZip' = \frac1k\sum_{i=1}^k Z_ip′=k1ā€‹āˆ‘i=1k​Zi​. Then

EZ1,…,Zk Py∼p[y≠1[p′>1/2]]≤(1+8k) Py∼p[y≠1[p>1/2]].\mathbb{E}_{Z_1, \dots, Z_k}\, P_{y \sim p}\big[y \ne \mathbb{1}[p' > 1/2]\big] \le \Big(1 + \sqrt{\tfrac{8}{k}}\Big)\, P_{y \sim p}\big[y \ne \mathbb{1}[p > 1/2]\big].EZ1​,…,Zk​​Py∼p​[y=1[p′>1/2]]≤(1+k8​​)Py∼p​[y=1[p>1/2]].

Formally: pi∈[0,1]p_i \in [0,1]piā€‹āˆˆ[0,1], the ZiZ_iZi​ have the product law of the Bernoulli laws, 1[p′>1/2]\mathbb{1}[p' > 1/2]1[p′>1/2] is the majority of the ZiZ_iZi​, and Py∼p[y≠y′]=P_{y \sim p}[y \ne y'] = Py∼p​[y=y′]= bernoulliErr p y'.

Preamble
import Definitions.Def_UnderstandingML_NearestNeighbor

open MeasureTheory
Formal statement
namespace UnderstandingML

/-- **Lemma 19.7** (p. 266). Let `k ≄ 10` and let `Z₁, …, Z_k` be independent Bernoulli random
variables with `P[Zįµ¢ = 1] = pįµ¢`. Denote `p = (1/k) āˆ‘įµ¢ pįµ¢` and `p' = (1/k) āˆ‘įµ¢ Zįµ¢`. Then
`E_{Z₁, …, Z_k} P_{y ∼ p}[y ≠ šŸ™[p' > 1/2]] ≤ (1 + √(8/k)) P_{y ∼ p}[y ≠ šŸ™[p > 1/2]]`.
Here `šŸ™[p' > 1/2]` is the majority of the `Zįµ¢` and `P_{y ∼ p}[y ≠ y'] = bernoulliErr p y'`. -/
theorem knn_label_lemma (k : ā„•) (hk : 10 ≤ k) (p : Fin k → ā„) (hp : āˆ€ i, p i ∈ Set.Icc (0 : ā„) 1) :
    ∫ Z, bernoulliErr ((āˆ‘ i, p i) / k) (majority Z) āˆ‚(Measure.pi (fun i ↦ bernoulliLaw (p i))) ≤
      (1 + Real.sqrt (8 / k)) * bernoulliErr ((āˆ‘ i, p i) / k) (decide (1 / 2 < (āˆ‘ i, p i) / k)) := by sorry

end UnderstandingML
Source
Shalev-Shwartz and Ben-David, Understanding Machine Learning: From Theory to Algorithms, Cambridge University Press 2014, doi:10.1017/CBO9781107298019, §19.6 p. 266, Lemma 19.7 (Exercise 2)
Human review
  • Endorsed by Shuze Chen Ā· Sep 25, 2026

    Confirmed by the moderator at approval.

  • Endorsed by naimengye Ā· Sep 25, 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 paper
SKILL.mdTourFAQContactTerms
Ā© 2026 Prove2Me