Bayesian Regression¶
In the Bayesian approach to statistical inference, we treat our parameters as random variables and assign them a prior distribution. This forces our estimates to reconcile our existing beliefs about these parameters with new information given by the data. This approach can be applied to linear regression by assigning the regression coefficients a prior distribution.
We also may wish to perform Bayesian regression not because of a prior belief about the coefficients but in order to minimize model complexity. By assigning the parameters a prior distribution with mean 0, we force the posterior estimates to be closer to 0 than they would otherwise. This is a form of regularization similar to the Ridge and Lasso methods discussed in the previous section.
The Bayesian Structure¶
To demonstrate Bayesian regression, we’ll follow three typical steps to Bayesian analysis: writing the likelihood, writing the prior density, and using Bayes’ Rule to get the posterior density. In the results below, we use the posterior density to calculate the maximum-a-posteriori (MAP)—the equivalent of calculating the \(\hat{\bbeta}\) estimates in ordinary linear regression.
1. The Likelihood¶
As in the typical regression set-up, let’s assume
We can write the collection of observations jointly as
where \(\by \in \mathbb{R}^N\) and \(\bSigma = \sigma^2 I_N \in \mathbb{R}^{N \times N}\) for some known scalar \(\sigma^2\). Note that \(\by\) is a vector of random variables—it is not capitalized in order to distinguish it from a matrix.
Note
See this lecture for an example of Bayesian regression without the assumption of known variance.
We can then get our likelihood and log-likelihood using the Multivariate Normal.
2. The Prior¶
Now, let’s assign \(\bbeta\) a prior distribution. We typically assume
where \(\bbeta \in \mathbb{R}^D\) and \(\bT = \tau I_D \in \mathbb{R}^{D \times D}\) for some scalar \(\tau\). We choose \(\tau\) (and therefore \(\bT\)) ourselves, with a greater \(\tau\) giving less weight to the prior.
The prior density is given by
3. The Posterior¶
We are then interested in a posterior density of \(\bbeta\) given the data, \(\bX\) and \(\by\).
Bayes’ rule tells us that the posterior density of the coefficients is proportional to the likelihood of the data times the prior density of the coefficients. Using the two previous results, we have
where \(k\) is some constant that we don’t care about.
Results¶
Intuition¶
Often in the Bayesian setting it is infeasible to obtain the entire posterior distribution. Instead, one typically looks at the maximum-a-posteriori (MAP), the value of the parameters that maximize the posterior density. In our case, the MAP is the \(\bbetahat\) that maximizes
This is equivalent to finding the \(\bbetahat\) that minimizes the following loss function, where \(\lambda = 1/\tau\).
Notice that this is extremely close to the Ridge loss function discussed in the previous section—it is not quite equal to the Ridge loss function since it also penalizes the magnitude of the intercept, though this difference could be eliminated by changing the prior distribution of the intercept.
This shows that Bayesian regression with a mean-zero Normal prior distribution is essentially equivalent to Ridge regression. Decreasing \(\tau\), just like increasing \(\lambda\), increases the amount of regularization.
Full Results¶
Now let’s actually derive the MAP by calculating the gradient of the log posterior density.
Math Note
For a symmetric matrix \(\mathbf{W}\),
This implies that
Using the Math Note above, we have
We calculate the MAP by setting this gradient equal to 0: