Gaussian Processes for Machine Learning
A distribution over functions, not just parameters
Most regression methods — linear regression, neural networks — fit a specific functional form with a finite set of parameters. A Gaussian Process (GP) takes a fundamentally different, nonparametric approach: it defines a probability distribution directly over *functions*, such that any finite set of points sampled from a GP follows a joint multivariate Gaussian distribution. Formally, a GP is fully specified by a mean function $m(x)$ (often assumed zero) and a covariance (kernel) function $k(x, x')$ that determines how correlated the function's values are at different input points: $f(x) \sim \mathcal{GP}(m(x), k(x, x'))$.
The kernel encodes assumptions about smoothness
The kernel function $k(x, x')$ is where a GP's modeling assumptions actually live — it determines how much knowing $f$ at one point tells you about $f$ at nearby points. The RBF (squared exponential) kernel, $k(x,x') = \sigma^2 \exp(-\|x-x'\|^2 / 2\ell^2)$, encodes an assumption of smooth, infinitely differentiable functions, with the length-scale $\ell$ controlling how quickly correlation decays with distance. The Matérn kernel offers a tunable smoothness parameter, useful when RBF's extreme smoothness assumption is too strong for the data. Choosing (or learning, via marginal likelihood maximization) a kernel and its hyperparameters is effectively choosing what kinds of functions the GP considers plausible before seeing any data — the kernel plays the role that network architecture plays for a neural network.
import numpy as np
def rbf_kernel(X1, X2, length_scale=1.0, variance=1.0):
sqdist = np.sum(X1**2, 1).reshape(-1, 1) + np.sum(X2**2, 1) - 2 * X1 @ X2.T
return variance * np.exp(-0.5 * sqdist / length_scale**2)
def gp_predict(X_train, y_train, X_test, noise=1e-3, **kernel_args):
K = rbf_kernel(X_train, X_train, **kernel_args) + noise * np.eye(len(X_train))
K_s = rbf_kernel(X_train, X_test, **kernel_args)
K_ss = rbf_kernel(X_test, X_test, **kernel_args)
K_inv = np.linalg.inv(K)
mean = K_s.T @ K_inv @ y_train # posterior mean prediction
cov = K_ss - K_s.T @ K_inv @ K_s # posterior covariance (uncertainty)
return mean, np.sqrt(np.diag(cov)) # mean and per-point std devPredictions come with calibrated uncertainty for free
Gaussian processes vs neural networks
| Property | Gaussian process | Neural network |
|---|---|---|
| Parametric form | Nonparametric — distribution over functions | Fixed parametric function form |
| Uncertainty estimates | Built-in, exact (for a fixed kernel) | Requires separate techniques (ensembles, BNN, etc.) |
| Scaling with data size | O(n³) — poor beyond a few thousand points | Scales to millions/billions of examples |
| Best suited for | Small-to-medium data, need for calibrated uncertainty | Large data, high-dimensional unstructured inputs |
The scaling bottleneck, and sparse approximations
Exact GP inference requires inverting the $n \times n$ kernel matrix, an $O(n^3)$ operation that becomes prohibitive beyond roughly a few thousand training points — a hard practical ceiling that distinguishes GPs sharply from neural networks, which scale (with appropriate hardware) to vastly larger datasets. Sparse GP approximations address this by summarizing the training data with a smaller set of $m \ll n$ inducing points, reducing complexity to roughly $O(nm^2)$ — a substantial improvement that extends practical GP use into larger-data regimes, though still well short of neural-network scale. This scaling limitation is the single biggest reason GPs remain a specialized tool (Bayesian optimization, scientific modeling with limited data, spatial statistics) rather than a general-purpose deep learning replacement.
Where GPs are chosen over the alternatives
GPs are typically chosen specifically when the dataset is small-to-moderate, the input dimensionality is manageable, and calibrated, principled uncertainty genuinely matters more than raw predictive scale — exactly the Bayesian optimization setting covered elsewhere, as well as spatial statistics (kriging), robotics state estimation, and scientific modeling where every data point is expensive to obtain. When data is abundant and uncertainty needs are looser, the scaling and flexibility advantages of neural networks usually win out instead.
What's Next?
Gaussian processes provide calibrated uncertainty through a full generative model of the function; a lighter-weight approach that provides formal coverage guarantees without committing to any particular probabilistic model of the underlying function is conformal prediction.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.