Documentation

Hypothesis.Regression

Linear regression #

over ℝ or ℂ

noncomputable def K₁ {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
Equations
Instances For
    theorem hxK₁ {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
    theorem h1K₁ {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
    (WithLp.toLp 2 fun (x : Fin n) => 1) K₁ x
    theorem topsub₁ {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
    def Kvec₁ {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
    Fin (Nat.succ 0).succ(K₁ x)
    Equations
    Instances For
      noncomputable def regression_coordinates₁ {n : } {R : Type u_1} [RCLike R] (x y : Fin nR) (lin_indep : LinearIndependent R (Kvec₁ x)) :
      Fin 2R

      Given points (x i, y i), obtain the coordinates [c, d] such that y = c x + d is the best fit regression line.

      Equations
      Instances For
        def A {m : } {R : Type u_1} [RCLike R] (x : Fin mR) :
        Matrix (Fin m) (Fin 2) R
        Equations
        Instances For
          noncomputable def getCoeffs {m : } {R : Type u_1} [RCLike R] (x y : Fin mR) :
          Matrix (Fin 2) (Fin 1) R
          Equations
          Instances For
            def theDistance {m : } {R : Type u_1} [RCLike R] (x y : Fin mR) (M : Matrix (Fin 2) (Fin 1) R) :
            R

            getCoeffs is supposed to mimize this

            Equations
            Instances For
              theorem getCoeffs_minimizes_theDistance {m : } {R : Type u_1} [RCLike R] [LE R] (x y : Fin mR) (M : Matrix (Fin 2) (Fin 1) R) (a b : R) :

              getCoeffs minimizes theDistance.

              theorem matrix_smul {m : } {R : Type u_1} [RCLike R] (b : Matrix (Fin m) (Fin 1) R) (v : Matrix (Fin 2) (Fin 2) R) (c : R) (o : Matrix (Fin m) (Fin 2) R) (i : Matrix (Fin 2) (Fin m) R) :
              o * (c v * i * b) = c (o * (v * i * b))
              theorem getx {m : } {R : Type u_1} [RCLike R] (x : Fin mR) (c : R) (e : Matrix (Fin 2) (Fin 1) R) :
              ((c e) 0 0 x + (c e) 1 0 fun (x : Fin m) => 1) = fun (i : Fin m) => (c (A x).mulᵣ e) i 0
              theorem getDet {n : } {R : Type u_1} [RCLike R] (x : Fin nR) :
              !![i : Fin n, x i ^ 2, i : Fin n, x i; i : Fin n, x i, n]⁻¹ = ((∑ i : Fin n, x i ^ 2) * n - (∑ i : Fin n, x i) ^ 2)⁻¹ !![n, -i : Fin n, x i; -i : Fin n, x i, i : Fin n, x i ^ 2]
              theorem matmulcase {m : } {R : Type u_1} [RCLike R] (x : Fin mR) :
              Matrix.mulᵣ ![x, fun (x : Fin m) => 1] (Matrix.transpose ![x, fun (x : Fin m) => 1]) = !![i : Fin m, x i ^ 2, i : Fin m, x i; i : Fin m, x i, m]
              theorem matrix_proj_in_subspace {m : } {R : Type u_1} [RCLike R] (x : Fin mR) (Y : Matrix (Fin m) (Fin 1) R) :
              (WithLp.toLp 2 fun (i : Fin m) => (A x).mulᵣ ((((A x).transpose.mulᵣ (A x))⁻¹.mulᵣ (A x).transpose).mulᵣ Y) i 0) K₁ x
              theorem matrix_algebra {n t o w : } {R : Type u_1} [RCLike R] (B : Matrix (Fin n) (Fin t) R) (hB : IsUnit (B.transpose * B).det) (m : Fin tFin oR) (P : Matrix (Fin n) (Fin w) R) :
              theorem star_projection_is_matrix_product {m : } {R : Type u_1} [RCLike R] [TrivialStar R] {x : Fin mR} (y : Fin mR) (hB : IsUnit ((A x).transpose * A x).det) :
              (fun (i : Fin m) => (A x).mulᵣ ((((A x).transpose.mulᵣ (A x))⁻¹.mulᵣ (A x).transpose).mulᵣ fun (j : Fin m) (x : Fin 1) => y j) i 0) = ((K₁ x).starProjection (WithLp.toLp 2 y)).ofLp

              This does not hold over ℂ.

              theorem getCoeffs_eq_regression_coordinates₁ {m : } (x y : Fin m) (i : Fin 2) (hl : LinearIndependent (Kvec₁ x)) (hB : IsUnit ((A x).transpose * A x).det) :
              noncomputable def hat {m : } (x y : Fin m) (h : LinearIndependent (Kvec₁ x)) :
              Fin m

              The coordinates "y hat" or y^.

              Equations
              Instances For
                noncomputable def bar {m : } (y : Fin m) :

                The value "y bar".

                Equations
                Instances For
                  def nonconstant {m : } (x : Fin m) :
                  Equations
                  Instances For
                    theorem isunit_of_nonconstant {m : } (x : Fin m) (hx : (∑ i : Fin m, x i ^ 2) * m - (∑ i : Fin m, x i) ^ 2 0) :
                    theorem sum_of_constant' {m : } (x : Fin m) (h : nonconstant x) :
                    f : Fin 2Fin m with f 0 f 1, (x (f 0) - x (f 1)) ^ 2 0
                    theorem Finset.sum_iUnion {k : } {T : Type u_1} [Fintype T] (A : Fin kFinset T) (X : T) (h : univ.toSet.PairwiseDisjoint A) :
                    i : T with i ⋃ (j : Fin k), (A j), X i = j : Fin k, i : T with i A j, X i

                    A "missing lemma" in Mathlib?

                    theorem decompose_pair_sum {n : } (f : Fin n) :
                    x : Fin 2Fin n, f (x 0) = i : Fin n, g : Fin 2Fin n with g 0 = i, f (g 0)
                    theorem diagonalSq {m : } (x : Fin m) (x_1 : Fin m) :
                    x_2 : Fin 2Fin m with x_2 1 = x_1, x (x_2 0) ^ 2 = i : Fin m, x i ^ 2
                    theorem sum_ij_xi2 {m : } (x : Fin m) :
                    σ : Fin 2Fin m, x (σ 0) ^ 2 = m * σ : Fin 2Fin m with σ 0 = σ 1, x (σ 0) * x (σ 1)
                    theorem offDiagonalSq {m : } (x : Fin m) :
                    f : Fin 2Fin m with f 0 f 1, x (f 1) ^ 2 = (m - 1) * i : Fin m, x i ^ 2
                    theorem determinant_value_nonzero_of_nonconstant {m : } (x : Fin m) (h : nonconstant x) :
                    (∑ i : Fin m, x i ^ 2) * m - (∑ i : Fin m, x i) ^ 2 0
                    theorem average_predicted_value {m : } (x y : Fin m) (h : nonconstant x) :
                    i : Fin m, y i = i : Fin m, hat x y i
                    def A₃ (x : Fin 3) :
                    Matrix (Fin 3) (Fin 2)
                    Equations
                    • A₃ x = !![x 0, 1; x 1, 1; x 2, 1]
                    Instances For
                      noncomputable def getCoeffs₃ (x y : Fin 3) :
                      Matrix (Fin 2) (Fin 1)
                      Equations
                      Instances For
                        theorem getx₃ (x : Fin 3) (c : ) (e : Matrix (Fin 2) (Fin 1) ) :
                        ((c e) 0 0 x + (c e) 1 0 fun (x : Fin 3) => 1) = fun (i : Fin 3) => (c (!![x 0, 1; x 1, 1; x 2, 1] * e)) i 0
                        theorem getDet₃ (x₀ x₁ x₂ : ) :
                        !![x₀ ^ 2 + x₁ ^ 2 + x₂ ^ 2, x₀ + x₁ + x₂; x₀ + x₁ + x₂, 3]⁻¹ = (2 * (x₀ ^ 2 + x₁ ^ 2 + x₂ ^ 2 - x₀ * x₁ - x₀ * x₂ - x₁ * x₂))⁻¹ !![3, -(x₀ + x₁ + x₂); -(x₀ + x₁ + x₂), x₀ ^ 2 + x₁ ^ 2 + x₂ ^ 2]
                        theorem matrix_proj_in_subspace₃ (x : Fin 3) (Y : Matrix (Fin 3) (Fin 1) ) :
                        (WithLp.toLp 2 fun (i : Fin 3) => (A₃ x).mulᵣ ((((A₃ x).transpose.mulᵣ (A₃ x))⁻¹.mulᵣ (A₃ x).transpose).mulᵣ Y) i 0) K₁ x
                        theorem star_projection_is_matrix_product₃ {x : Fin 3} (y : Fin 3) (hB : IsUnit (!![x 0, 1; x 1, 1; x 2, 1].transpose * !![x 0, 1; x 1, 1; x 2, 1]).det) :
                        (fun (i : Fin 3) => (A₃ x).mulᵣ ((((A₃ x).transpose.mulᵣ (A₃ x))⁻¹.mulᵣ (A₃ x).transpose).mulᵣ !![y 0; y 1; y 2]) i 0) = ((K₁ x).starProjection (WithLp.toLp 2 y)).ofLp
                        theorem getCoeffs₃_eq_regression_coordinates₁ (x y : Fin 3) (i : Fin 2) (hl : LinearIndependent (Kvec₁ x)) (hB : IsUnit (!![x 0, 1; x 1, 1; x 2, 1].transpose * !![x 0, 1; x 1, 1; x 2, 1]).det) :
                        noncomputable def K₂ {n : } (x₀ x₁ : Fin n) :

                        Multivariate regression.

                        Equations
                        Instances For
                          theorem hxK₂₀ {n : } (x₀ x₁ : Fin n) :
                          WithLp.toLp 2 x₀ K₂ x₀ x₁
                          theorem hxK₂₁ {n : } (x₀ x₁ : Fin n) :
                          WithLp.toLp 2 x₁ K₂ x₀ x₁
                          theorem h1K₂ {n : } (x₀ x₁ : Fin n) :
                          (WithLp.toLp 2 fun (x : Fin n) => 1) K₂ x₀ x₁
                          theorem topsub₂ {n : } (x₀ x₁ : Fin n) :
                          def Kvec₂ {n : } (x₀ x₁ : Fin n) :
                          Fin (Nat.succ 0).succ.succ(K₂ x₀ x₁)
                          Equations
                          Instances For
                            noncomputable def regression_coordinates₂ {n : } (x₀ x₁ y : Fin n) (lin_indep : LinearIndependent (Kvec₂ x₀ x₁)) :
                            Fin 3
                            Equations
                            Instances For
                              theorem hvo₀₁₁ (w : EuclideanSpace (Fin 3)) (hw : w K₁ ![0, 1, 2]) :
                              inner (![0, 1, 1] - ![1 / 6, 4 / 6, 7 / 6]) w = 0