> For the complete documentation index, see [llms.txt](https://ee16a.gitbook.io/studee16a/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ee16a.gitbook.io/studee16a/linear-algebra/least-squares.md).

# Least Squares

## What and why?

Sometimes, we receive erroneous or distorted data. This makes it impossible to find a function that goes through every single point. Consequently, we have to roughly estimate what the values should be by estimating a function that minimizes the squared distance between our function and the actual data.

![Least squares curve](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Linear_least_squares_example2.svg/220px-Linear_least_squares_example2.svg.png)

In this figure, there is no line that goes through all the data points. Consequently, we use least squares to create the best "estimate" for these points.
