From Least Squares to Bayesian Linear Regression: A Glance at Bayesian Machine Learning

StableSlopmachine-learning
Last reviewed31 min read

Suppose we observe a handful of points and want to predict the target at an input we have not seen. Drawing a curve through the observations is easy; deciding what that curve means is harder. Why should we prefer one curve over another? How much should we trust its prediction? If several curves explain the data nearly equally well, what happens to the alternatives we did not choose?

We will approach these questions through polynomial curve fitting, following the example in Bishop’s Pattern Recognition and Machine Learning [Bishop, 2006]. We begin with least squares, which selects parameters by minimizing an error. We will then reinterpret the same model probabilistically, introduce uncertainty over its parameters, and arrive at Bayesian linear regression.

The mathematics will become richer, but the model will change very little. When the same curve-fitting problem is viewed from several angles, we can see exactly what each new assumption buys us.

Important

You do not need to memorize every symbol as it appears. The notation table is there when a symbol has slipped your mind.

1. One curve from least squares

Let

D={(xn,yn)}n=1N,xn,ynR\mathcal D=\{(x_n,y_n)\}_{n=1}^{N}, \qquad x_n,y_n\in\mathbb R

be a dataset of NN input-target pairs. Our immediate task is to construct a function that predicts the target corresponding to a new input xx^\star.

For now, the inputs x1,,xNx_1,\ldots,x_N are treated as fixed. We are not claiming that inputs are never random; we are choosing to condition on the values we observed. This fixed-design viewpoint lets us focus on uncertainty in the targets and, later, in the model parameters without worrying about the inputs.

1.1 A model that is linear in its parameters

Assume first that an MMth-degree polynomial is flexible enough to represent the pattern of our dataset:

f(x,w)=w0+w1x++wMxM=j=0Mwjxj,f(x,\mathbf w) = w_0+w_1x+\cdots+w_Mx^M = \sum_{j=0}^{M}w_jx^j,

where:

w=(w0,w1,,wM)RM+1\mathbf w=(w_0,w_1,\ldots,w_M)^\top\in\mathbb R^{M+1}

is the parameter vector. When M>1M>1, the function is nonlinear in the input xx, but it is still linear in the parameters: each wjw_j appears only to the first power, multiplied by a known function of xx. It is this second kind of linearity that makes the model a linear regression model.

Polynomial notation is familiar, but it hides a useful general pattern. This is where linear algebra comes in. Let P=M+1P=M+1 and define the basis functions:

ϕj(x)=xj,j=0,1,,M.\phi_j(x)=x^j, \qquad j=0,1,\ldots,M.

Collecting them gives us the feature vector:

ϕ(x)=[ϕ0(x)ϕ1(x)ϕP1(x)]RP,\boldsymbol\phi(x) = \begin{bmatrix} \phi_0(x)\\ \phi_1(x)\\ \vdots\\ \phi_{P-1}(x) \end{bmatrix} \in\mathbb R^P,

so the polynomial can be written as a dot product:

f(x,w)=ϕ(x)w.\boxed{ f(x,\mathbf w)=\boldsymbol\phi(x)^\top\mathbf w }.

Nothing in this form requires monomials. We could replace the components of ϕ\boldsymbol\phi—the monomials 1,x,x2,1,x,x^2,\ldots in this case—with splines, Fourier functions, radial basis functions, or another fixed collection of features. Once ϕ\boldsymbol\phi has been chosen, the model remains linear in w\mathbf w. The feature map determines which shapes the model can express; the parameters determine which of those shapes it selects [Rasmussen et al., 2006].

1.2 Seeing all observations at once

Evaluating the feature vector at every training input produces the design matrix:

Φ=[ϕ(x1)ϕ(x2)ϕ(xN)]RN×P.\boldsymbol\Phi = \begin{bmatrix} \boldsymbol\phi(x_1)^\top\\ \boldsymbol\phi(x_2)^\top\\ \vdots\\ \boldsymbol\phi(x_N)^\top \end{bmatrix} \in\mathbb R^{N\times P}.

Similarly, collect the observed targets into:

y=[y1y2yN]RN.\mathbf y = \begin{bmatrix} y_1\\ y_2\\ \vdots\\ y_N \end{bmatrix} \in\mathbb R^N.

For any proposed parameter vector w\mathbf w, the product:

Φw=[f(x1,w)f(x2,w)f(xN,w)]\boldsymbol\Phi\mathbf w = \begin{bmatrix} f(x_1,\mathbf w)\\ f(x_2,\mathbf w)\\ \vdots\\ f(x_N,\mathbf w) \end{bmatrix}

contains the model’s predictions at all training inputs.

1.3 How to choose one best-fitting curve

We know that the model is a polynomial parameterized by w\mathbf w. The next question is: how do we choose the best-fitting curve for our data? We need a way to measure the discrepancy between the model predictions and the observed targets.

The larger the discrepancy, the worse the fit. We measure this discrepancy with a loss function, then seek the parameter vector w\mathbf w that minimizes it.

For a parameter vector w\mathbf w, we define the residual vector as:

r(w)=Φwy.\mathbf r(\mathbf w)=\boldsymbol\Phi\mathbf w-\mathbf y.

We define the loss function E(w)E(\mathbf w) as the sum of squared residualsThe factor 1/21/2 does not change which parameters minimize the objective; it merely cancels the factor 22 that appears when we differentiate a square.:

E(w)=12Φwy22.E(\mathbf w) = \frac12\lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2.

A least-squares estimate is any parameter vector satisfyingWe write \in rather than == because the minimizing parameter vector need not be unique. If the columns of Φ\boldsymbol\Phi are linearly dependent, different parameter vectors can produce identical predictions at every training input.:

w^LSarg minwRPE(w).\boxed{ \widehat{\mathbf w}_{\mathrm{LS}} \in \operatorname*{arg\,min}_{\mathbf w\in\mathbb R^P} E(\mathbf w) }.

1.4 Solving for the fitted curve

To find a least-squares estimate, differentiate the objective:

wE(w)=w[12(Φwy)(Φwy)]=Φ(Φwy).\begin{aligned} \nabla_{\mathbf w}E(\mathbf w) &= \nabla_{\mathbf w} \left[ \frac12 (\boldsymbol\Phi\mathbf w-\mathbf y)^\top (\boldsymbol\Phi\mathbf w-\mathbf y) \right]\\ &= \boldsymbol\Phi^\top (\boldsymbol\Phi\mathbf w-\mathbf y). \end{aligned}

Setting the gradient to zero gives the normal equations:

ΦΦw^LS=Φy.\boxed{ \boldsymbol\Phi^\top\boldsymbol\Phi \widehat{\mathbf w}_{\mathrm{LS}} = \boldsymbol\Phi^\top\mathbf y }.

The normal equations also have a geometric meaning. Rewrite them as

Φ(Φw^LSy)=0.\boldsymbol\Phi^\top (\boldsymbol\Phi\widehat{\mathbf w}_{\mathrm{LS}}-\mathbf y) =\mathbf 0.

Every attainable vector of fitted training values lies in the column space col(Φ)\operatorname{col}(\boldsymbol\Phi). The equation says that the fitted residual is orthogonal to every column of Φ\boldsymbol\Phi, and therefore to that entire model space. Thus Φw^LS\boldsymbol\Phi\widehat{\mathbf w}_{\mathrm{LS}} is the closest point in the model space to y\mathbf y.

The next figure shows the exact geometry when the observation space is two-dimensional and the model space is a line. Moving along the line changes both the residual length on the left and the squared loss on the right; the orthogonal projection and the bottom of the loss curve identify the same fit [Trefethen et al., 1997].

The closest prediction is the bottom of the loss

Drag the gold candidate in either view

Model direction
Observation-space projectionDragging the candidate prediction along the model line changes its residual. The least-squares fit is the perpendicular projection of the target onto that line.Observation spaceattainable predictions lie on col(Φ)model lineobserved yclosest ŷdrag predictionLeast-squares loss along the model lineThe squared residual forms a parabola as the candidate prediction moves along the model line. Its minimum corresponds to the orthogonal projection shown in observation space.Optimization viewloss E(a) along the model line012.424.7-4-2024minimumdrag acoefficient a → prediction a usquared loss E(a)
Candidate a1.77
Loss E(a)0.781
Best â2.87
Minimum0.176
Every point on the blue line is an attainable prediction. The closest one to the observed target has a perpendicular residual; the same point is the minimum of the quadratic loss on the right. Line style, labels, and the right-angle mark repeat the color encoding.

The Hessian is ΦΦ\boldsymbol\Phi^\top\boldsymbol\Phi, and for every vRP\mathbf v\in\mathbb R^P:

vΦΦv=Φv220.\mathbf v^\top \boldsymbol\Phi^\top\boldsymbol\Phi \mathbf v = \lVert\boldsymbol\Phi\mathbf v\rVert_2^2 \ge 0.

Therefore EE is convex, so every solution of the normal equations is a global minimizer. If Φ\boldsymbol\Phi has full column rank, the Hessian is positive definite, the minimizer is unique, and:

w^LS=(ΦΦ)1Φy.\boxed{ \widehat{\mathbf w}_{\mathrm{LS}} = (\boldsymbol\Phi^\top\boldsymbol\Phi)^{-1} \boldsymbol\Phi^\top\mathbf y }.

If Φ\boldsymbol\Phi is rank deficient, a minimizer still exists and the fitted training vector Φw^LS\boldsymbol\Phi\widehat{\mathbf w}_{\mathrm{LS}} is unique, but multiple parameter vectors can represent it. The inverse formula is then unavailableEven when the inverse exists, explicitly forming it is usually a poor numerical method. Practical least-squares solvers use QR or singular-value decompositions because the normal equations can worsen conditioning [Trefethen et al., 1997]..

At this stage, squared error is a choice, not a consequence. It says that positive and negative residuals of the same magnitude are equally costly, and that a residual twice as large contributes four times as much. Those properties may be reasonable, but least squares alone does not tell us why they should describe the data.

This leaves a more basic question: what would it mean for one parameter vector—or one curve—to be more plausible than another?

2. A bridge into the Bayesian world

Least squares gives us an optimization problem. Bayesian inference will give us a language for uncertainty. Before connecting the two, we need to distinguish three objects that are often collapsed in informal explanations: a discrepancy, a probability model for the observations, and uncertainty about the parameters themselves.

The distinction matters because a small training error does not imply that the fitted curve is known with certainty. With limited data, many curves may remain plausible even when an optimizer returns only one of them. Bayesian machine learning begins by refusing to silently discard those alternatives.

2.1 What becomes uncertain?

In least squares, w\mathbf w is an unknown but fixed parameter. We search through RP\mathbb R^P and retain a value that minimizes E(w)E(\mathbf w). The hat in w^LS\widehat{\mathbf w}_{\mathrm{LS}} reminds us that this value was estimated from data, but the estimate itself is still a single point.

Bayesian inference represents our uncertainty about w\mathbf w with a probability distribution. Imagine that the curve has one fixed but unknown parameter vector. Before seeing the data, many values of w\mathbf w may be plausible. After seeing the data, values that produce curves inconsistent with the observations become less plausible. The data change our distribution over w\mathbf w; they do not cause the parameter itself to move or be redrawn.

This is separate from noisy observations. Even if w\mathbf w were known exactly, repeated targets at the same input could still differ. Conversely, the observations could be almost noiseless while limited data leave several parameter values plausible. Bayesian prediction will eventually account for both sources, but they enter through different parts of the model.

2.2 Bayes’ theorem as an update rule

Let D\mathcal D denote the observed dataset and, for the moment, suppress the fixed training inputs from the notation. The product rule gives two ways to factor the same joint distribution:

p(w,D)=p(Dw)p(w)=p(wD)p(D).p(\mathbf w,\mathcal D) = p(\mathcal D\mid\mathbf w)p(\mathbf w) = p(\mathbf w\mid\mathcal D)p(\mathcal D).

Equating the two factorizations and dividing by p(D)p(\mathcal D) gives Bayes’ theorem:

p(wD)=p(Dw)p(w)p(D).\boxed{ p(\mathbf w\mid\mathcal D) = \frac{p(\mathcal D\mid\mathbf w)p(\mathbf w)}{p(\mathcal D)} }.

Each term has a different role:

  • The prior p(w)p(\mathbf w) describes our uncertainty about the parameters before using D\mathcal D.
  • The likelihood p(Dw)p(\mathcal D\mid\mathbf w) measures how compatible the observed data are with each proposed parameter value.
  • The posterior p(wD)p(\mathbf w\mid\mathcal D) describes our updated uncertainty after using the data.
  • The evidence p(D)p(\mathcal D) is the probability or density assigned to the observed data by the model as a whole.

For a continuous parameter vector wRP\mathbf w\in\mathbb R^P, the evidence is obtained by averaging the likelihood under the prior. This is also known as marginalization:

p(D)=RPp(Dw)p(w)dw.p(\mathcal D) = \int_{\mathbb R^P} p(\mathcal D\mid\mathbf w)p(\mathbf w) \,d\mathbf w.

Provided 0<p(D)<0<p(\mathcal D)<\infty, the evidence normalizes the numerator so that the posterior integrates to one. It does not depend on the particular value of w\mathbf w under consideration, so we can treat it as a constant with respect to w\mathbf w. We may therefore describe the shape of the posterior by writing:

p(wD)p(Dw)p(w).\boxed{ p(\mathbf w\mid\mathcal D) \propto p(\mathcal D\mid\mathbf w)p(\mathbf w) }.

2.3 What is the likelihood?

The expression p(Dw)p(\mathcal D\mid\mathbf w) can be read in two related ways. If w\mathbf w is fixed and possible datasets vary, it is a probability mass function or density over the data. Once D\mathcal D has been observed, we hold it fixed and view the same expression as a function of w\mathbf w:

L(w;D):=p(Dw).\mathcal L(\mathbf w;\mathcal D) := p(\mathcal D\mid\mathbf w).

This function is the likelihood. The semicolon is a reminder that w\mathbf w varies while the observed dataset is fixed.

Likelihood is not, by itself, a probability distribution over w\mathbf w. In general:

RPL(w;D)dw\int_{\mathbb R^P} \mathcal L(\mathbf w;\mathcal D) \,d\mathbf w

need not equal one. The likelihood can rank parameter values by how well they explain the same observations, but a prior and the evidence are needed to turn those relative weights into a posterior distribution.

This gives us the first connection to ordinary model fitting. Maximum-likelihood estimation (MLE) retains the parameter value at the peak of the likelihood:

w^MLarg maxwp(Dw).\boxed{ \widehat{\mathbf w}_{\mathrm{ML}} \in \operatorname*{arg\,max}_{\mathbf w} p(\mathcal D\mid\mathbf w) }.

It uses a probability model for the observations, but its output is still one parameter estimate.

2.4 From MLE to MAP and beyond

Once a prior has been specified, we could instead retain the parameter value at the peak of the posterior. This is the maximum a posteriori, or MAP, estimate:

w^MAParg maxwp(wD)=arg maxwp(Dw)p(w).\begin{aligned} \widehat{\mathbf w}_{\mathrm{MAP}} &\in \operatorname*{arg\,max}_{\mathbf w} p(\mathbf w\mid\mathcal D)\\ &= \operatorname*{arg\,max}_{\mathbf w} p(\mathcal D\mid\mathbf w)p(\mathbf w). \end{aligned}

The evidence disappears from the optimization because it is constant with respect to w\mathbf w. MAP does not maximize the likelihood and prior separately; it chooses the mode of their product.

If the prior density is constant over all parameter values relevant to the optimization, then it does not change their ranking. In that case:

w^MAP=w^ML\boxed{ \widehat{\mathbf w}_{\mathrm{MAP}} = \widehat{\mathbf w}_{\mathrm{ML}} }

whenever the corresponding optimizer is uniqueA proper uniform distribution over all of RP\mathbb R^P does not exist. A “flat prior” may instead mean a proper prior that is constant on a bounded admissible region, or an improper constant density used as a formal device. In the latter case, we must still check that the resulting posterior is proper..

But MAP is not the final destination of Bayesian inference. It uses the posterior and then collapses it back to one point. If two separated regions of parameter space are both plausible, their relative mass is lost once we report only the highest point.

Full Bayesian inference retains the posterior distribution. For prediction at a new input xx^\star, it averages the prediction associated with every possible parameter value, weighted by posterior plausibility:

p(yx,D)=RPp(yx,w)p(wD)dw.\boxed{ p(y^\star\mid x^\star,\mathcal D) = \int_{\mathbb R^P} p(y^\star\mid x^\star,\mathbf w) p(\mathbf w\mid\mathcal D) \,d\mathbf w }.

After integrating over w\mathbf w, the predictive distribution no longer conditions on one chosen parameter value. A sharply concentrated posterior may make this average resemble prediction with a single estimate. A broad or multimodal posterior can make the difference substantial.

Summary (Three procedures, three retained objects)
  • MLE uses the likelihood and retains one parameter estimate.
  • MAP uses the posterior and retains one parameter estimate.
  • Full Bayesian inference retains parameter uncertainty and averages over it when making predictions.

We now have the roadmap, but one part is still abstract: the likelihood. What probability model for the targets would make smaller squared residuals more plausible, and would recover our least-squares objective through maximum likelihood? Gaussian observation noise gives an exact answer.

3. Gaussian noise turns least squares into likelihood

Least squares began with a loss function. It compared the fitted curve with the targets we happened to observe, but it said nothing about which other targets we might have observed instead. A likelihood requires that missing piece: a probability model for the targets.

We are still one step short of Bayesian linear regression. In this section, probability enters through the observations, while w\mathbf w and the noise level remain fixed but unknown parameters. We will estimate them rather than place distributions over them.

3.1 A stochastic model for the targets

Keep the training inputs x1,,xNx_1,\ldots,x_N fixed. For each input, suppose the corresponding target can be approximated by our linear model, but life is not perfect: there is always some mismatch between the model and the target.

Yn=ϕ(xn)w+εn,Y_n = \boldsymbol\phi(x_n)^\top\mathbf w + \varepsilon_n,

This mismatch or error is represented by a random noise variable εn\varepsilon_n:

εni.i.d.N(0,β1),β>0.\varepsilon_n \overset{\mathrm{i.i.d.}}{\sim} \mathcal N(0,\beta^{-1}), \qquad \beta>0.

The parameter β\beta is called the noise precision. Precision is the reciprocal of variance, so a larger β\beta means that observations are more tightly concentrated around the curve We usually use μ\mu and σ2\sigma^2 for a “standard” notation when a random variable has a normal distribution. But here, we use β\beta, or the precision, instead. The goal is to make the derivation more convenient and also more consistent with Bayesian literature.:

Var(εn)=β1.\operatorname{Var}(\varepsilon_n)=\beta^{-1}.
Gaussian noise

The curve with a Gaussian noise model from Bishop [Bishop, 2006].

Equivalently, the conditional distribution of each target is:

Ynxn,w,βN ⁣(ϕ(xn)w,β1).\boxed{ Y_n\mid x_n,\mathbf w,\beta \sim \mathcal N\!\left( \boldsymbol\phi(x_n)^\top\mathbf w, \beta^{-1} \right) }.

The curve f(xn,w)f(x_n,\mathbf w) now has a probabilistic meaning: it is the conditional mean of the target.

E[Ynxn,w,β]=f(xn,w)=ϕ(xn)w.\mathbb E[Y_n\mid x_n,\mathbf w,\beta] = f(x_n,\mathbf w) = \boldsymbol\phi(x_n)^\top\mathbf w.

Zero-mean noise does not say that every observed residual r\mathbf r must be zero. It says that if we repeatedly generated a target at the same input while holding w\mathbf w and β\beta fixed, the residuals would average to zero under the model.

Collect the random targets into Y=(Y1,,YN)\mathbf Y=(Y_1,\ldots,Y_N)^\top. The NN scalar assumptions can then be written as one multivariate Gaussian:

YΦ,w,βN ⁣(Φw,β1IN).\boxed{ \mathbf Y\mid\boldsymbol\Phi,\mathbf w,\beta \sim \mathcal N\!\left( \boldsymbol\Phi\mathbf w, \beta^{-1}\mathbf I_N \right) }.

The covariance matrix β1IN\beta^{-1}\mathbf I_N records two assumptions: every target has the same conditional variance, and the observation errors are independent once the inputs and parameters are fixedThe targets themselves are not identically distributed when their inputs give different means. The centered errors εn\varepsilon_n are i.i.d..

Caveat (Gaussian noise is an assumption).The Gaussian model is not forced upon us by least squares. It can be a poor description of outliers, asymmetric errors, bounded targets, counts, or noise whose variance changes with the input. Different observation models produce different likelihoods and usually different losses.

3.2 From the observation model to a likelihood

We have observed the numerical target vector y\mathbf y. Because the targets are conditionally independent, their joint density is the product of the individual Gaussian densities:

p(yΦ,w,β)=n=1Np(ynxn,w,β)=n=1NN ⁣(ynϕ(xn)w,β1).\begin{aligned} p(\mathbf y\mid\boldsymbol\Phi,\mathbf w,\beta) &= \prod_{n=1}^{N} p(y_n\mid x_n,\mathbf w,\beta)\\ &= \prod_{n=1}^{N} \mathcal N\!\left( y_n\mid \boldsymbol\phi(x_n)^\top\mathbf w, \beta^{-1} \right). \end{aligned}

Holding y\mathbf y and Φ\boldsymbol\Phi fixed while varying w\mathbf w and β\beta turns this density into the likelihood:

L(w,β;y,Φ):=p(yΦ,w,β).\mathcal L(\mathbf w,\beta;\mathbf y,\boldsymbol\Phi) := p(\mathbf y\mid\boldsymbol\Phi,\mathbf w,\beta).

Substituting the Gaussian density gives:

L(w,β)=(β2π)N/2exp ⁣{β2Φwy22},\mathcal L(\mathbf w,\beta) = \left(\frac{\beta}{2\pi}\right)^{N/2} \exp\!\left\{ -\frac{\beta}{2} \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 \right\},

where the observed quantities have been suppressed from the notation. The residual norm from least squares has reappeared, now inside a probability density.

Products of many densities are inconvenient to manipulate and can become numerically tiny. Since the logarithm is strictly increasing, maximizing the likelihood is equivalent to maximizing the log-likelihood:

(w,β):=logL(w,β)=N2logβN2log(2π)β2Φwy22.\begin{aligned} \ell(\mathbf w,\beta) &:= \log\mathcal L(\mathbf w,\beta)\\ &= \frac N2\log\beta -\frac N2\log(2\pi) -\frac\beta2 \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2. \end{aligned}

Using the least-squares loss E(w)E(\mathbf w), the same expression becomes:

(w,β)=N2logβN2log(2π)βE(w).\boxed{ \ell(\mathbf w,\beta) = \frac N2\log\beta -\frac N2\log(2\pi) -\beta E(\mathbf w) }.

Drag one residual through probability and loss

The negative logarithm reverses the ranking without moving the optimum

Probability viewGaussian density p(r | β)most probabledrag rOptimization viewloss −log p(r | β)smallest lossdrag r
Residual r+1.00
Density0.242
Negative log-likelihood1.419
Noise σ1.00
Drag the gold residual in either plot. Moving away from zero lowers its Gaussian density and raises its negative log-likelihood, so the density peak and loss minimum identify the same fit. Greater precision narrows the density and steepens the penalty: the model becomes less forgiving of the same residual.

This identity is the bridge back to our original optimization problem. The figure isolates one residual, but conditional independence makes the dataset log-likelihood a sum of terms with the same shape [Bishop, 2006] [Murphy, 2022].

3.3 Maximum likelihood recovers least squares

Fix any noise precision β>0\beta>0. The first two terms of (w,β)\ell(\mathbf w,\beta) do not depend on w\mathbf w, and the coefficient of E(w)E(\mathbf w) is strictly negative. Therefore:

arg maxw(w,β)=arg maxw[βE(w)]=arg minwE(w).\begin{aligned} \operatorname*{arg\,max}_{\mathbf w} \ell(\mathbf w,\beta) &= \operatorname*{arg\,max}_{\mathbf w} \bigl[-\beta E(\mathbf w)\bigr]\\ &= \operatorname*{arg\,min}_{\mathbf w} E(\mathbf w). \end{aligned}

The maximizing set is the same for every fixed β>0\beta>0. Consequently, whenever a finite joint maximum over (w,β)(\mathbf w,\beta) exists, its w\mathbf w component is a least-squares estimate. Conversely, any least-squares estimate maximizes the likelihood over w\mathbf w when β\beta is fixed:

w^MLarg minw12Φwy22.\boxed{ \widehat{\mathbf w}_{\mathrm{ML}} \in \operatorname*{arg\,min}_{\mathbf w} \frac12 \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 }.

We can now answer why squared error appeared: under independent Gaussian observation noise with constant variance, the negative log-likelihood differs from a positive multiple of squared error only by terms that do not depend on w\mathbf w [Bishop, 2006].

This is an equivalence between two optimization problems under stated assumptions. It does not prove that Gaussian noise is correct for a particular dataset. Rather, it tells us exactly which probability model makes least squares a maximum-likelihood procedure.

The least-squares solution from Section 1 is therefore also the maximum-likelihood solution for w\mathbf w under this observation model. The curve has not changed; only our interpretation of its objective has.

3.4 Estimating the noise precision

The parameter vector determines the center of the Gaussian observation model. Its precision β\beta determines how tightly possible targets cluster around that center. We can estimate it from the same likelihood.

Let:

S:=Φw^MLy22S := \lVert \boldsymbol\Phi\widehat{\mathbf w}_{\mathrm{ML}}-\mathbf y \rVert_2^2

be the residual sum of squares at a least-squares solution, which also maximizes the likelihood over w\mathbf w for every fixed β>0\beta>0. Every such solution produces the same fitted training vector, so SS is well defined even if the parameter vector is not unique.

With w=w^ML\mathbf w=\widehat{\mathbf w}_{\mathrm{ML}} fixed, the log-likelihood becomes:

(w^ML,β)=N2logβN2log(2π)β2S.\ell(\widehat{\mathbf w}_{\mathrm{ML}},\beta) = \frac N2\log\beta -\frac N2\log(2\pi) -\frac\beta2S.

Assume first that S>0S>0. Differentiating with respect to β\beta gives:

β=N2βS2.\frac{\partial\ell}{\partial\beta} = \frac{N}{2\beta}-\frac S2.

Setting this derivative to zero yields:

β^ML=NS,β^ML1=1NΦw^MLy22.\boxed{ \widehat\beta_{\mathrm{ML}} = \frac NS, \qquad \widehat\beta_{\mathrm{ML}}^{-1} = \frac1N \lVert \boldsymbol\Phi\widehat{\mathbf w}_{\mathrm{ML}}-\mathbf y \rVert_2^2 }.

The second derivative is

2β2=N2β2<0,\frac{\partial^2\ell}{\partial\beta^2} = -\frac{N}{2\beta^2}<0,

so this stationary point is the unique maximum over β>0\beta>0.

Caveat (An exact fit has no finite precision estimate).If S=0S=0, the fitted curve interpolates every training target. The log-likelihood then increases without bound as β\beta\to\infty, or equivalently as the noise variance approaches zero. In this case, no finite maximum-likelihood estimate of β\beta exists, and the formula N/SN/S must not be used.

3.5 Prediction after maximum likelihood

For a new fixed input xx^\star, the same observation model says:

Yx,w,βN ⁣(ϕ(x)w,β1).Y^\star\mid x^\star,\mathbf w,\beta \sim \mathcal N\!\left( \boldsymbol\phi(x^\star)^\top\mathbf w, \beta^{-1} \right).

Substituting the maximum-likelihood estimates gives the plug-in predictive distribution:

p(yx,w^ML,β^ML)=N ⁣(yϕ(x)w^ML,β^ML1).\boxed{ p(y^\star\mid x^\star, \widehat{\mathbf w}_{\mathrm{ML}}, \widehat\beta_{\mathrm{ML}}) = \mathcal N\!\left( y^\star\mid \boldsymbol\phi(x^\star)^\top \widehat{\mathbf w}_{\mathrm{ML}}, \widehat\beta_{\mathrm{ML}}^{-1} \right) }.

The mean is our familiar curve evaluated at the new input:

y^=ϕ(x)w^ML.\widehat y^\star = \boldsymbol\phi(x^\star)^\top \widehat{\mathbf w}_{\mathrm{ML}}.

The variance β^ML1\widehat\beta_{\mathrm{ML}}^{-1} describes how a new observation can vary around that curve according to the fitted noise model. It does not express uncertainty about the estimated parameters themselves.

3.6 The uncertainty that maximum likelihood discards

The plug-in distribution looks probabilistic, but it treats w^ML\widehat{\mathbf w}_{\mathrm{ML}} and β^ML\widehat\beta_{\mathrm{ML}} as if the data had revealed their exact values. It therefore handles one source of uncertainty while discarding another:

  • Observation uncertainty: even if the parameters were known, a new target could differ from the curve because of ε\varepsilon^\star. The plug-in distribution retains this variation.
  • Parameter uncertainty: finite data can leave many values of w\mathbf w plausible. Substituting w^ML\widehat{\mathbf w}_{\mathrm{ML}} discards this uncertainty.

The difference becomes visible when we extrapolate. Under the constant-variance Gaussian model, the plug-in distribution has the same width at every input. It is just as narrow far away from the training data as it is near them, even though the fitted curve is usually much less constrained there.

This is the limitation that motivates the next step. We will place a prior distribution over w\mathbf w, update it with the Gaussian likelihood, and carry the resulting posterior uncertainty into prediction.

4. A Gaussian prior and the MAP estimate

Maximum likelihood asks which parameter value makes the observations most plausible. It has no way to express which parameter values seemed plausible before seeing those observations. A prior supplies that missing information.

To keep the next derivation focused, we will treat the noise precision β\beta as fixed and introduce uncertainty only over w\mathbf w. We will also introduce a second precision parameter, α>0\alpha>0, that controls the prior. Both are hyperparameters: they determine the shapes of distributions over other quantities rather than directly determining the fitted curveA more complete Bayesian model could place priors over α\alpha and β\beta as well. Treating them as fixed lets us first see the central update for w\mathbf w without another layer of integration..

4.1 A prior over the weights

Choose an isotropic zero-mean Gaussian prior:

p(wα)=N ⁣(w0,α1IP).\boxed{ p(\mathbf w\mid\alpha) = \mathcal N\!\left( \mathbf w\mid\mathbf 0, \alpha^{-1}\mathbf I_P \right) }.

Written as a density, this is:

p(wα)=(α2π)P/2exp ⁣(α2ww).p(\mathbf w\mid\alpha) = \left(\frac{\alpha}{2\pi}\right)^{P/2} \exp\!\left( -\frac\alpha2\mathbf w^\top\mathbf w \right).

The prior assigns its largest density to w=0\mathbf w=\mathbf 0 and gradually less density to parameter vectors with larger Euclidean norm. It does not assert that the weights are zero. It says, before using the targets, that smaller weights are more plausible than very large ones under this model.

The precision α\alpha controls how strongly the prior concentrates around zero:

  • A large α\alpha gives a narrow prior and expresses a stronger preference for small weights.
  • A small α\alpha gives a broad prior and allows a wider range of weights.

This prior is convenient, but it is still an assumption. Zero mean treats positive and negative coefficients symmetrically, while the covariance α1IP\alpha^{-1}\mathbf I_P treats every coefficient as independent and equally variable. Those choices may be unsuitable when features have very different meanings or scales.

4.2 Combining the prior and likelihood

Bayes’ theorem gives the posterior up to its normalizing evidence:

p(wy,Φ,α,β)p(yΦ,w,β)p(wα).p(\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta) \propto p(\mathbf y\mid\boldsymbol\Phi,\mathbf w,\beta) p(\mathbf w\mid\alpha).

Substituting the Gaussian likelihood and prior gives:

p(wy,Φ,α,β)exp ⁣{β2Φwy22α2ww}.p(\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta) \propto \exp\!\left\{ -\frac\beta2 \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 -\frac\alpha2 \mathbf w^\top\mathbf w \right\}.

The likelihood favors weights whose curve agrees with the observed targets. The prior favors weights close to zero. The posterior combines both preferences rather than choosing between them.

Move the evidence, watch the posterior negotiate

Posterior ∝ likelihood × prior; precision determines the pull

priorlikelihooddrag the evidenceμ = +1.16
Prior mean0.00
Likelihood peak+1.80
Posterior mean+1.16
Posterior σ0.60
Drag the coral likelihood peak. The purple posterior stays between it and the zero-centred blue prior. Increase likelihood precision to make the evidence narrower and more influential: the posterior moves toward it and contracts. The curves are normalized densities, so greater precision also produces a taller peak.

The figure shows the standard one-dimensional Gaussian conjugate update [Bishop, 2006] [Murphy, 2022] so that the mechanism fits on a page. Our regression parameter w\mathbf w lives in RP\mathbb R^P, where prior, likelihood, and posterior are surfaces rather than lines, but the same precision-weighted multiplication occurs.

4.3 The MAP objective

The MAP estimate is the mode of this posterior. Since the logarithm is strictly increasing, maximizing the posterior is equivalent to minimizing its negative logarithm. Terms that do not depend on w\mathbf w can be dropped, leaving:

w^MAParg minw{β2Φwy22+α2w22}.\boxed{ \widehat{\mathbf w}_{\mathrm{MAP}} \in \operatorname*{arg\,min}_{\mathbf w} \left\{ \frac\beta2 \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 + \frac\alpha2 \lVert\mathbf w\rVert_2^2 \right\} }.

The first term rewards agreement with the data; the second penalizes large weights. Dividing the whole objective by β>0\beta>0 does not change its minimizer, so we can also write:

w^MAParg minw{12Φwy22+λ2w22},λ=αβ.\widehat{\mathbf w}_{\mathrm{MAP}} \in \operatorname*{arg\,min}_{\mathbf w} \left\{ \frac12 \lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 + \frac\lambda2 \lVert\mathbf w\rVert_2^2 \right\}, \qquad \lambda=\frac\alpha\beta.

This is the objective used by ridge regression, or L2L_2-regularized least squares. From the optimization viewpoint, λ\lambda is a regularization strength. From the probabilistic viewpoint, it is the ratio between prior precision and observation precision.

4.4 Solving for the MAP estimate

Differentiating the MAP objective gives:

βΦ(Φwy)+αw.\beta\boldsymbol\Phi^\top (\boldsymbol\Phi\mathbf w-\mathbf y) + \alpha\mathbf w.

Setting this gradient to zero yields:

(βΦΦ+αIP)w^MAP=βΦy.(\beta\boldsymbol\Phi^\top\boldsymbol\Phi +\alpha\mathbf I_P) \widehat{\mathbf w}_{\mathrm{MAP}} = \beta\boldsymbol\Phi^\top\mathbf y.

Because α>0\alpha>0, the matrix βΦΦ+αIP\beta\boldsymbol\Phi^\top\boldsymbol\Phi+\alpha\mathbf I_P is positive definite even when Φ\boldsymbol\Phi is rank deficient. The MAP estimate is therefore unique:

w^MAP=(βΦΦ+αIP)1βΦy.\boxed{ \widehat{\mathbf w}_{\mathrm{MAP}} = (\beta\boldsymbol\Phi^\top\boldsymbol\Phi +\alpha\mathbf I_P)^{-1} \beta\boldsymbol\Phi^\top\mathbf y }.

Equivalently,

w^MAP=(ΦΦ+αβIP)1Φy.\widehat{\mathbf w}_{\mathrm{MAP}} = \left( \boldsymbol\Phi^\top\boldsymbol\Phi +\frac\alpha\beta\mathbf I_P \right)^{-1} \boldsymbol\Phi^\top\mathbf y.

As α0\alpha\to0, the prior becomes flatter and the MAP objective approaches least squares. For positive α\alpha, the prior pulls the solution toward zero and resolves parameter non-uniqueness by preferring the smaller-norm explanation.

MAP has improved the optimization problem, but its output remains one parameter vector. The posterior expression above contains more information than its mode. In the next step, we will identify the entire Gaussian posterior and see what uncertainty MAP leaves behind.

5. Keeping the whole posterior

The MAP estimate keeps only the highest point of the posterior. This is enough when our sole aim is to choose one parameter vector, but it cannot tell us whether that point is a sharp peak or merely the top of a broad hill. Those two posteriors have the same kind of summary—a mode—but express very different levels of certainty.

For our Gaussian likelihood and Gaussian prior, we do not need an approximation to recover the missing information. Their product is another Gaussian distribution, so the full posterior can be written exactly.

5.1 Recognizing the Gaussian

Return to the unnormalized posterior:

p(wy,Φ,α,β)exp ⁣{12[βΦwy22+αww]}.p(\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta) \propto \exp\!\left\{ -\frac12 \left[ \beta\lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 +\alpha\mathbf w^\top\mathbf w \right] \right\}.

To identify this density, we need to rewrite its exponent as a quadratic centered at some vector. First expand the squared residual:

βΦwy22+αww=w(αIP+βΦΦ)SN1w2(βΦy)SN1mNw+βyy.\begin{aligned} \beta\lVert\boldsymbol\Phi\mathbf w-\mathbf y\rVert_2^2 +\alpha\mathbf w^\top\mathbf w &= \mathbf w^\top \underbrace{(\alpha\mathbf I_P+\beta\boldsymbol\Phi^\top\boldsymbol\Phi)}_{\mathbf S_N^{-1}} \mathbf w -2\underbrace{(\beta\boldsymbol\Phi^\top\mathbf y)}_{\mathbf S_N^{-1}\mathbf m_N}^\top\mathbf w +\beta\mathbf y^\top\mathbf y. \end{aligned}

This notation defines

SN1=αIP+βΦΦ,mN=βSNΦy.\boxed{ \mathbf S_N^{-1} = \alpha\mathbf I_P + \beta\boldsymbol\Phi^\top\boldsymbol\Phi }, \qquad \boxed{ \mathbf m_N = \beta\mathbf S_N\boldsymbol\Phi^\top\mathbf y }.

The matrix SN1\mathbf S_N^{-1} is positive definite because α>0\alpha>0, so its inverse SN\mathbf S_N exists. We can therefore complete the square:

wSN1w2mNSN1w+βyy=(wmN)SN1(wmN)+βyymNSN1mN.\begin{aligned} &\mathbf w^\top\mathbf S_N^{-1}\mathbf w -2\mathbf m_N^\top\mathbf S_N^{-1}\mathbf w +\beta\mathbf y^\top\mathbf y \\ &\qquad= (\mathbf w-\mathbf m_N)^\top \mathbf S_N^{-1} (\mathbf w-\mathbf m_N) +\beta\mathbf y^\top\mathbf y -\mathbf m_N^\top\mathbf S_N^{-1}\mathbf m_N. \end{aligned}

The last two terms do not depend on w\mathbf w; they become part of the normalizing constant. What remains has exactly the exponent of a multivariate Gaussian. Hence

p(wy,Φ,α,β)=N(wmN,SN).\boxed{ p(\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta) = \mathcal N(\mathbf w\mid\mathbf m_N,\mathbf S_N) }.

This closed form is a consequence of conjugacy: the Gaussian prior and Gaussian likelihood combine to produce a posterior in the same distribution family as the prior. Conjugacy is not required for Bayesian inference, but here it lets us see every step without numerical integration [Murphy, 2022].

5.2 What the posterior mean remembers from MAP

The posterior mean is

mN=(αIP+βΦΦ)1βΦy.\mathbf m_N = (\alpha\mathbf I_P+\beta\boldsymbol\Phi^\top\boldsymbol\Phi)^{-1} \beta\boldsymbol\Phi^\top\mathbf y.

This is exactly the MAP estimate derived in Section 4:

mN=w^MAP.\boxed{ \mathbf m_N=\widehat{\mathbf w}_{\mathrm{MAP}} }.

The equality is special to this Gaussian posterior. A Gaussian is symmetric around its mean, and its mean is also its unique mode. For a skewed or multimodal posterior, the posterior mean and MAP estimate can differ substantially.

The Bayesian update therefore does not discard the curve selected by MAP. It places that curve at the center of a distribution over alternative parameter vectors:

wy,Φ,α,βN(mN,SN).\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta \sim \mathcal N(\mathbf m_N,\mathbf S_N).

Each draw of w\mathbf w from this posterior produces a different plausible curve f(x,w)f(x,\mathbf w). Parameter vectors close to mN\mathbf m_N in the geometry determined by SN\mathbf S_N receive more posterior density, while distant vectors receive less. MAP retains the center; full Bayesian inference retains the surrounding alternatives as well.

The next figure makes this correspondence visible in the special case ϕ(x)=(1,x)\boldsymbol\phi(x)=(1,x)^\top. Then w=(w0,w1)\mathbf w=(w_0,w_1)^\top has only two components, so a point in weight space can be drawn on a page. That same point defines exactly one line f(x,w)=w0+w1xf(x,\mathbf w)=w_0+w_1x in function space.

Drag a weight, watch the function move

The same w determines a location in posterior density and a line f(x, w)

Posterior density in weight spaceGreen-to-coral contour bands show posterior density. The dashed contour shows the prior. A draggable gold marker selects one intercept and slope.Posterior density p(w | D)-202-202intercept w₀slope w₁priorselected = meanSelected and posterior-mean functionsThe selected intercept and slope produce one gold line. Residual segments connect that line to the observations. The posterior mean and uncertainty band provide context.Function f(x, w)-1.501.5-202input xf(x, w)Observation 1: (-1.35, -0.72), residual -0.16Observation 2: (-0.55, 0.18), residual 0.21selected = mean
Selected weight(0.34, 0.66)
Relative posterior density100% of peak
Drag the gold marker through weight space. Its line moves at the same time, while the residual segments show how that choice fits the observations. Warmer inner contours mean greater posterior density. Add data to watch the plausible region contract; the blue band is ±1 posterior standard deviation for the latent function and excludes observation noise.

This coupled view follows the weight-space constructions used by Bishop and by Rasmussen and Williams [Bishop, 2006] [Rasmussen et al., 2006]. Its direct manipulation is inspired by the linked weight-space and prediction views in Yu et al.’s visual tutorial [Yu et al., n.d.]. It is a two-parameter illustration, not a claim that a high-dimensional posterior can always be inspected directly. What survives in higher dimensions is the correspondence: selecting one w\mathbf w identifies one possible function, while sampling w\mathbf w from the posterior produces functions in proportion to their posterior plausibility.

5.3 Reading uncertainty from the covariance

The posterior covariance is

SN=(αIP+βΦΦ)1.\boxed{ \mathbf S_N = (\alpha\mathbf I_P+\beta\boldsymbol\Phi^\top\boldsymbol\Phi)^{-1} }.

Its inverse has a particularly useful interpretation:

SN1posterior precision=αIPprior precision+βΦΦinformation supplied by the data.\underbrace{\mathbf S_N^{-1}}_{\text{posterior precision}} = \underbrace{\alpha\mathbf I_P}_{\text{prior precision}} + \underbrace{\beta\boldsymbol\Phi^\top\boldsymbol\Phi}_{\text{information supplied by the data}}.

The update is additive in precision, not covariance. To make “direction” precise, choose any unit vector vRP\mathbf v\in\mathbb R^P and restrict the posterior to a line w0+tv\mathbf w_0+t\mathbf v. Its negative log-density has curvature

vSN1v=α+βΦv22.\mathbf v^\top\mathbf S_N^{-1}\mathbf v = \alpha + \beta\lVert\boldsymbol\Phi\mathbf v\rVert_2^2.

The prior contributes α\alpha in every direction. The data contribute more curvature when moving along v\mathbf v changes the fitted training values substantially. If Φv=0\boldsymbol\Phi\mathbf v=\mathbf 0, the likelihood is flat along that direction and contributes nothing; only the prior prevents the posterior from remaining flat.

The uncertainty of the scalar component vw\mathbf v^\top\mathbf w is

Var(vwy)=vSNv.\operatorname{Var}(\mathbf v^\top\mathbf w\mid\mathbf y) = \mathbf v^\top\mathbf S_N\mathbf v.

These two directional quantities are exact, but they are not generally reciprocals: correlations can couple v\mathbf v to other directions. They become reciprocals when v\mathbf v is an eigenvector of SN\mathbf S_N. The useful conclusion survives without that shortcut—the likelihood constrains only parameter movements that change the model’s values at the observed inputs.

This also explains why the posterior remains well defined when the design matrix is rank deficient. Least squares cannot distinguish parameter vectors that differ in an unobserved direction. The Gaussian prior can: it supplies the positive precision α\alpha even where the likelihood supplies none.

Important (Uncertain parameters do not always mean uncertain predictions)

Two parameter vectors can differ while producing nearly the same function over inputs we care about. Conversely, a modest amount of parameter uncertainty can become large predictive uncertainty at an input whose feature vector points in a poorly constrained direction. The covariance SN\mathbf S_N lives in parameter space; the feature vector ϕ(x)\boldsymbol\phi(x) will translate it into uncertainty about a prediction.

We now possess what MAP omitted: a distribution over the weights. The remaining step is to make a prediction without collapsing that distribution back to one fitted vector. We will do this by averaging the observation model over every parameter value in the posterior.

6. Prediction without collapsing the posterior

At a new input xx^\star, maximum likelihood and MAP substitute one fitted weight vector into the observation model. Full Bayesian prediction takes a different route: it considers the prediction made by every possible w\mathbf w and weighs that prediction by the posterior plausibility of w\mathbf w.

The resulting posterior predictive distribution is

p(yx,y,Φ,α,β)=p(yx,w,β)p(wy,Φ,α,β)dw.\boxed{ p(y^\star\mid x^\star,\mathbf y,\boldsymbol\Phi,\alpha,\beta) = \int p(y^\star\mid x^\star,\mathbf w,\beta) p(\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta) \,d\mathbf w }.

The integral is the essential Bayesian step. We do not have to decide which single w\mathbf w is correct before predicting. Instead, parameter values with high posterior density contribute strongly, values with low posterior density contribute weakly, and the alternatives are averaged rather than discarded [MacKay, 2003].

6.1 From uncertain weights to an uncertain curve

Let

ϕ=ϕ(x)\boldsymbol\phi^\star=\boldsymbol\phi(x^\star)

be the feature vector at the new input. Under the posterior,

wy,Φ,α,βN(mN,SN).\mathbf w\mid\mathbf y,\boldsymbol\Phi,\alpha,\beta \sim \mathcal N(\mathbf m_N,\mathbf S_N).

The noise-free model value at xx^\star is the scalar

F=(ϕ)w.F^\star=(\boldsymbol\phi^\star)^\top\mathbf w.

A linear transformation of a Gaussian random vector is Gaussian. Therefore,

Fx,y,Φ,α,βN ⁣((ϕ)mN,(ϕ)SNϕ).\boxed{ F^\star\mid x^\star,\mathbf y,\boldsymbol\Phi,\alpha,\beta \sim \mathcal N\!\left( (\boldsymbol\phi^\star)^\top\mathbf m_N, (\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star \right) }.

The mean is the curve obtained from the posterior mean mN\mathbf m_N, which is also the MAP estimate in our model. The variance is new. It measures how much the plausible curves disagree at the particular input xx^\star.

Notice that this variance depends on the input through ϕ\boldsymbol\phi^\star. The posterior over w\mathbf w is the same no matter where we query it, but different inputs probe different directions in parameter space. Near well-supported inputs, the plausible curves may agree closely. Where the data constrain the curve poorly, they may spread apart.

6.2 Adding the uncertainty of a future observation

A future target is not just the noise-free curve value. The observation model also includes fresh noise:

Y=F+ε,εN(0,β1).Y^\star=F^\star+\varepsilon^\star, \qquad \varepsilon^\star\sim\mathcal N(0,\beta^{-1}).

The new noise ε\varepsilon^\star is independent of the posterior uncertainty in FF^\star. The sum of two independent Gaussian variables is Gaussian; their means and variances add. Thus the integral defining the posterior predictive distribution has the closed form

p(yx,y,Φ,α,β)=N ⁣(y(ϕ)mN,β1+(ϕ)SNϕ).\boxed{ p(y^\star\mid x^\star,\mathbf y,\boldsymbol\Phi,\alpha,\beta) = \mathcal N\!\left( y^\star\mid (\boldsymbol\phi^\star)^\top\mathbf m_N, \beta^{-1} + (\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star \right) }.

The predictive variance separates into two sources:

Var(Yx,D)total predictive uncertainty=β1observation uncertainty+(ϕ)SNϕparameter uncertainty at x.\underbrace{\operatorname{Var}(Y^\star\mid x^\star,\mathcal D)}_{\text{total predictive uncertainty}} = \underbrace{\beta^{-1}}_{\text{observation uncertainty}} + \underbrace{(\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star}_{\text{parameter uncertainty at }x^\star}.

The first term is the irreducible variation assumed by our observation model. Even perfect knowledge of w\mathbf w would not remove it. The second term records our incomplete knowledge of the curve. It can shrink as informative data constrain the weights, and it changes with the input.

This distinction also tells us which uncertainty to report:

  • If we care about the latent mean function FF^\star, its posterior variance is only (ϕ)SNϕ(\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star.
  • If we care about a future noisy target YY^\star, its predictive variance also includes β1\beta^{-1}.

Calling both bands simply an “uncertainty interval” hides an important modeling choice. One describes uncertainty about the underlying curve; the other describes where a new observation may fall.

The distinction becomes easier to see if we inspect both distributions at the same input and then move that input through the domain.

Drag the question, separate the uncertainties

The latent curve and a future observation answer different questions

drag x*F* · latentY* · future targetpossible valueμ = +1.78
Query x*+1.80
Latent σ0.31
Noise σ0.35
Predictive σ0.47
Drag the gold query through the regression plot. The blue band is a 95% credible interval for the noise-free value F*; the coral band is the wider 95% predictive interval for a future target Y*. Their cross-sections appear on the right. Observation noise stays fixed, while disagreement among plausible lines changes with x* and shrinks when more data are used.

This linked construction follows the predictive-variance decomposition used in Bayesian linear regression [Bishop, 2006] [Murphy, 2022] and the function-space interpretation emphasized by Rasmussen and Williams [Rasmussen et al., 2006]. The bands use Gaussian 95% intervals under our fixed prior and noise precision; they are conditional on those modeling assumptions.

For example, under our Gaussian model,

(ϕ)mN  ±  1.96(ϕ)SNϕ(\boldsymbol\phi^\star)^\top\mathbf m_N \;\pm\; 1.96\sqrt{(\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star}

is an approximate 95%95\% posterior credible interval for the latent value FF^\star. It does not include the additional scatter of a future observation around that value.

6.3 What full Bayesian prediction adds

Compare the result with a plug-in prediction that substitutes the MAP estimate w^MAP=mN\widehat{\mathbf w}_{\mathrm{MAP}}=\mathbf m_N. The Bayesian and MAP plug-in predictive means agree:

E[Yx,D]=(ϕ)mN.\mathbb E[Y^\star\mid x^\star,\mathcal D] = (\boldsymbol\phi^\star)^\top\mathbf m_N.

The maximum-likelihood plug-in mean from Section 3 generally differs because w^ML\widehat{\mathbf w}_{\mathrm{ML}} need not equal mN\mathbf m_N. More importantly, either plug-in approach discards parameter uncertainty. A MAP plug-in distribution keeps only β1\beta^{-1} in its variance; Bayesian prediction also carries the posterior uncertainty in the weights:

VarBayes(Yx,D)=Varplug-in(Yx)+(ϕ)SNϕ.\operatorname{Var}_{\mathrm{Bayes}}(Y^\star\mid x^\star,\mathcal D) = \operatorname{Var}_{\mathrm{plug\text{-}in}}(Y^\star\mid x^\star) + (\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star.

This is why the Bayesian predictive band can widen away from the observations even though the assumed noise variance β1\beta^{-1} is constant. The noise has not increased; the plausible curves disagree more strongly there.

A Bayesian polynomial regression prediction with observations, the true generating curve, the posterior predictive mean, and a predictive uncertainty band that becomes wider near the boundaries

Bishop’s Bayesian polynomial curve fit. The red curve is the predictive mean and the shaded region extends one predictive standard deviation on either side [Bishop, 2006].

In the figure, the shaded region is narrower where the observations constrain the polynomial and wider near the boundaries, where many plausible weight vectors yield different curves. The width combines observation noise and parameter uncertainty; it should not be read as uncertainty in the red mean curve alone. The green curve is the function that generated Bishop’s synthetic data, shown for comparison. A real dataset would not reveal this ground-truth function to us.

For a Gaussian posterior predictive distribution, an interval

(ϕ)mN  ±  1.96β1+(ϕ)SNϕ(\boldsymbol\phi^\star)^\top\mathbf m_N \;\pm\; 1.96 \sqrt{ \beta^{-1} + (\boldsymbol\phi^\star)^\top\mathbf S_N\boldsymbol\phi^\star }

contains approximately 95%95\% of future targets under the model. This is a posterior predictive interval: unlike the plug-in predictive distribution in Section 3, it averages over uncertainty in w\mathbf w. The statement is still conditional on our chosen feature map and on the fixed hyperparameters α\alpha and β\beta.

The progression is now complete. Least squares chose one curve by minimizing error. A Gaussian noise model reinterpreted that choice as maximum likelihood. A Gaussian prior turned it into MAP and ridge regression. The full posterior retained the plausible alternatives, and the posterior predictive distribution carried their disagreement into the prediction.

Notation

The table below records the symbols that carry the main argument. We use YnY_n, Y\mathbf Y, and YY^\star for random targets under the observation model; yny_n, y\mathbf y, and yy^\star denote realized values. Other uppercase symbols can have different roles: Φ\boldsymbol\Phi, for example, is a fixed matrix. A hat marks a fitted or estimated quantity.

SymbolMeaningShape or domainRole
D\mathcal DTraining dataset {(xn,yn)}n=1N\{(x_n,y_n)\}_{n=1}^NNN input-target pairsObserved
xnx_nInput for observation nnR\mathbb RFixed design
yny_n / YnY_nObserved target / target before observationR\mathbb RObserved / random
ϕ(x)\boldsymbol\phi(x)Feature vector at input xxRP\mathbb R^PFixed transformation
Φ\boldsymbol\PhiDesign matrixRN×P\mathbb R^{N\times P}Fixed after observing the inputs
w\mathbf wModel parametersRP\mathbb R^POptimized first; uncertain later
y\mathbf y / Y\mathbf YObserved / random target vectorRN\mathbb R^NObserved / random
β\betaObservation-noise precisionR>0\mathbb R_{>0}Estimated first; possibly uncertain later
α\alphaPrior precision for w\mathbf wR>0\mathbb R_{>0}Fixed hyperparameter
λ\lambdaMAP regularization strength α/β\alpha/\betaR>0\mathbb R_{>0}Derived hyperparameter
mN\mathbf m_NPosterior mean of w\mathbf wRP\mathbb R^PInferred from the data
SN\mathbf S_NPosterior covariance of w\mathbf wRP×P\mathbb R^{P\times P}Inferred uncertainty
xx^\starNew inputR\mathbb RFixed query
FF^\starLatent noise-free model value at xx^\starR\mathbb RRandom under the posterior
yy^\star / YY^\starRealized / random future targetR\mathbb RPrediction

References

  1. [Bishop, 2006]
    Pattern Recognition and Machine Learning[HTML]
    Bishop, Christopher M., 2006. Springer.
  2. [Trefethen et al., 1997]
    Numerical Linear Algebra[DOI]
    Trefethen, Lloyd N. and Bau, David, 1997. Society for Industrial and Applied Mathematics.
  3. [Rasmussen et al., 2006]
    Gaussian Processes for Machine Learning[HTML]
    Rasmussen, Carl Edward and Williams, Christopher K. I., 2006. MIT Press.
  4. [Murphy, 2022]
    Probabilistic Machine Learning: An Introduction[HTML]
    Murphy, Kevin P., 2022. MIT Press.
  5. [MacKay, 2003]
    Information Theory, Inference, and Learning Algorithms[HTML]
    MacKay, David J. C., 2003. Cambridge University Press.
  6. [Yu et al., n.d.]
    Bayesian Neural Networks[HTML]
    Yu, Jerry Qinghui, Creager, Elliot, Duvenaud, David, et al., n.d..