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
Using QR Factorization
Proof
How to solve
Method 1
- Construct QR Factorization
- Solve
Method 2
- Solve the normal equation for .
Method 3
Line
Say we want to find a line that is the best fit for the following points:
x | -2 | -1 | 1 | 1 | 2 |
---|---|---|---|---|---|
y | -2 | -1 | 1 | 2 | 2 |
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 | -1 | 0 | 0 | 1 |
---|---|---|---|---|
y | 2 | 1 | 0 | 6 |
Using
Now we can use one of the methods to solve for