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 (y_i,x_i), i=1,ldots,m, where x_i in mathbf{R}^n is the ‘‘input’’ and y_i in mathbf{R} is the ‘‘output’’ for the i-th measurement. We seek to find a linear function f : mathbf{R}^n rightarrow mathbf{R} such that f(x_i) are collectively close to the corresponding values y_i.

In least-squares regression, the way we evaluate how well a candidate function f fits the data is via the (squared) Euclidean norm:

 sum_{i=1}^m (y_i - f(x_i))^2.

Since a linear function f has the form f(x) = theta^Tx for some theta in mathbf{R}^n, the problem of minimizing the above criterion takes the form

 min_theta : sum_{i=1}^m (y_i - x_i^Ttheta)^2.

We can formulate this as a least-squares problem:

 min_theta : |Atheta - y|_2,

where

 A = left( begin{array}{c} x_1^T  vdots  x_m^T end{array} right).

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.

alt text 

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 (x_i,y_i), i=1,ldots,m. The x_i's contain the prices of the item, and the y_i's the average number of customers who buy the item at that price.

The generic equation of a non-vertical line is y = theta_1 x+theta_2, where theta=(theta_1,theta_2) 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 y (blue dotted lines). Thus, the best least-squares fit is obtained via the least-squares problem

 min_theta : sum_{i=1}^m (theta_1 x_i+theta_2 - y_i)^2 .

Once the line is found, it can be used to predict the value of the average number of customers buying the item (y) for a new price (x). The prediction is shown in red.

See also: