In this post, I look at a Bayesian treatment of the linear regression problem. Making use of basis functions allows you to model non-linear patterns in data, however taking this route usually requires that you regularize your solution. To find the best regularization parameter often requires cross validation, but by looking at a framework known as Evidence Approximation, this allows us to reformulate regression optimization into a form where we can analytically find the most likely value for the regularization parameter. What results is a lightweight algorithm that requires no parameter-tuning.
(Note: This post is based on my collection of reading notes from Section 3.5 of Chris Bishop’s book “Pattern Recognition and Machine Learning”. I highly recommend this text, and encourage you to look at this source for derivations and deeper insights.)
We start with a linear regression problem which has the form,
where is a vector of basis function values. Using linear basis functions is powerful, as it lets you model non-linear relationships in your data. Unfortunately, selecting the best basis functions is an art and often times you need to take a “kitchen sink” approach and throw in as many basis functions as possible.
As soon as you do this though you run into overfitting problems as well as numerical problems as your design matrix can become ill-conditioned. The solution to this, of course, is to add a regularization penalty on , and the common practice is to use cross validation to find the right value of .
It turns out that by taking a Bayesian look at the linear regression problem, we can derive a solution for the value of the regularization parameter that does not require cross validation, rather it’s easily estimated from your training data. Let’s dig into this:
We start with a generative model that measures the likelihood of your observations ,
Where the probability density functions on the right are both Gaussian, is the design matrix of basis functions evaluated at your input points , and and are precision parameters for their respective distributions. Note that the last distribution on the r.h.s. is a prior on the distribution of weights with zero mean and precision .
Our goal is to find the most likely value for and given the training data, this requires that we integrate out . Hence, we have,
As we’ll see shortly, this solution leads to an optimally regularized linear regression solution.
We can re-write Equation 1 as,
where , N is the number of training points and M is the number of basis functions.
Here is where the connection to regularized linear regression comes out. Notice that is the same the regularized least squares problem where the regularization parameter . Also note that optimization of the log-likelihood of (1) w.r.t reduces to the optimization of .
Our goal at this point is to find the most likely and within . This gives us an implicit value for the regularization parameter, at which point we are free to estimate the most likely value for using the least squares solution. There are a few methods for doing this, for example, EM or trying to find a direct solution. In this post we look at the direct solution. You can follow the derivation in Section 3.5 of Bishop’s text. The solutions for and are,
where where the ‘s are the eigenvalues of the matrix , , and .
These solutions are implicit, but we can estimate and by plugging in initial estimates and iterating over the recurrence relations until convergence.
Testing it out…
I wrote a Matlab script implementing the solution (You can download the code below). Again, the nice thing about this solution is that all you need to provide is the training data and your design matrix and an optimally “regularized” solution just pops out.
I tested this method out on the classic “Series G” data set of Box and Jenkins which represents airline passenger totals from 1949 to 1960. The dataset is displayed as the solid blue curve in the image above. Noticing the obviously periodic trends I created a design matrix that contained sinusoids with various periods and offsets. Specifically I added sinusoids for between .25 and 10 in steps of .25 and between 0 and in steps of . Also, noticing the general uptrend in the data I added a single linear function to the design matrix.
The results are satisfying. The method is able to find the correct weights for and , such that it picks up the periodic uptrend, all without needing to resort to cross validation to tune parameters.
- Download a Matlab implementation of the code.