Linear models for regression

The goal of regression is to predict the value of one or more continuous targets variables given the value of a D-dimensional vector of input variables.

By linear models we mean that the model is a linear function of the adjustable parameters. E.g. the polynomial curve fitting algorith builds a linear model. The simplest form of linear regression models are also linear functions of the input variables.

We get a more useful class of functions by taking linear combinations of a fixed set of nonlinear functions of the input variables, known as basis functions. Such models are linear functions of the parameters (which gives simple analytical properties) and yet can be nonlinear with respect to the input variables.

Given a dataset of observations where , together with the corresponding target values , the goal is to predict for a new value of .

  • Simple approach: Find an appropiate function
  • General approach: Find the predictive distribution to get the uncertainty of a prediction

Linear Basis Function Models

The simplest linear model involves a linear combination of the input variables, also called linear regression:

This is:

  • A linear function of the parameters (good for optimization)
  • A linear function of the inputs (bad for expressiveness)

Extend the concept of linear combination to combine fixed nonlinear functions of the input:

where are known as basis functions. By having components, the total number of parameters is (consider the bias).

If we consider , then we can write:

These linear models are:

  • A linear function of the parameters (good for optimization)
  • A nonlinear function of the inputs (good for expressiveness)

Polynomials are basis functions of the form . The problem with polynomial is that they are global functions: a change in a region of the input space affects all the other regions.

Other choices for the basis functions are:

Which is the Gaussian basis function. In this case, is the location in the input space, and is the scale. This function doesn't have a probabilistic interpretation.

Another possibility is the Sigmoidal basis function:

Where is the logistic function, but we can also use the tanh function.

We can use also Fourier basis functions such that the the regression function is an expansion of sinusoidal functions at a certain frequency. Combining basis functions localized in both space and frequency leads to a class of functions known as wavelets.

Maximum likelihood and least squares

Let be a deterministic function such that , let be a random Gaussian variable with precision . We assume that the target variable is given by:

The conditional distribution of will then be

For a new value , the optimal prediction of is given by the conditional mean:

For a dataset , let , assuming that is given by a linear model , then the likelihood of the target variables is given by:

The log-likelihood is:

Where is the sum-of-squares error function:

We now estimate the parameters by maximum likelihood. The gradient w.r.t. to is:

By setting the gradient to 0 and solving for we find:

which are known as the normal equations for the least squares problem. Here is a NxM matrix called design matrix whose elements are given by .

The quantity

Is known as Moore-Penrose pseudo-inverse of the matrix , which is a generalization of the inverse for nonsquare matrices.

If we solve for the bias parameter , the solution suggests that the bias compensates for the difference between the averages (over the training set) of the target values and the weighted sum of the averages of the basis function values.

Maximizing for the precision parameter we get:

which is basically the precision of the residuals.

Geometric interpretation of least square solution

Consider an N-dimensional space. Let be a vector in that space, where the N components are the ground truth target variables for all the N observations we are trying to predict.

Build a vector made of the target variables of our dataset made of N observation. This vector lives in a N-dimensional space.

The input variable is D-dimensional, while we use the basis functions that are M-dimensional. Consider each component of the basis function evaluated on all the N observations of our dataset, we have vectors in the N-dimensional space which span a subregion S of dimension .

The target value is predicted by combining the basis function output using some weights , and therefore the N-dimensional vectore made of the predicted target value for each observation in the dataset is indeed a linear combination of the vectors, and resides inside the subregion .

The book demonstrates how the solution from the least square problem corresponds to the orthogonal projection of to the closest M-dimensional subregion S.

Sequential Least Squares

Authors suggest to use gradient descent to get the least square solution sequentially (one observation at the time). Given the sum-of-squares loss, the update of the weights is

Regularized least squares

Adding a regularization term to the loss function helps avoiding overfitting to the data. The most famous regularization term for least squares is weight decay, where the optimization process is forced to produce small weights unless supported by the data. The general form of weight decay is: For we have the classic quadratic regularizer. For we have the Lasso regularizer which has the property (for sufficiently large) of driving some of the weights to zero, leading to a sparse model. This is useful to avoid overfitting when we have a small dataset, even if the problem becomes to find the suitable .

Multiple outputs

Given a regression problem with a multivariate output, the book demonstrates how the solution decouples between the different target variables (they all share the same pseudo-inverse matrix assuming that the target variables are distributed by an isotropic gaussian). Most of the time, we can work with a single variable and easily generalize to the multivariate case.

Bias-variance decomposition

Suppose we want to find a function that approximates the target value on the input . We model the relation between the input and the target value as We assume that has random noise, so it's a random variable distributed by We want to find . Let be a loss function that measures the prediction error, then the average loss is: If the loss is the MSE, then we have:

is the expected value of , which is now considered a random variable since we assume it contains random noise. The conditioning on reflects the fact that the Gaussian distribution is centered at , which depends on .

  • The first term depends on and can be reduced to zero with an unlimited amount of data.
  • The second term depends on the noise in the data, so it can't be changed by acting on , so it is the minimum achievable value of expected loss.

Now let's consider K different datasets drawn indipendently from the same distribution . We estimate a different function for each dataset, since they all contain random noise. We can define as Now consider the square loss and add and subtract the term If we take the expectation of this term w.r.t. the dataset , then we have: The expected squared difference between the model predictions and the observed data can be expressed as the sum of two terms, the bias squared and the variance.

  • The squared bias term represents to which extent the average prediction over all datasets differs from the desired function
  • The variance term measures the extent to which the solutions for individual datasets vary around their average (sensitiveness to the choice of dataset)

If we apply this observation to the expected loss value shown before, we have the following decomposition: Where

Mathematically: recall the decomposition of the loss in two terms, we took the first term and further decomposed it into squared variance + variance. The expectation we took is w.r.t. the datasets, but we need to calculate it against the input .

In practice, bias-variance decomposition can be estimated numerically by replacing the expectation with averages on the observed data. The method requires to have multiple datasets, but that means that all the datasets can be merged in a single big dataset that will produce less overfitted models. Bias-variance decomposition isn't the best way to validate our models, but it's useful to understand how overfitting works.

Bayesian Linear Regression

We introduce a Bayesian treatment for linear regression, which will avoid over-fitting and will lead to automatic methods of determining model complexity using training data alone.

Parameter distribution

The likelihood function is the exponential of a quadratic function of the parameters (as defined previously) Where are all the target values in the dataset and is the noise precision. Therefore, the conjugate prior over is given by a Gaussian distribution of the form: Where are the mean and covariance.

The posterior is a Gaussian distribution (we are using a conjugate prior) proportional to the likelihood and the prior. We calculate the normalization coefficient using the result from 2.116 (from PRML). Where Since the posterior is a Gaussian, its mode coincides with its mean, thus the maximum posterior weight vector is simply given by .

The Bayesian approach is automatically regularized. Assume the prior to be a zero-mean isotropic Gaussian governed by a single parameter The parameters of the posterior distribution will then be given by: The log of the posterior distribution is given by: The maximization of the posterior is equivalent to the minimization of the sum of squares with the addition of a quadratic regularization term with .

Predictive distribution

Once we have the posterior distribution over the weights , how do we estimate the target value for a new point ? We use the predictive distribution. Where we recall that: The solution to this integral is explained in (2.115). We have where the variance Because the noise process and the distribution of are independent, the variances are additive. For , the second term goes to zero, and the variance of the predictive distr. is only given by noise in the data.

The more data we have, the narrower is the predictive distribution, in fact it can be shown that (Qazaz et al., 1997).

Equivalent kernel

To perform inference using the predictive distribution, we return the mean value, which can be written in the form: The mean of the predictive distribution is a linear combination of the target variables from the training set: Where is called smoother matrix or equivalent kernel. Regression functions that make inference by taking linear combination of the training target values are called linear smoothers. Such kernels have a localization property that increase the response if and are closer.

An alternative approach of linear regression is to directly compute an equivalent kernel instead of working with the basis functions. This leads to the Gaussian processes.

Some properties of the kernels are that (1) the weights sum to one and (2) the function can be expressed as an inner product where is a non linear function.

Bayesian Model Comparison

Suppose we want to compare models , where a model represents a different probability distribution over the observed data . The uncertainty of the model is expressed by a prior distribution (we can assume to be uniform). Given the dataset , we want to evaluate the posterior distribution:

is called model evidence or marginal likelihood, since it can be viewed as a likelihood function over the space of models, in which the parameters have been marginalized out.

The ratio of model evidences is called Bayes factor.

Given the posterior , the predictive distribution is given by the sum and product rule:

This is an example of a mixture distribution, obtained by averaging the predictive distributions of individual models weighted by the posterior probabilities of those models.

An approximation of model averaging is to use the most probable model alone to make predictions. This is called model selection.

Now we focus on the model evidence / marginal likelihood. For a model governed by parameters , the evidence is:

  1. The evidence can be viewed as the probability of generating from by randomly sampling .
  2. The evidence appears as the normalization coefficient in the posterior

Bayesian model complexity. The evidence is useful to evaluate the complexity of the model. Let's approximate the integral above by (i) assuming the posterior is peaked at most probable with a width of , and the prior is flat with width . In this case, the integral can be approximated by: If we take the logs: If the model complexity increases, then increases because it better fits the data, but decreases, because becomes smaller and the ratio approaches 0. In general, the Bayesian approach favours the best trade-off between accuracy and complexity.