We want to find a line/curve that minimizes the sum of the square of the error caused due to deviation.

Least squares

The least squares for is for which,

for all

We can use the normal equation to solve for

Normal Equation

Manipulating this we can get this,

Proof

Proof

How to solve

Method 1

  1. Construct QR Factorization
  2. Solve

Method 2

  1. Solve the normal equation for .

Method 3

  1. Use Mean Deviation

Line

Say we want to find a line that is the best fit for the following points:

x-2-1112
y-2-1122

We can create a list of linear equations using this:

We can turn this in to a matrix equation like so,

Compute QR,

Now compute , Finally solve ,

So we get

Curves

We can use this method to fit data to a curve using the function,

Lets take an example, Say we want to modal:

x-1001
y2106

Using

Now we can use one of the methods to solve for