Skip to content
mlmentorship

Gaussian processes

A distribution over functions defined by a mean and covariance kernel. Predicts a mean and kernel-conditional uncertainty. Beautiful theory, brutal scaling.

Published · 5 min read ·Role-specific ·Intermediate

Visual quick review

Visual first · depth when needed

Explain how kernel similarity to observed inputs simultaneously shapes a Gaussian process posterior mean and reduces posterior function uncertainty at a query location.

Preparing the visual…

Summary

A Gaussian process (GP) places a prior over functions such that any finite collection of values is jointly Gaussian. The GP is fully specified by a mean function (usually 0) and a covariance kernel .

GPs are the canonical Bayesian regression model. They give a closed-form posterior over functions, with a predictive mean and a predictive variance per query point. Under a suitable, well-specified kernel, that variance can be calibrated and returns toward the prior variance as kernel similarity to the observations falls. This makes GPs a standard tool for Bayesian optimization, active learning, and settings where uncertainty quantification matters as much as the prediction.

The cost is brutal scaling: exact inference. GPs are practical up to a few thousand training points without approximation; modern variants (sparse, structured kernel, deep kernel) push that to millions.

The mechanism

For training inputs , training targets , test point , prior covariance kernel , and noise variance :

The joint distribution is

where , is the vector of , and .

Conditioning on training data gives the Gaussian posterior:

Learning objective

See how kernel similarity makes observations reshape both the posterior mean and uncertainty.

Gaussian process posterior mean and uncertainty around three observations A horizontal input axis contains three observed points. A solid posterior mean bends through their neighborhood. A shaded uncertainty band is narrow near each observation and broad at the left and right edges, where there is little kernel similarity to the training inputs. Labels connect the narrow regions to a large covariance correction subtracted from prior variance and the broad regions to a near-zero correction. OUTPUT f(x) INPUT x posterior mean μ(x) posterior uncertainty OBSERVED INPUTS near X large k* → large subtraction → narrow far from X k* ≈ 0 → prior width remains
Read it this way: start at a query location and ask how similar it is to the observed inputs. Nearby, the covariance vector k* is large: observations pull the mean and the subtracted correction in Σ(x*) removes much of the prior uncertainty. Far away, k* approaches zero, so the mean relaxes toward the prior and the uncertainty band widens toward the prior variance. This behavior is conditional on the chosen kernel; it is not a universal guarantee of calibration. Original schematic checked against Rasmussen and Williams (2006).

Two matrix-vector products against give you both the predictive mean and the predictive variance at any test point. The hard part is , which costs to compute and to store.

Choosing the kernel

The kernel encodes prior beliefs about the function:

  • RBF / squared exponential: . Smooth functions, infinite differentiability. Default.
  • Matern: lets you tune smoothness via a half-integer parameter . is a common modern default; smoother than , less restrictive than RBF.
  • Periodic: . For periodic data.
  • Linear: . Recovers Bayesian linear regression.
  • Sums and products of valid kernels are valid kernels. Add a periodic and an RBF for “trend plus seasonality.”

Hyperparameters (lengthscale , variance , noise ) are typically learned by maximizing the marginal likelihood:

Scaling: sparse and approximate variants

  • Inducing points (Snelson & Ghahramani, 2005). Pick inducing inputs, approximate via a low-rank decomposition. training, prediction.
  • SVGP (Hensman et al., 2013). Variational inference over inducing point values. Stochastic mini-batch training. The standard for large-data GPs.
  • KISS-GP / structured kernels (Wilson & Nickisch, 2015). Exploit grid structure for inference.
  • Deep kernels. Replace with where is a neural network. Combines deep features with kernel-conditional uncertainty.

Where GPs are still the right tool

  • Bayesian optimization of expensive functions (hyperparameter search, materials discovery, drug design). The acquisition function uses the posterior variance to balance exploration and exploitation.
  • Geospatial / time-series modeling with structured covariance (kriging is just a GP).
  • Small-data regression where calibrated uncertainty matters more than predictive accuracy.
  • Probabilistic numerics (treat numerical algorithms as Bayesian inference).

For most large-scale supervised learning, deep nets with bootstrapping or deep ensembles deliver competitive uncertainty estimates at much better scaling.

Common pitfalls

  • Using RBF without setting the lengthscale. Default lengthscale produces nearly-flat predictions or wildly oscillating ones. Always optimize.
  • Ignoring the noise term . Without it, is often singular and inversion fails. Add a small jitter even for noiseless data.
  • Reading posterior variance as “model uncertainty.” GP variance is uncertainty in the function value given the kernel and the prior. Misspecified kernels give miscalibrated variance.
  • Treating GPs as automatic. Kernel choice is a strong prior. The model can fail silently if the kernel does not match the data structure.