Bayesian Regression
Recap
Bayes’ Rule
Bayes’ Rule (assuming
):
The prior
:
Belief about
before seeing
.
The likelihood
:
If A true, how probable is the observed evidence
.
The marginal likelihood
:
Total probability of observing
across all scenarios. Acts as normalisation constant.
The posterior
:
Updated belief about
after seeing
.
The PDF version:
where
is the normalising constant.
The point is that in Bayesian inference and regression, we will use the
form
ignoring the normalisation constant.
Unnormalised density
functions
A PDF is defined as:
is the normalising constant. If two functions
and
differ by only a constant, i.e.
,
then they define the exact same PDF.
is often intractable to compute, hence we can just write
and work with the unnormalised form
.
Example
The full PDF of a 1D Gaussian
is
Expanding the square in the exponent:
We dropped terms not involving
.
Hence if we observe this quadratic form in the exponent, we know it’s
Gaussian.
Frequentist vs Bayesian
Frequentist approach treats Parameters like
as fixed, unknown constants, wuth no distributions.
MLE is frequentist approach. It finds the parameter that makes the
observed data most probable.
Example
A factory produces products labeled 100g. The actual weight
follows a Gaussian distribution with known variance 1, but unknown mean
.
Three products are sampled with weights 99g, 110g, 107g. What is the
best estimate of
?
Given variance = 1 and the independent samples, the likelihood is
The joint likelihood of all observations is (by independence):
Taking the log-likelihood:
Maximising this is equivalent to minimising
:
MLE says that the sample mean is the best estimate for
.
However, this approach says nothing about our confidence in this
estimate. Also, we cannot incorporate any prior knowledge we may
have.
Bayesian approach treats parameters as random variables with its own
distribution. We can encode our prior beliefs about
and then update those beliefs.
Treating each observation as Gaussian around
,
the likelihood is:
Our prior Gaussian belief about
before seeing data:
Here
is our prior best guess for
,
and
is our uncertainty about that guess.
Applying Bayes’ Rule,
This is the posterior, i.e. the update belief about
after
observations.
The posterior is also Gaussian. Its parameters are
The posterior mean can be rewritten as
where
is the MLE estimate. Note that this is just the weighted average of the
MLE estimate and the prior mean. The weights depend on the relative
uncertainty.
If
is large, there is more weight on
.
If
is large, more weight on
.
As
,
.
The posterior variance
as
.
Compared to MLE, where
always.
Regression
Recall that Least Squares Method (LSM) finds a linear function of
that best predicts
,
given
data points, each consisting of input
and output
.
Organising the inputs and outputs:
We want a weight vector
such that
.
LSM finds
by minimising the total squared error:
By differentiating and setting to zero, we get
where
and assuming it is invertible. This is the normal equation, the
closed-form solution to least squares.
If we use MLE by supposing the true relationship between
and
is linear and corrupted by Gaussian noise,
where
is the true unknown weight vector.
The output
is Gaussian:
By MLE we will also get
The implication is that LSM has the same limitation as MLE. It just
gives a single estimate without the uncertainty about the prediction. It
also doesn’t incorporate prior beliefs. This leads into Bayesian Linear
Regression which address these gaps.
Bayesian Linear
Regression
1-D case
Applying Bayesian inference to the regression setting. Start with 1-D
inputs,
and
.
Likelihood: Each output is Gaussian around
:
Prior: Treat
as a random variable with a Gaussian prior:
The prior is centered at 0, encoding a belief that weights are
small.
The posterior: By Bayes’ Rule,
The result is that the posterior is Gaussian with
Comparing with ridge regression which solves
,
giving:
Note that they are identical with
.
So the Gaussion prior
is mathematically equivalent to
regularisation.
Large
(noisy data): Large
,
pulls
towards 0.
Small
(strong prior): large
.
Large
,
dominates,
negligible, prior fades away.
represents the remaining uncertainty about
after the observations. It shrinks as
increases.
Also, as
(no prior conviction),
and
.
Hence LSM is just a special case of Bayesian regression with an
infintely weak prior.
Derivation
collects the
coefficients from both the prior and likelihood:
Since a Gaussian has the form
,
by matching
and reading off
,
-dimension
case
For
dimensions, scalars just become vectors and scalars.
The likelihood and prior become:
The posterior is a multivariate Gaussian.
The variance
becomes a covariance matrix
:
Again, as
,
dominates and
.
The uncertainty drops with more data.
Predictive Distribution
So far Bayesian Linear Regression gives the posterior distribution
over weights
.
But we want to make predictions for new inputs.
Given a new input
,
we want to know the distribution of its output
.
This is the predictive distribution
(probability of
given all the training data).
Here
is a distribution, so every plausible value of
gives a different prediction for
.
We need to average over all of them, weighted by how probable each
is:
This is also called marginalising out
.
Since both
and
are Gaussian, the result is Gaussian and can be computed as:
Predictive mean
:
This is simply the posterior mean weights applied to the new input - the
same as what LSM would give using
.
The best single prediction is unchanged.
Predictive variance
:
is the irreducible noise. Even if we knew
exactly, there is inherent randomness in the data generating process
.
is the model uncertainty. This reflects our uncertainty about
itself, projected onto the new input
.
It depends on where
sits relative to the training data. If
is far from any training point,
is large in that direction and this term is large.
Basis Functions
can be replaced by basis functions
.
First transform the raw input:
Then the model is still linear in
but can still capture nonlinear relationships in the original
.