Core ML2006advanced11 min read

Gaussian Processes for Machine Learning

العمليات الغاوسية للتعلم الآلي

Rasmussen, C. E. · Williams, C. K. I. — MIT Press

The problem

Classical parametric models — like linear or neural networks — fix the structure first, then fit parameters. This forces the modeler to guess the right complexity: too simple underfits, too complex overfits. typically relies on , which wastes data. What's needed is a framework that defines a flexible directly over functions, updates it with data via , and provides built-in uncertainty that automatically penalizes unnecessary complexity.

The contribution

Gaussian Processes provide that framework. A GP defines a probability over functions: any finite set of function values follows a multivariate Gaussian, fully specified by a mean function and a () function. The kernel encodes prior beliefs — smoothness, periodicity, length scales — without fixing the number of parameters. Conditioning on observed data yields a GP whose mean is the prediction and whose is the uncertainty. Hyperparameters are tuned by maximizing the , which has a built-in Occam's razor: it automatically balances data fit against model complexity. For regression the posterior is exact and closed-form; for , approximations like Laplace or EP are used.

The impact

GPs became the gold standard for small-data regression with calibrated uncertainty — the go-to method in Bayesian optimization, , geostatistics, and experimental design. Their kernel view unified SVMs, splines, and networks under a single probabilistic roof. The marginal framework influenced model selection across all of . Bayesian optimization — which uses a GP surrogate to tune hyperparameters of neural networks and other expensive functions — is a direct descendant and one of the most widely used tools in modern ML engineering.

A is like a painter who picks one brush before seeing the landscape — if the brush is too broad, details are lost; too fine, and becomes part of the painting.

A is like an orchestra of painters: before seeing the data, every plausible curve plays its instrument. When data arrives, the conductor — Bayes' theorem — silences the instruments that contradict the observations. What remains is a harmony of curves: their average is the prediction, and the volume of remaining instruments at each point tells you exactly how uncertain you should be.

The problem: choosing model complexity before seeing data

In classical , you choose a model family first — say, a polynomial of degree 3 — and then fit its parameters. But why degree 3? A degree-2 polynomial might miss a real curve; degree 10 might memorize noise. The modeler must guess the right complexity, and guessing wrong wastes data (via cross-validation) or produces overconfident predictions.

Neural networks have a similar problem in reverse: they have too many parameters, so regularization techniques are bolted on to prevent . The result works, but provides no principled measure of how uncertain the prediction is.

What if, instead of choosing a fixed model and fitting its finite parameters, we placed a probability distribution directly over functions and let the data tell us which functions are plausible?

Open in Lab
Left: a fixed polynomial must commit to one degree. Right: a GP considers all smooth curves and shows uncertainty (shaded region) where data is sparse.
The demo wakes as you arrive…

Core idea: a distribution over functions

A Gaussian Process is the infinite-dimensional extension of the multivariate Gaussian distribution. Instead of describing the probability of a finite , it describes the probability of an entire function.

The formal definition is elegant: a GP is a collection of random variables, any finite number of which have a joint Gaussian distribution. It is fully specified by two things:

  • A mean function m(x)=E[f(x)]m(x) = \mathbb{E}[f(x)] — your default guess before seeing data (often set to zero).

  • A k(x,x′)=Cov[f(x),f(x′)]k(x, x') = \text{Cov}[f(x), f(x')] — also called the kernel — which encodes how correlated function values at two inputs should be.

Think of the kernel as a ruler: it answers "if I know f(x)f(x), how much does that tell me about f(x′)f(x')?" Nearby inputs get high covariance (so the function is smooth); distant inputs get low covariance (so the function is free to do something different).

f(x)∼GP(m(x),  k(x,x′))f(x) \sim \mathcal{GP}\bigl(m(x),\; k(x, x')\bigr)
A Gaussian Process prior over functions — Any finite collection of function values [f(x₁), f(x₂), …, f(xₙ)] follows a multivariate Gaussian with mean vector [m(x₁), …, m(xₙ)] and covariance matrix Kᵢⱼ = k(xᵢ, xⱼ).
Open in Lab
Each curve is a sample from the GP prior. Click "Sample" to draw new functions — notice they're all smooth, but otherwise unconstrained.
The demo wakes as you arrive…

The kernel: encoding prior beliefs

The kernel function is where domain knowledge enters. Different kernels express different beliefs about the function you expect to see:

  • The Squared Exponential (RBF) kernel k(x,x′)=σ2exp⁡ ⁣(−∥x−x′∥22ℓ2)k(x,x') = \sigma^2 \exp\!\bigl(-\frac{\|x-x'\|^2}{2\ell^2}\bigr) encodes infinitely smooth functions. The length-scale ℓ\ell controls how quickly correlation decays with distance — small ℓ\ell allows rapid wiggles, large ℓ\ell enforces broad trends. The signal variance σ2\sigma^2 controls the vertical scale.

  • The Matérn family allows rougher functions, parameterized by a smoothness ν\nu. At ν=1/2\nu = 1/2 you get an Ornstein-Uhlenbeck process (very rough); at ν→∞\nu \to \infty it converges to the RBF.

  • Periodic kernels model repeating patterns — perfect for seasonal data.

  • Kernels can be composed: adding two kernels mixes their patterns; multiplying creates interactions (e.g., a locally-periodic function that changes amplitude over time).

kSE(x,x′)=σ2exp⁡ ⁣(−∥x−x′∥22ℓ2)k_{\text{SE}}(x, x') = \sigma^2 \exp\!\Bigl(-\frac{\|x - x'\|^2}{2\ell^2}\Bigr)
Squared Exponential (RBF) kernel — σ² = signal variance (vertical scale) · ℓ = length-scale (horizontal reach of correlation) · The two hyperparameters fully control how smooth and how tall the functions are.
Open in Lab
Switch between kernel types and adjust hyperparameters to see how they shape the GP prior. Each button draws new samples from that kernel.
The demo wakes as you arrive…

GP regression: from prior to posterior

The magic happens when data arrives. Suppose we observe nn points {(xi,yi)}\{(x_i, y_i)\} where yi=f(xi)+εy_i = f(x_i) + \varepsilon and ε∼N(0,σn2)\varepsilon \sim \mathcal{N}(0, \sigma_n^2) is observation noise. We want the posterior distribution p(f∗∣X,y,x∗)p(f_* | X, y, x_*) at a new test input x∗x_*.

Because everything is Gaussian, the posterior is also Gaussian — and we can write its mean and variance in closed form. The predictive mean is a weighted combination of training outputs, where the weights come from the kernel. The predictive variance is large far from training data and shrinks near observed points.

This is the key insight: the GP gives you error bars for free. No , no ensemble of models — the uncertainty is a natural output of the Bayesian update.

fˉ∗=K(x∗,X) [K(X,X)+σn2I]−1 y\bar{f}_* = K(x_*, X)\,[K(X,X) + \sigma_n^2 I]^{-1}\,y
GP predictive mean — A Gaussian Process makes predictions by combining information from all observed training examples. Training points that are more similar to the query point receive greater influence, while distant or unrelated points contribute less. The prediction can therefore be viewed as a weighted average of known observations, with the weights determined by the chosen similarity function and adjusted to account for noise in the data.
Var(f∗)=k(x∗,x∗)−K(x∗,X) [K(X,X)+σn2I]−1 K(X,x∗)\text{Var}(f_*) = k(x_*, x_*) - K(x_*, X)\,[K(X,X) + \sigma_n^2 I]^{-1}\,K(X, x_*)
GP predictive variance — Uncertainty = prior variance minus the variance "explained" by training data. Near training points the second term is large, so uncertainty shrinks. Far away, it returns to the prior.
Open in Lab
Click to add data points. The GP posterior updates instantly — the blue line is the mean, the shaded band is ±2 standard deviations (95% confidence).
The demo wakes as you arrive…

Model selection: the automatic Occam's razor

How do you choose the right kernel and its hyperparameters (like the length-scale ℓ\ell)? GPs have a principled answer: maximize the marginal likelihood — the probability of the observed data after integrating out the function.

The log marginal likelihood decomposes into three terms. Think of it as a scoring system:

  • Data fit: how well the model explains the training data (wants complex models).

  • Complexity penalty: how much "volume" the model assigns to functions that don't match the data (penalizes complex models).

  • Normalization constant: a fixed term.

The fit term rewards models that pass near the data. The complexity term penalizes models that spread probability over too many functions. Together they implement an automatic Occam's razor: the simplest model that explains the data wins.

log⁡p(y∣X,θ)=−12y⊤Ky−1y−12log⁡∣Ky∣−n2log⁡2π\log p(y|X,\theta) = -\tfrac{1}{2}y^\top K_y^{-1} y - \tfrac{1}{2}\log|K_y| - \tfrac{n}{2}\log 2\pi
Log marginal likelihood — the GP's built-in model selection criterion — First term = data fit · Second term = complexity penalty (log determinant of covariance) · Third term = normalization. Kᵧ = K(X,X) + σₙ²I.
Open in Lab
Drag the length-scale slider. Too short → overfits (high data-fit, high penalty). Too long → underfits (low data-fit, low penalty). The marginal likelihood peaks at the right balance.
The demo wakes as you arrive…

GP classification: when the output is a label

For classification, the output is a class label, not a continuous value. The GP models a latent function f(x)f(x) that is then squashed through a (for binary) or (for multi-class) to produce class probabilities.

The challenge is that the sigmoid breaks the Gaussian conjugacy — the posterior over ff is no longer Gaussian. Two main approximations are used:

  • Laplace approximation: fit a Gaussian to the posterior by finding the mode and using the local curvature () to define the spread. Fast but can be inaccurate for skewed posteriors.

  • Expectation Propagation (EP): iteratively refines local Gaussian approximations at each data point. More accurate than Laplace, especially for small datasets.

Despite the approximation, GP classifiers provide calibrated uncertainty — they say "I'm 60% sure this is class A" rather than forcing a hard decision.

Connections: SVMs, neural networks, and splines

One of the book's deepest contributions is showing that GPs are not an isolated technique but a unifying perspective:

  • SVMs are GPs without uncertainty. The SVM solution is the MAP (maximum a posteriori) estimate of a GP — the single most probable function. The GP adds the full posterior: not just the best guess, but the distribution around it.

  • Infinite neural networks are GPs. Neal (1996) showed that a single-layer with infinitely many hidden units converges to a GP. The kernel is determined by the prior and the . This connection has been revived in the Neural Tangent Kernel theory.

  • Splines are GP MAP estimates. Cubic smoothing splines are the MAP solution of a GP with a specific kernel. Regularization networks and RBF networks also emerge as special cases.

This unification means insights from one field transfer to others — kernel design in SVMs informs GP priors, and GP enriches neural network predictions.

Open in Lab
Same kernel, same data. Left: SVM gives a hard decision boundary. Right: GP gives class probabilities with smooth uncertainty gradients.
The demo wakes as you arrive…

The scalability challenge: O(n³) and how to tame it

The elephant in the room: GP regression requires inverting the n×nn \times n covariance , which costs O(n3)O(n^3) time and O(n2)O(n^2) memory. For 10,000 points this is manageable; for millions, it's prohibitive.

Several approximation strategies have been developed:

  • Sparse / inducing-point methods: pick m≪nm \ll n representative "inducing points" and approximate the full GP through them. Reduces cost to O(nm2)O(nm^2). FITC and variational methods (Titsias 2009) are popular choices.

  • Structured kernels: if the data lies on a grid, Kronecker and Toeplitz structure in the covariance matrix enables O(nlog⁡n)O(n \log n) computations.

  • Random features: approximate the kernel with a finite-dimensional map (Rahimi & Recht 2007), turning the GP into a Bayesian linear regression in feature space.

These approximations have made GPs practical for datasets of hundreds of thousands of points, though neural networks remain the tool of choice for truly massive datasets.

The same idea in code

GP regression from scratch — predict mean and uncertaintypython

Simplified to show the idea — not the real implementation.

import numpy as np

def rbf_kernel(X1, X2, length_scale=1.0, signal_var=1.0):
    """Squared Exponential kernel: k(x,x') = σ² exp(-||x-x'||²/2ℓ²)"""
    sq_dist = np.sum(X1**2, 1).reshape(-1,1) + np.sum(X2**2, 1) - 2*X1@X2.T
    return signal_var * np.exp(-0.5 * sq_dist / length_scale**2)

def gp_predict(X_train, y_train, X_test, noise=0.1, l=1.0, sv=1.0):
    """GP regression: returns predictive mean and variance."""
    K = rbf_kernel(X_train, X_train, l, sv) + noise**2 * np.eye(len(X_train))
    K_s = rbf_kernel(X_train, X_test, l, sv)
    K_ss = rbf_kernel(X_test, X_test, l, sv)

    # Solve K⁻¹y via Cholesky (numerically stable)
    L = np.linalg.cholesky(K)
    alpha = np.linalg.solve(L.T, np.linalg.solve(L, y_train))

    # Predictive mean: weighted sum of training labels
    mu = K_s.T @ alpha

    # Predictive variance: prior minus explained
    v = np.linalg.solve(L, K_s)
    var = np.diag(K_ss) - np.sum(v**2, axis=0)

    return mu, var  # mean prediction + calibrated uncertainty

# That's it. The GP gives you predictions AND error bars.
# Bayesian optimization uses exactly this to decide where to sample next.

Why it mattered

  1. 1996

    Neal links neural networks to GPs

    Radford Neal proves that a Bayesian neural network with infinitely many hidden units converges to a Gaussian process. First deep bridge between the two paradigms.

  2. 2006

    GPML textbook published

    Rasmussen & Williams publish the definitive reference, unifying GPs with SVMs, splines, and regularization networks under one Bayesian framework.

  3. 2012

    Bayesian optimization goes mainstream

    Snoek, Larochelle & Adams show that GP-based Bayesian optimization outperforms manual tuning and grid search for neural network hyperparameters.

  4. 2018

    Neural Tangent Kernel

    Jacot et al. show that infinitely-wide neural networks trained by gradient descent behave exactly like GPs — reviving Neal's connection in the deep learning era.

  5. 2020

    GPyTorch & scalable GPs

    Modern libraries exploit GPU acceleration and inducing-point methods, making GPs practical for datasets with hundreds of thousands of points.

The GP framework gave machine learning a language for uncertainty that parametric models lacked. Bayesian optimization — the most direct descendant — uses a GP surrogate to answer the question every engineer asks: "where should I experiment next?" That question, and the principled Bayesian answer GPs provide, is why this book remains essential reading two decades after publication.

CitationRasmussen, Williams. Gaussian Processes for Machine Learning. MIT Press, 2006.

Terms in this paper