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,yn∈R
be a dataset of N input-target pairs. Our immediate task is to construct a function that predicts the target corresponding to a new input x⋆.
For now, the inputs x1,…,xN 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 Mth-degree polynomial is flexible enough to represent the pattern of our dataset:
f(x,w)=w0+w1x+⋯+wMxM=j=0∑Mwjxj,
where:
w=(w0,w1,…,wM)⊤∈RM+1
is the parameter vector. When M>1, the function is nonlinear in the input x, but it is still linear in the parameters: each wj appears only to the first power, multiplied by a known function of x. 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+1 and define the basis functions:
ϕj(x)=xj,j=0,1,…,M.
Collecting them gives us the feature vector:
ϕ(x)=ϕ0(x)ϕ1(x)⋮ϕP−1(x)∈RP,
so the polynomial can be written as a dot product:
f(x,w)=ϕ(x)⊤w.
Nothing in this form requires monomials. We could replace the components of ϕ—the monomials 1,x,x2,… in this case—with splines, Fourier functions, radial basis functions, or another fixed collection of features. Once ϕ has been chosen, the model remains linear in 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.
Similarly, collect the observed targets into:
y=y1y2⋮yN∈RN.
For any proposed parameter vector w, the product:
Φw=f(x1,w)f(x2,w)⋮f(xN,w)
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. 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 that minimizes it.
For a parameter vector w, we define the residual vector as:
r(w)=Φw−y.
We define the loss function E(w) as the sum of squared residualsThe factor 1/2 does not change which parameters minimize the objective; it merely cancels the factor 2 that appears when we differentiate a square.:
E(w)=21∥Φw−y∥22.
A least-squares estimate is any parameter vector satisfyingWe write ∈ rather than = because the minimizing parameter vector need not be unique. If the columns of Φ are linearly dependent, different parameter vectors can produce identical predictions at every training input.:
wLS∈w∈RPargminE(w).
1.4 Solving for the fitted curve
To find a least-squares estimate, differentiate the objective:
∇wE(w)=∇w[21(Φw−y)⊤(Φw−y)]=Φ⊤(Φw−y).
Setting the gradient to zero gives the normal equations:
Φ⊤ΦwLS=Φ⊤y.
The normal equations also have a geometric meaning. Rewrite them as
Φ⊤(ΦwLS−y)=0.
Every attainable vector of fitted training values lies in the column space col(Φ). The equation says that the fitted residual is orthogonal to every column of Φ, and therefore to that entire model space. Thus ΦwLS is the closest point in the model space to 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
same candidate ↔
Candidate a·
Loss E(a)·
Best â·
Minimum·
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 Φ⊤Φ, and for every v∈RP:
v⊤Φ⊤Φv=∥Φv∥22≥0.
Therefore E is convex, so every solution of the normal equations is a global minimizer. If Φ has full column rank, the Hessian is positive definite, the minimizer is unique, and:
wLS=(Φ⊤Φ)−1Φ⊤y.
If Φ is rank deficient, a minimizer still exists and the fitted training vector ΦwLS 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 is an unknown but fixed parameter. We search through RP and retain a value that minimizes E(w). The hat in wLS 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 with a probability distribution. Imagine that the curve has one fixed but unknown parameter vector. Before seeing the data, many values of 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; they do not cause the parameter itself to move or be redrawn.
This is separate from noisy observations. Even if 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 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(D∣w)p(w)=p(w∣D)p(D).
Equating the two factorizations and dividing by p(D) gives Bayes’ theorem:
p(w∣D)=p(D)p(D∣w)p(w).
Each term has a different role:
The priorp(w) describes our uncertainty about the parameters before using D.
The likelihoodp(D∣w) measures how compatible the observed data are with each proposed parameter value.
The posteriorp(w∣D) describes our updated uncertainty after using the data.
The evidencep(D) is the probability or density assigned to the observed data by the model as a whole.
For a continuous parameter vector w∈RP, the evidence is obtained by averaging the likelihood under the prior. This is also known as marginalization:
p(D)=∫RPp(D∣w)p(w)dw.
Provided 0<p(D)<∞, the evidence normalizes the numerator so that the posterior integrates to one. It does not depend on the particular value of w under consideration, so we can treat it as a constant with respect to w. We may therefore describe the shape of the posterior by writing:
p(w∣D)∝p(D∣w)p(w).
2.3 What is the likelihood?
The expression p(D∣w) can be read in two related ways. If w is fixed and possible datasets vary, it is a probability mass function or density over the data. Once D has been observed, we hold it fixed and view the same expression as a function of w:
L(w;D):=p(D∣w).
This function is the likelihood. The semicolon is a reminder that w varies while the observed dataset is fixed.
Likelihood is not, by itself, a probability distribution over w. In general:
∫RPL(w;D)dw
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:
wML∈wargmaxp(D∣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:
wMAP∈wargmaxp(w∣D)=wargmaxp(D∣w)p(w).
The evidence disappears from the optimization because it is constant with respect to 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:
wMAP=wML
whenever the corresponding optimizer is uniqueA proper uniform distribution over all of RP 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 x⋆, it averages the prediction associated with every possible parameter value, weighted by posterior plausibility:
p(y⋆∣x⋆,D)=∫RPp(y⋆∣x⋆,w)p(w∣D)dw.
After integrating over 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 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,…,xN 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,
This mismatch or error is represented by a random noise variable εn:
εn∼i.i.d.N(0,β−1),β>0.
The parameter β is called the noise precision. Precision is the reciprocal of variance, so a larger β means that observations are more tightly concentrated around the curve We usually use μ and σ2 for a “standard” notation when a random variable has a normal distribution. But here, we use β, or the precision, instead. The goal is to make the derivation more convenient and also more consistent with Bayesian literature.:
Var(εn)=β−1.
The curve with a Gaussian noise model from Bishop [Bishop, 2006].
Equivalently, the conditional distribution of each target is:
Yn∣xn,w,β∼N(ϕ(xn)⊤w,β−1).
The curve f(xn,w) now has a probabilistic meaning: it is the conditional mean of the target.
E[Yn∣xn,w,β]=f(xn,w)=ϕ(xn)⊤w.
Zero-mean noise does not say that every observed residual r must be zero. It says that if we repeatedly generated a target at the same input while holding w and β fixed, the residuals would average to zero under the model.
Collect the random targets into Y=(Y1,…,YN)⊤. The N scalar assumptions can then be written as one multivariate Gaussian:
Y∣Φ,w,β∼N(Φw,β−1IN).
The covariance matrix β−1IN 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 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. Because the targets are conditionally independent, their joint density is the product of the individual Gaussian densities:
Holding y and Φ fixed while varying w and β turns this density into the likelihood:
L(w,β;y,Φ):=p(y∣Φ,w,β).
Substituting the Gaussian density gives:
L(w,β)=(2πβ)N/2exp{−2β∥Φw−y∥22},
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:
Using the least-squares loss E(w), the same expression becomes:
ℓ(w,β)=2Nlogβ−2Nlog(2π)−βE(w).
Drag one residual through probability and loss
The negative logarithm reverses the ranking without moving the optimum
Probability viewGaussian density p(r | β)-2-1012residual r = prediction − observationp = 0.242most probabledrag r
apply −log ↓
Optimization viewloss −log p(r | β)-2-1012residual r = prediction − observationloss = 1.419smallest lossdrag r
Residual r·
Density·
Negative log-likelihood·
Noise σ·
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. The first two terms of ℓ(w,β) do not depend on w, and the coefficient of E(w) is strictly negative. Therefore:
wargmaxℓ(w,β)=wargmax[−βE(w)]=wargminE(w).
The maximizing set is the same for every fixed β>0. Consequently, whenever a finite joint maximum over (w,β) exists, its w component is a least-squares estimate. Conversely, any least-squares estimate maximizes the likelihood over w when β is fixed:
wML∈wargmin21∥Φw−y∥22.
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[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 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 β determines how tightly possible targets cluster around that center. We can estimate it from the same likelihood.
Let:
S:=∥ΦwML−y∥22
be the residual sum of squares at a least-squares solution, which also maximizes the likelihood over w for every fixed β>0. Every such solution produces the same fitted training vector, so S is well defined even if the parameter vector is not unique.
With w=wML fixed, the log-likelihood becomes:
ℓ(wML,β)=2Nlogβ−2Nlog(2π)−2βS.
Assume first that S>0. Differentiating with respect to β gives:
∂β∂ℓ=2βN−2S.
Setting this derivative to zero yields:
βML=SN,βML−1=N1∥ΦwML−y∥22.
The second derivative is
∂β2∂2ℓ=−2β2N<0,
so this stationary point is the unique maximum over β>0.
Caveat (An exact fit has no finite precision estimate).If S=0, the fitted curve interpolates every training target. The log-likelihood then increases without bound as β→∞, or equivalently as the noise variance approaches zero. In this case, no finite maximum-likelihood estimate of β exists, and the formula N/S must not be used.
3.5 Prediction after maximum likelihood
For a new fixed input x⋆, the same observation model says:
Y⋆∣x⋆,w,β∼N(ϕ(x⋆)⊤w,β−1).
Substituting the maximum-likelihood estimates gives the plug-in predictive distribution:
p(y⋆∣x⋆,wML,βML)=N(y⋆∣ϕ(x⋆)⊤wML,βML−1).
The mean is our familiar curve evaluated at the new input:
y⋆=ϕ(x⋆)⊤wML.
The variance β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 wML and β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 ε⋆. The plug-in distribution retains this variation.
Parameter uncertainty: finite data can leave many values of w plausible. Substituting wML 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, 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 β as fixed and introduce uncertainty only over w. We will also introduce a second precision parameter, α>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 α and β as well. Treating them as fixed lets us first see the central update for w without another layer of integration..
4.1 A prior over the weights
Choose an isotropic zero-mean Gaussian prior:
p(w∣α)=N(w∣0,α−1IP).
Written as a density, this is:
p(w∣α)=(2πα)P/2exp(−2αw⊤w).
The prior assigns its largest density to w=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 α controls how strongly the prior concentrates around zero:
A large α gives a narrow prior and expresses a stronger preference for small weights.
A small α 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 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(w∣y,Φ,α,β)∝p(y∣Φ,w,β)p(w∣α).
Substituting the Gaussian likelihood and prior gives:
p(w∣y,Φ,α,β)∝exp{−2β∥Φw−y∥22−2αw⊤w}.
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
A Gaussian prior and likelihood combine into a posteriorDragging the likelihood mean in the left panel moves the posterior in the right panel. Increasing likelihood precision makes both curves narrower and pulls the posterior closer to the likelihood.Factorsprior × likelihood-3-2-10123wpriorlikelihooddrag the evidence∝normalizePosteriornormalized product; dashed guides mark the input means-3-2-10123wμ = +1.16
Factorsprior × likelihood-3-2-10123wpriorlikelihooddrag the evidence
multiply and normalize ↓
Posteriornormalized product; dashed guides mark the input means-3-2-10123wμ = +1.16
Prior mean·
Likelihood peak·
Posterior mean·
Posterior σ·
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 lives in RP, 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 can be dropped, leaving:
wMAP∈wargmin{2β∥Φw−y∥22+2α∥w∥22}.
The first term rewards agreement with the data; the second penalizes large weights. Dividing the whole objective by β>0 does not change its minimizer, so we can also write:
wMAP∈wargmin{21∥Φw−y∥22+2λ∥w∥22},λ=βα.
This is the objective used by ridge regression, or L2-regularized least squares. From the optimization viewpoint, λ 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:
βΦ⊤(Φw−y)+αw.
Setting this gradient to zero yields:
(βΦ⊤Φ+αIP)wMAP=βΦ⊤y.
Because α>0, the matrix βΦ⊤Φ+αIP is positive definite even when Φ is rank deficient. The MAP estimate is therefore unique:
wMAP=(βΦ⊤Φ+αIP)−1βΦ⊤y.
Equivalently,
wMAP=(Φ⊤Φ+βαIP)−1Φ⊤y.
As α→0, the prior becomes flatter and the MAP objective approaches least squares. For positive α, 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(w∣y,Φ,α,β)∝exp{−21[β∥Φw−y∥22+αw⊤w]}.
To identify this density, we need to rewrite its exponent as a quadratic centered at some vector. First expand the squared residual:
The last two terms do not depend on w; they become part of the normalizing constant. What remains has exactly the exponent of a multivariate Gaussian. Hence
p(w∣y,Φ,α,β)=N(w∣mN,SN).
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.
This is exactly the MAP estimate derived in Section 4:
mN=wMAP.
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:
w∣y,Φ,α,β∼N(mN,SN).
Each draw of w from this posterior produces a different plausible curve f(x,w). Parameter vectors close to mN in the geometry determined by SN 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)⊤. Then w=(w0,w1)⊤ 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+w1x 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)
One weight shown in parameter space and function spaceDragging the selected weight in the left plot changes the regression line and residuals in the right plot.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 = meansame wSelected 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
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 = mean
same w ↓
Selected 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·
Relative posterior density·
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 identifies one possible function, while sampling 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.
Its inverse has a particularly useful interpretation:
posterior precisionSN−1=prior precisionαIP+information supplied by the dataβΦ⊤Φ.
The update is additive in precision, not covariance. To make “direction” precise, choose any unit vector v∈RP and restrict the posterior to a line w0+tv. Its negative log-density has curvature
v⊤SN−1v=α+β∥Φv∥22.
The prior contributes α in every direction. The data contribute more curvature when moving along v changes the fitted training values substantially. If Φv=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 v⊤w is
Var(v⊤w∣y)=v⊤SNv.
These two directional quantities are exact, but they are not generally reciprocals: correlations can couple v to other directions. They become reciprocals when v is an eigenvector of SN. 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 α 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 lives in parameter space; the feature vector ϕ(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 x⋆, 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 and weighs that prediction by the posterior plausibility of w.
The resulting posterior predictive distribution is
p(y⋆∣x⋆,y,Φ,α,β)=∫p(y⋆∣x⋆,w,β)p(w∣y,Φ,α,β)dw.
The integral is the essential Bayesian step. We do not have to decide which single 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⋆)
be the feature vector at the new input. Under the posterior,
w∣y,Φ,α,β∼N(mN,SN).
The noise-free model value at x⋆ is the scalar
F⋆=(ϕ⋆)⊤w.
A linear transformation of a Gaussian random vector is Gaussian. Therefore,
F⋆∣x⋆,y,Φ,α,β∼N((ϕ⋆)⊤mN,(ϕ⋆)⊤SNϕ⋆).
The mean is the curve obtained from the posterior mean mN, 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 x⋆.
Notice that this variance depends on the input through ϕ⋆. The posterior over 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).
The new noise ε⋆ is independent of the posterior uncertainty in F⋆. 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(y⋆∣x⋆,y,Φ,α,β)=N(y⋆∣(ϕ⋆)⊤mN,β−1+(ϕ⋆)⊤SNϕ⋆).
The predictive variance separates into two sources:
total predictive uncertaintyVar(Y⋆∣x⋆,D)=observation uncertaintyβ−1+parameter uncertainty at x⋆(ϕ⋆)⊤SNϕ⋆.
The first term is the irreducible variation assumed by our observation model. Even perfect knowledge of 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 F⋆, its posterior variance is only (ϕ⋆)⊤SNϕ⋆.
If we care about a future noisy target Y⋆, its predictive variance also includes β−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
Where could the curve and target be?inner blue: F* · outer coral: Y*-2-1012-202input xtargetdrag x*At x* = +1.80same mean, different spreadF* · latentY* · future targetpossible valueμ = +1.78
Where could the curve and target be?inner blue: F* · outer coral: Y*-2-1012-202input xtargetdrag x*
distribution at x* ↓
At x* = +1.80same mean, different spreadF* · latentY* · future targetpossible valueμ = +1.78
Query x*·
Latent σ·
Noise σ·
Predictive σ·
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ϕ⋆
is an approximate 95% posterior credible interval for the latent value F⋆. 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 wMAP=mN. The Bayesian and MAP plug-in predictive means agree:
E[Y⋆∣x⋆,D]=(ϕ⋆)⊤mN.
The maximum-likelihood plug-in mean from Section 3 generally differs because wML need not equal mN. More importantly, either plug-in approach discards parameter uncertainty. A MAP plug-in distribution keeps only β−1 in its variance; Bayesian prediction also carries the posterior uncertainty in the weights:
VarBayes(Y⋆∣x⋆,D)=Varplug-in(Y⋆∣x⋆)+(ϕ⋆)⊤SNϕ⋆.
This is why the Bayesian predictive band can widen away from the observations even though the assumed noise variance β−1 is constant. The noise has not increased; the plausible curves disagree more strongly there.
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ϕ⋆
contains approximately 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. The statement is still conditional on our chosen feature map and on the fixed hyperparameters α and β.
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 Yn, Y, and Y⋆ for random targets under the observation model; yn, y, and y⋆ denote realized values. Other uppercase symbols can have different roles: Φ, for example, is a fixed matrix. A hat marks a fitted or estimated quantity.