Documentation

CslibFrontier.MachineLearning.LossMinimization.Squared

The squared loss and ridge regression #

The squared loss of a linear predictor w on a point x with label y is (⟪w, x⟫ - y)² / 2 [ShalevShwartzBenDavid2014, (13.3)]. It is convex and nonnegative in w, and its derivative (⟪w, x⟫ - y) ⟪x, ·⟫ is ‖x‖²-Lipschitz [ShalevShwartzBenDavid2014, Example 12.6]. Ridge regression, Tikhonov regularized minimization of the empirical squared risk over all of E [ShalevShwartzBenDavid2014, Section 13.1.1], therefore inherits the oracle inequality of Cslib.MachineLearning.IsRLM for smooth losses.

Examples z are described by a feature map φ : Z → E and real labels y : Z → ℝ, with ‖φ z‖ ≤ 1 and |y z| ≤ 1 as in the source.

Main definitions #

Main results #

References #

noncomputable def Cslib.MachineLearning.squaredLoss {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (w x : E) (y : ℝ) :

The squared loss (⟪w, x⟫ - y)² / 2 of the linear predictor w on the point x with label y [ShalevShwartzBenDavid2014, (13.3)].

The squared loss is convex in the predictor.

theorem Cslib.MachineLearning.hasFDerivAt_squaredLoss {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (w x : E) (y : ℝ) :
HasFDerivAt (fun (w : E) => squaredLoss w x y) ((inner ℝ w x - y) • (innerSL ℝ) x) w

The derivative of the squared loss at w is (⟪w, x⟫ - y) ⟪x, ·⟫.

theorem Cslib.MachineLearning.fderiv_squaredLoss {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (w x : E) (y : ℝ) :
fderiv ℝ (fun (w : E) => squaredLoss w x y) w = (inner ℝ w x - y) • (innerSL ℝ) x

The derivative of the squared loss is ‖x‖²-Lipschitz, so the squared loss is ‖x‖²-smooth [ShalevShwartzBenDavid2014, Example 12.6].

With ‖x‖ ≤ 1, the derivative of the squared loss is 1-Lipschitz.

theorem Cslib.MachineLearning.IsRLM.integral_trueRisk_squaredLoss_le_add {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {Z : Type u_2} [MeasurableSpace Z] {φ : Z → E} {y : Z → ℝ} (hφ : ∀ (z : Z), ‖φ z‖ ≤ 1) (hy : ∀ (z : Z), |y z| ≤ 1) {ε B : ℝ} (hε : 0 < ε) (hε1 : ε < 1) (hB : 0 < B) {m : ℕ} (hm : 150 * B ^ 2 / ε ^ 2 ≤ ↑m) {r : ℝ} (hr : r = ε / (3 * B ^ 2)) {A : (Fin m → Z) → E} (hA : IsRLM (fun (w : E) (z : Z) => squaredLoss w (φ z) (y z)) (fun (w : E) => r * ‖w‖ ^ 2) Set.univ A) (D : MeasureTheory.Measure Z) [MeasureTheory.IsProbabilityMeasure D] (hint : MeasureTheory.Integrable (fun (p : (Fin m → Z) × Z) => squaredLoss (A p.1) (φ p.2) (y p.2)) ((MeasureTheory.Measure.pi fun (x : Fin m) => D).prod D)) (hint' : ∀ (i : Fin m), MeasureTheory.Integrable (fun (S : Fin m → Z) => squaredLoss (A S) (φ (S i)) (y (S i))) (MeasureTheory.Measure.pi fun (x : Fin m) => D)) {w : E} (hwB : ‖w‖ ≤ B) (hwint : MeasureTheory.Integrable (fun (z : Z) => squaredLoss w (φ z) (y z)) D) :
(∫ (S : Fin m → Z), trueRisk (fun (w : E) (z : Z) => squaredLoss w (φ z) (y z)) D (A S) ∂MeasureTheory.Measure.pi fun (x : Fin m) => D) ≤ trueRisk (fun (w : E) (z : Z) => squaredLoss w (φ z) (y z)) D w + ε

Learnability by ridge regression [ShalevShwartzBenDavid2014, Theorem 13.1]: let A be a ridge regression rule, a minimizer of the empirical squared risk plus r‖w‖² over all of E. If every example z has feature vector ‖φ z‖ ≤ 1 and label |y z| ≤ 1, then for ε ∈ (0, 1), B > 0, r = ε / (3 B²), m ≥ 150 B² / ε² i.i.d. examples from D and every w with ‖w‖ ≤ B, 𝔼_S [L_D(A S)] ≤ L_D(w) + ε, where L_D is the true squared risk.

The integrability hypotheses are those of Cslib.MachineLearning.integral_trueRisk_sub_empiricalRisk; they hold automatically when Z is finite with measurable singletons.