Gaussian processes: smooth predictions that know where they're guessing
A Gaussian process learns a smooth function from a kernel and reports an SD for every prediction. Read its lengthscale and noise, let the marginal likelihood fit them, and check the intervals it promises.
What runs in CodeSplash
- Gaussian process Verified in Python and R
You will be able to
- Say what a kernel, a lengthscale and a noise SD mean for a Gaussian process
- Explain why the predictive SD grows away from the training rows
- Fit kernel settings by the marginal likelihood and read the result
- Check a model's intervals with conformal coverage and its Wilson interval
A prior over functions
ReadMost learners pick one function. A Gaussian process keeps every smooth function in play and weighs them by how well they explain the training rows. The kernel says how similar the function's values are at two rows: close rows, similar values.
| Setting | What it controls |
|---|---|
| Lengthscale | How far apart rows can be before their values stop being alike |
| Signal SD | How far the function moves from its mean |
| Noise SD | How far the rows scatter around the function |
The kernel's shape sets the smoothness. Matérn 5/2 (the default) allows bends; Radial basis is smoother still; Matérn 3/2 is rougher; Rational quadratic mixes many lengthscales.
Where is it guessing?
PredictPredict first
A Gaussian process was trained on temperatures between 60 and 95 °F. How wide is its predictive interval at 110 °F?
Reveal
Wider. Far from every training row, the kernel says nothing ties the function down, so the SD falls back to the signal SD plus the noise. Near the data it shrinks toward the noise SD alone.
Fitting the kernel settings
ReadYou don't have to guess the lengthscale. Fit kernel settings to the data maximizes the log marginal likelihood: how probable the targets are with the function averaged out. It trades fit against wiggliness on its own, without a validation split.
Ozone from solar radiation, wind, temperature and month (Matérn 5/2):
| Value | |
|---|---|
| Lengthscale (standardized features) | 2.95 |
| Noise SD (ppb) | 17.0 |
| Log marginal likelihood | −86.3 |
| Cross-validated RMSE | 20.0 |
| 90% predictive intervals covering held-out rows | 0.873 |
The likelihood can have more than one peak. The fit starts from one fixed place, so if you suspect another answer, refit from a different starting Lengthscale and keep the run with the higher log marginal likelihood.
One lengthscale per feature
ReflectOne lengthscale per feature (ARD) fits a separate lengthscale for each design column. A short one means the predictions change quickly along that feature. With the radial basis kernel on three features, the lengthscale for temperature is 1.88 and for wind 1.36. The importance table shows 1/lengthscale, scaled to sum to 1.
ARD adds one setting per feature. With few rows, does the extra flexibility find the relevant features, or does it fit noise? Compare its cross-validated score with the shared lengthscale before you trust it.
Binary targets and large tables
ReadFor a yes/no target the function lives on the log-odds scale and passes through a logistic link. The posterior is no longer normal, so CodeSplash uses the Laplace approximation: a normal centered on the most probable function. On the Pima diabetes data the cross-validated ROC AUC is 0.855.
The cost grows with the cube of the training rows. Above Most training rows (1,000 by default), the model is fitted on that many evenly spaced rows and every row is still predicted. The result says so.
Do the intervals keep their promise?
ReadA Gaussian process's intervals assume its kernel and normal noise are right. The Uncertainty tab checks that from out-of-fold rows with conformal prediction, and every coverage now comes with a 95% Wilson interval: 88% coverage on 50 test rows is consistent with a 90% promise, while 88% on 5,000 rows isn't.
For conformalized quantile regression, When the quantiles cross decides what happens to rows whose lower-quantile prediction lands above the upper one: keep them as they are, or sort the two first.
Check your understanding
CheckpointCheck yourself
A Gaussian process with one lengthscale per feature fits a lengthscale of 0.4 for age and 40 for region. What does that say?
Show the answer
Answer: a
A long lengthscale means the function is nearly flat along that feature. Short lengthscales mark the features the predictions depend on.
Check yourself
Two fits from different starting lengthscales end with log marginal likelihoods of −512 and −498. Which do you keep?
Show the answer
Answer: b
Kernel settings are fitted by maximizing the log marginal likelihood, so the higher value is the better fit of the same model to the same rows.
Check yourself
The Uncertainty tab reports 86.0% test coverage for 90% intervals, with a 95% Wilson interval of 79.1–91.0%. What do you conclude?
Show the answer
Answer: b
The Wilson interval shows what the test set can resolve. It includes 90%, so these rows don't show under-coverage.
Set it up
In the appIn Predict, choose Gaussian process among the learners. Kernel, One lengthscale per feature (ARD) and Fit kernel settings to the data are in the model settings; the starting values and Most training rows are under the advanced ones. The run's Uncertainty tab checks the intervals.
import numpy as np
import pandas as pd
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel, Matern, WhiteKernel
from sklearn.preprocessing import StandardScaler
df = pd.read_csv("airquality.csv").dropna(subset=["Ozone", "Solar.R"])
X = StandardScaler().fit_transform(df[["Solar.R", "Wind", "Temp", "Month"]])
kernel = ConstantKernel(1.0) * Matern(length_scale=2.0, nu=2.5) + WhiteKernel(0.09)
gp = GaussianProcessRegressor(kernel, normalize_y=True).fit(X, df["Ozone"])
mean, sd = gp.predict(X[:5], return_std=True)
print(gp.kernel_, np.round(mean, 1), np.round(sd, 1))library(DiceKriging)
df <- na.omit(read.csv("airquality.csv")[, c("Ozone", "Solar.R", "Wind", "Temp", "Month")])
X <- scale(df[, -1])
fit <- km(design = data.frame(X), response = df$Ozone, covtype = "matern5_2", nugget.estim = TRUE)
p <- predict(fit, newdata = data.frame(X[1:5, ]), type = "UK")
round(cbind(mean = p$mean, sd = p$sd), 1)Recap
Recap- A Gaussian process predicts a mean and an SD for every row; the SD grows away from the data.
- Lengthscale, signal SD and noise SD are fitted by the log marginal likelihood; refit from another start if in doubt.
- ARD lengthscales show which features matter; binary targets use the Laplace approximation.
- Check the intervals in the Uncertainty tab, and read coverage with its Wilson interval.
Concepts in this lesson