The least-squares line uses a straight line
to approximate the given set of data, , , ..., , where . The best fitting curve has the least square error, i.e.,
Please note that and are unknown coefficients while all and are given. To obtain the least square error, the unknown coefficients and must yield zero first derivatives.
Expanding the above equations, we have:
The unknown coefficients and can therefore be obtained:
where stands for .