GaussianProcessClassifier
Bayesian Gaussian Process classification using Laplace approximation for binary tasks and One-vs-Rest for multiclass tasks.
Overview
GaussianProcessClassifier implements probabilistic Gaussian Process (GP) classification using Newton-based Laplace approximation for binary classification and One-vs-Rest (OvR) decomposition for multiclass classification. It supports optional Nelder-Mead hyperparameter optimization via log marginal likelihood (LML) and produces well-calibrated posterior class probabilities. (^▽^)
Backend Support
- Primitives:
N3(pairwise_l2_sqfor RBF, Matern, and Rational Quadratic kernels),N2(elementwise_op),E1(matvec/matmul) - Devices:
cpu(Rayon parallelf64),cuda/cuda:0(dynamic cuBLAS),wgpu(Vulkan/Metal/DX12),tpu(OpenXLA PJRT), andauto - Persistence:
.ditbinary format viasave()/load()(andochreml.save()/ochreml.load()), plus Pythonpicklesupport
Import & Signature
from ochreml.gaussian_process import GaussianProcessClassifier
# Also available from top-level: from ochreml import GaussianProcessClassifier
GaussianProcessClassifier(
kernel: str | dict | Any | None = "rbf",
length_scale: float = 1.0,
constant_value: float = 1.0,
nu: float = 1.5,
noise_level: float = 1.0,
rq_alpha: float = 1.0,
max_iter_predict: int = 100,
optimize_hyperparams: bool = False,
n_restarts_optimizer: int = 0,
random_state: int | None = None,
device: str | None = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
kernel | str, dict, or None | "rbf" | Kernel specification: "rbf", "matern", "white", "rational_quadratic", or "rbf_white". Also accepts a dict or kernel-like object with matching attributes. |
length_scale | float | 1.0 | Length scale of the covariance kernel (length_scale > 0). |
constant_value | float | 1.0 | Constant variance scaling factor of the kernel (constant_value > 0). |
nu | float | 1.5 | Smoothness parameter for the Matern kernel (0.5, 1.5, or 2.5). |
noise_level | float | 1.0 | Noise variance for "white" and "rbf_white" kernels (noise_level > 0). |
rq_alpha | float | 1.0 | Scale mixture parameter for "rational_quadratic" kernel (rq_alpha > 0). |
max_iter_predict | int | 100 | Maximum number of Newton iterations used to find the mode during Laplace approximation. |
optimize_hyperparams | bool | False | Whether to optimize kernel hyperparameters via Nelder-Mead maximization of the log marginal likelihood. |
n_restarts_optimizer | int | 0 | Number of random restarts for the hyperparameter optimizer. |
random_state | int | None | None | Random seed used for optimizer restarts. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
classes_ | ndarray of shape (n_classes,) | Sorted unique class labels seen during fit(). |
n_classes_ | int | None | Number of distinct classes in the training set. |
log_marginal_likelihood_value_ | float | None | Log marginal likelihood of the fitted hyperparameters. |
n_features_in_ | int | None | Number of features seen during fit(). |
device_ | str | None | Resolved execution device string. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y) -> GaussianProcessClassifier | Fit the Gaussian Process classification model on (X, y). |
predict | predict(X) -> ndarray | Predict class labels for samples in X. |
predict_proba | predict_proba(X) -> ndarray | Return posterior class probabilities of shape (n_samples, n_classes). |
log_marginal_likelihood | log_marginal_likelihood() -> float | Return the log marginal likelihood of the fitted model. |
score | score(X, y) -> float | Return mean classification accuracy on (X, y). |
to | to(device) -> GaussianProcessClassifier | Move the estimator's compute target to another device. |
save | save(path) -> None | Save the fitted model to a .dit binary file. |
load | GaussianProcessClassifier.load(path, device=None) -> GaussianProcessClassifier | Class method to load a fitted model from a .dit file. |
Example
import numpy as np
from ochreml.gaussian_process import GaussianProcessClassifier
X_train = np.array([
[-2.0, -1.5],
[-1.5, -2.0],
[-1.0, -1.0],
[1.0, 1.0],
[1.5, 2.0],
[2.0, 1.5],
], dtype=np.float64)
y_train = np.array([0, 0, 0, 1, 1, 1], dtype=np.float64)
gpc = GaussianProcessClassifier(kernel="rbf", length_scale=1.0, random_state=42)
gpc.fit(X_train, y_train)
X_test = np.array([[-1.2, -1.2], [1.2, 1.4]], dtype=np.float64)
print("Predictions:", gpc.predict(X_test))
print("Probabilities:", gpc.predict_proba(X_test))
print("Accuracy:", gpc.score(X_train, y_train))
print("LML:", gpc.log_marginal_likelihood())GaussianProcessRegressor
Bayesian Gaussian Process regression with Cholesky factorization, predictive uncertainty, and Nelder-Mead LML optimization.
Scalers & Normalizers
Hardware-accelerated feature scaling and sample normalization in ochreml.preprocessing (StandardScaler, MinMaxScaler, MaxAbsScaler, RobustScaler, Normalizer).