22.4. Scikit-learn demo notebooks#
The Gaussian Process for Machine Learning page on the scikit-learn website is a great source of code and documentation and examples for GPs.
Here we have adapted their demonstration notebooks for:
Gaussian Processes regression: basic introductory example. Compares noise-free (interpolation) and noisy (regression) for a one-dimensional function (which can be easily changed). An RBF kernel is the default, but this is exchangeable for any of the standard sklearn kernels. A maximum likelihood fit determines the hyperparameters (so it might fail to find a good solution, but the hyperparameter values are given so this can be diagnosed).
Illustration of prior and posterior Gaussian process for different kernels. This example illustrates the prior and posterior of the Scikit-learn class
GaussianProcessRegressorwith different kernels. Mean, standard deviation, and 5 samples are shown for both prior and posterior distributions.
We also have additional demo notebooks
Gaussian Process Regression, which builds an RBF-based kernel (with signal scale and noise term), fits the GP on a subset (e.g., every 3rd point), predicts mean and uncertainty on a target grid or the full input, plots mean Β±2Ο and data, and computes simple validation metrics.
Exercise: Gaussian Processes, which build RBF kernels with signal variance and length-scale, fit GaussianProcessRegressor with a white-noise term, predict posterior mean and uncertainty, plot mean Β±2Ο and data, examine setting hyperparameters explicitly vs. optimizing by LML.
Gaussian Processes Exercises, which build RBF kernels and visualize samples, fit a GP to 1D data (train/test split), plot the posterior mean and Β±2Ο band, apply the workflow to a small dataset.