What is it?
The least squares method is a mathematical method used in Statistics and Machine Learning to find the best-fitting line of a set of data. It’s a method widely used for Linear Regression and other regressive statistical models, to find the relation between variables and estimating outcomes.
The objective is to find a best-fitting line based on the deviation from all measured data points, and the deviation itself is measured with the squared error .
Applying the Least Squares method
We can use Linear Algebra concepts on collected data to find the best-fitting line. Given a set of data, we can map the line function to the known data of , and then we would discover the coefficients:
X | Y |
---|---|
1 | 2 |
2 | 3 |
3 | 2 |
4 | 4 |
Because it’s a overdetermined system, with more equations than unknown variables, we solve . Calculating and , we can write the equivalent system:
Which then, we can solve using the Gauss-Jordan Elimination Method to conclude that . Replacing the value of in the original function, we can discover the best-fitting line of , which would result in the following graph: