GPflow

raw JSON →
2.10.0 verified Sat May 09 auth: no python

GPflow is a Gaussian process library in TensorFlow, designed for GP regression and advanced GP models. It provides a flexible, composable framework for building and training GP models using TensorFlow's automatic differentiation. Current version 2.10.0 targets TensorFlow 2.x and has a moderate release cadence (major/minor roughly every few months).

pip install gpflow
error AttributeError: module 'gpflow' has no attribute 'kernels'
cause GPflow 2.x lazy-loads submodules; you must import them explicitly.
fix
Use from gpflow import kernels instead of import gpflow.kernels.
error TypeError: Expected float64, got float32
cause GPflow defaults to float64; TensorFlow may produce float32 from default settings.
fix
Cast input data: tf.cast(X, tf.float64) or set global default to float64.
breaking GPflow 2.x is a major rewrite with breaking changes from 1.x. The API, module structure, and TensorFlow version requirements (TF 2.x) are different. Models built for GPflow 1.x will not work without modification.
fix Migrate code: use `from gpflow import ...` (not `import gpflow as gp` submodules), replace `gpflow.kernels.RBF` with `gpflow.kernels.SquaredExponential`, and update to TF 2.x.
deprecated GPflow 2.10.0 still supports TensorFlow 2.x, but future versions may require TensorFlow 2.10+ or higher. Check compatibility matrix.
fix Keep TensorFlow updated and pin versions if needed.
gotcha When using `gpflow.models.GPR` (or other models), the training loss is a TensorFlow tensor, not a scalar. Use `.numpy()` to get a Python float if needed.
fix Call `m.training_loss.numpy()` to get the value as a float.

Basic GP regression with GPflow: create data, build GPR model with SquaredExponential kernel, optimise hyperparameters, and predict.

import gpflow
import numpy as np
import tensorflow as tf

# Create synthetic data
X = np.random.randn(20, 1)
Y = np.sin(X) + 0.1 * np.random.randn(20, 1)

# Build model
k = gpflow.kernels.SquaredExponential()
m = gpflow.models.GPR(data=(X, Y), kernel=k, noise_variance=1.0)

# Optimise
opt = gpflow.optimizers.Scipy()
opt.minimize(m.training_loss, m.trainable_variables)

# Predict
Xtest = np.linspace(-3, 3, 100)[:, None]
mean, var = m.predict_f(Xtest)
print("Predictions:", mean.numpy().flatten()[:5])