liveBook · Manning

Linear regression

As explained in Bayesian Optimization in Action

Linear regression is a model that represents a response as a linear combination of input features and fitted coefficients.

Linear regression represents a prediction as a weighted combination of input features plus a bias: μ = wᵀx + b. The weights encode each feature’s influence, while the bias shifts the prediction. With one feature such as living area, a positive weight makes predicted housing price rise as area increases. section 3.3.3

As a mean model, linear regression supplies an expected trend before observations are incorporated. A Gaussian process can then model uncertainty around that trend, combining the predictive power of a linear model with uncertainty quantification. A constant mean is the special case w = 0. section 3.2 section 3.3.3

The model is useful when the expected response is plausibly related to features through a linear combination:

  • Define the feature vector x, coefficient vector w, and bias b. section 3.3.3
  • Fit the coefficients so the resulting line or hyperplane follows the observed targets. section 3.3.3
  • Use a linear mean to impose an upward or downward trend, while a covariance model controls additional variability and smoothness. section 3.2 section 3.3.3

Housing prices and structured targets

For housing, living area is the feature and price is the response; a positive coefficient predicts higher prices for larger homes. The same regression framing can treat MNIST digit labels as continuous targets, or predict ad-click probability, molecular energy, or drug effectiveness. section 3.3.3 section 13.1

class LinearMeanGPModel(gpytorch.models.ExactGP):
    def __init__(self, train_x, train_y, likelihood):
        super().__init__(train_x, train_y, likelihood)
        self.mean_module = gpytorch.means.LinearMean(1)    #1
        self.covar_module = gpytorch.kernels.RBFKernel()

A compact GPyTorch model shows how to replace a constant mean with LinearMean and retain an RBF covariance module. section 3.3.3

How Bayesian Optimization in Action covers it

How deep it goes
Defines μ = wᵀx + b, explains coefficient roles and special cases, and demonstrates implementation without deriving coefficient fitting.
Examples
Uses housing prices, MNIST digit labels, advertising clicks, molecular energy, and drug effectiveness as regression targets.
What it assumes
Assumes feature vectors and target labels, while introducing coefficient weights, bias, and the linear prediction equation.
What you can do after
Build it from scratch with GPyTorch by configuring LinearMean and pairing it with a covariance module.
How it connects
Connects linear regression with Gaussian processes, mean functions, covariance functions, gradient descent, and uncertainty quantification.

Also explained in

Compare how 22 books explain linear regression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bayesian Optimization in Action. The section links point to the parts of the book it draws on.