Definition
Given an input vector . The linear regression model:
Setting
In a machine learning, we often subsume the by using a full one column in the design matrix (Zhang et al., 2024):
with
Intuition
The linear model either assumes that the regression function is linear or the linear model is a reasonable approximation (Hastie et al., 2009).
The variables can come from different sources:
- quantitative inputs;
- transformations, e.g. polynomial representation;
- numeric / “dummy” coding (e.g. one-hot) of the categories of qualitative inputs;
- interactions between variables, e.g. . No matter the source of the , the model is linear in the parameters.
Estimating the coefficients
Given a training dataset
- : The th observed value of .
- : The th observed value of (simplified to just 1 feature, e.g. only).
- : The space of possible responses
- Rergression: .
- Classification: A finite set of classes. Goal: Find
- : Loss function, e.g. For OLS: .
The Ordinary least squares (OLS) method
Assume i.i.d observations , we have the residual sum of squared as our loss function:
The goal is to find the coefficients that minimizes the loss function:
Analytical solution
Consider the machine learning setting above. Then, we can write the residual sum of squared as
This is a quadratic function in the parameters. Differentiating w.r.t. , we obtain:
Assuming that has full column rank, and hence is positive definite. Set the first derivative to zero
to obtain the unique solution:
The non-full-rank case: It might happen that the columns of are linearly dependent, e.g. two of the inputs might be perfectly correlated (). Then is singular are not uniquely defined //TODO
However, the fitted values are still the projection of onto the column space of but there are more than one way to express that projection in terms of the column vectors of .
The non-full-rank case occurs most often when one or more qualitative inputs are coded in a redundant fashion Resolve the non-unique representation, by recoding and/or dropping redundant columns in (Hastie et al., 2009).
Gradient descent
//TODO
Prediction
The predicted values at an input vector are given by:
- : Augmented vector.
The fitted values (optimal point estimator) at all the training inputs are:
- .
- : The “hat” matrix (because it puts the hat on ), the projection matrix.
Inference
//TODO