Conceptualization¶
Generally, we are given some datapoint pairs . We suppose there is a function with parameters , such that . If is linear in all the parameters (e.g. polynomials or RBFs), then we can just feed in , pairs and construct a lienar system,
where each row of the system is determined by .
NB: The function does not have to be linear in x! It is the parameters which we are solving for here.
If is square, i.e. the number of parameters equals the number of pairs then this system can be solved exactly and we call this interpolation. Geometrically, this means our fit will pass through all of the data points.
Linear regression / linear least squares¶
In the general case, is not square, e.g. we have more data points than parameters, and we want to find the best fit for ; i.e. the parameters that minimizes
The set of residuals is the vector and our goal is to minimize . This is called linear regression / linear least squares, and we already know how to do this generally through the pseudoinverse,
Recall that the pseudoinverse recovers the exact inverse for square matricies (an exact fit is the best fit by definition!)
Foreshadowing nonlinear least squares¶
In general, curve fitting is an optimization problem since can be nonlinear in (e.g. ). This is nonlinear least squares which is an optimization problem and will be covered later. Technically, nonlinear least squares is the true generalization which includes linear regression and our methods will also be applicable. However, linear regression is common and robust enough that it is maintained as a separate tool.