| # Linear regression via least-squares Linear regression is based on the idea of fitting a linear function through data points. In its basic form, the problem is as follows. we are given data , , where is the ‘‘input’’ and is the ‘‘output’’ for the -th measurement. We seek to find a linear function such that are collectively close to the corresponding values . In least-squares regression, the way we evaluate how well a candidate function fits the data is via the (squared) Euclidean norm: Since a linear function has the form for some , the problem of minimizing the above criterion takes the form We can formulate this as a least-squares problem: where The linear regression approach can be extended to multiple dimensions, that is, to problems where the output in the above problem contains more than one dimension (see here). It can also be extended to the problem of fitting non-linear curves.
| In this example we seek to analyze how customers react to an increase in the price of a given item. We are given two-dimensional data points , . The 's contain the prices of the item, and the 's the average number of customers who buy the item at that price. The generic equation of a non-vertical line is , where contains the decision variables. The quality of the fit of a generic line is measured via the sum of the squares of the error in the component (blue dotted lines). Thus, the best least-squares fit is obtained via the least-squares problem Once the line is found, it can be used to predict the value of the average number of customers buying the item () for a new price (). The prediction is shown in red.
See also: Auto-regressive models for time series prediction. The problem of Gauss.