No history yet

Frequentist vs Bayesian

Beyond a Single Best Line

In linear regression, we often start with a familiar goal: find the single straight line that best fits our data. This method, known as (OLS), gives us one set of coefficients—one slope and one intercept—that minimize the squared distance between the line and the data points. This is a point estimate. It's clean, simple, and often very effective. But it has a crucial limitation: it communicates no uncertainty. It gives us the 'best' answer without telling us how confident we should be in that answer.

What if, instead of asking for the one best line, we asked for a probability distribution over all possible lines? This shift in perspective is the core of Bayesian linear regression. We move from finding a single point to describing a landscape of possibilities. Instead of one answer, we get a range of plausible answers, each with a probability attached. This approach acknowledges that our data is finite and noisy, so our estimate of the model's parameters should reflect that uncertainty.

This probabilistic viewpoint requires us to think about two key ingredients: the likelihood and the prior.

Likelihood and Priors

The asks: given a particular set of weights (a specific line), what is the probability of observing our actual data? For linear regression, we typically assume the errors, or residuals, are drawn from a Gaussian (normal) distribution with a mean of zero. Therefore, the likelihood is the product of the probabilities of each data point, assuming they were generated by a line plus some Gaussian noise.

L(βy,X)=P(yX,β)=i=1n12πσ2e(yixiTβ)22σ2\mathcal{L}(\beta | y, X) = P(y | X, \beta) = \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(y_i - x_i^T\beta)^2}{2\sigma^2}}

The frequentist approach of Maximum Likelihood Estimation (MLE) stops here. It finds the parameters β\beta that maximize this likelihood function. It turns out that for linear regression, maximizing this likelihood is equivalent to minimizing the sum of squared errors—giving you the same result as OLS.

Maximizing the likelihood is the same as maximizing its logarithm, which is often easier mathematically. This is called the log-likelihood.

The Bayesian approach, pioneered by Thomas Bayes, introduces the second ingredient: the prior distribution, P(β)P(\beta). The prior is a probability distribution that represents our beliefs about the parameters before we see any data. It's where we can incorporate domain knowledge or a preference for simpler models. For example, we might start with a prior belief that the regression weights are likely to be small and centered around zero.

Lesson image

By combining the prior with the likelihood using Bayes' theorem, we get the posterior distribution, P(βy,X)P(\beta | y, X).

P(βy,X)=P(yX,β)P(β)P(yX)P(\beta | y, X) = \frac{P(y | X, \beta) P(\beta)}{P(y | X)}

Since the denominator, P(yX)P(y|X), doesn't depend on β\beta, we often work with the proportional relationship:

Posterior ∝ Likelihood × Prior

MLE vs. MAP

This brings us to the core difference in estimation. The frequentist approach uses Maximum Likelihood Estimation (MLE), while a common Bayesian estimation method is Maximum A Posteriori (MAP).

MethodGoalFormula to MaximizeResult
MLEFind the parameters that make the observed data most probable.L(β)=P(yX,β)\mathcal{L}(\beta) = P(y \| X, \beta)A single point estimate.
MAPFind the most probable parameters given the data and our prior beliefs.P(yX,β)P(β)P(y \| X, \beta) P(\beta)A single point estimate (but influenced by the prior).

Notice that MAP is like MLE with an extra term: the prior. This prior acts as a regularizer. For example, if we use a Gaussian prior for our weights centered at zero, the MAP estimate becomes equivalent to Ridge Regression. The prior effectively penalizes large weights, helping to prevent overfitting.

While MAP provides a single point estimate, the true power of the Bayesian approach lies in using the entire posterior distribution. Instead of just one line, we have a whole family of lines, which gives us a credible interval for our predictions and a richer understanding of the model's uncertainty.

Quiz Questions 1/5

What is the primary conceptual shift when moving from Ordinary Least Squares (OLS) linear regression to Bayesian linear regression?

Quiz Questions 2/5

In the Bayesian framework, what does the prior distribution, P(β)P(\beta), represent?

This shift from point estimates to distributions is a fundamental change in how we think about modeling. It forces us to be explicit about our assumptions and provides a complete picture of what our model has learned from the data.