Implementation:Scikit learn Scikit learn GaussianProcessClassifier
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Gaussian Processes, Classification |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete implementation of Gaussian Process Classification (GPC) provided by scikit-learn.
Description
The GaussianProcessClassifier implements Gaussian process classification based on Laplace approximation. For binary classification, it uses _BinaryGaussianProcessClassifierLaplace internally. For multiclass problems, it wraps the binary classifier using either one-vs-rest or one-vs-one strategies. The kernel hyperparameters are optimized during fitting via L-BFGS-B. The module provides both class predictions and calibrated probability estimates.
Usage
Use Gaussian Process Classification when you need probabilistic predictions with uncertainty estimates, particularly for small to medium-sized datasets. GPC provides well-calibrated class probabilities and works well when the kernel captures the underlying data structure.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/gaussian_process/_gpc.py
Signature
class _BinaryGaussianProcessClassifierLaplace(BaseEstimator):
def __init__(self, kernel=None, *, optimizer="fmin_l_bfgs_b",
n_restarts_optimizer=0, max_iter_predict=100,
warm_start=False, copy_X_train=True, random_state=None):
...
class GaussianProcessClassifier(ClassifierMixin, BaseEstimator):
def __init__(self, kernel=None, *, optimizer="fmin_l_bfgs_b",
n_restarts_optimizer=0, max_iter_predict=100,
warm_start=False, copy_X_train=True, random_state=None,
multi_class="one_vs_rest", n_jobs=None):
...
def fit(self, X, y):
...
def predict(self, X):
...
def predict_proba(self, X):
...
def log_marginal_likelihood(self, theta=None, eval_gradient=False, clone_kernel=True):
...
Import
from sklearn.gaussian_process import GaussianProcessClassifier
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| X | array-like of shape (n_samples, n_features) | Yes | Training input samples |
| y | array-like of shape (n_samples,) | Yes | Target class labels |
| kernel | Kernel instance | No | Covariance function (default: 1.0 * RBF(1.0)) |
| optimizer | str or callable | No | Optimizer for kernel hyperparameters |
| n_restarts_optimizer | int | No | Number of optimizer restarts |
| multi_class | str | No | Multiclass strategy: "one_vs_rest" or "one_vs_one" |
Outputs
| Name | Type | Description |
|---|---|---|
| predictions | ndarray of shape (n_samples,) | Predicted class labels |
| probabilities | ndarray of shape (n_samples, n_classes) | Class probability estimates |
| log_marginal_likelihood_value_ | float | Log marginal likelihood of the fitted model |
| kernel_ | Kernel | Optimized kernel with fitted hyperparameters |
Usage Examples
Basic Usage
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.gaussian_process.kernels import RBF
from sklearn.datasets import make_classification
X, y = make_classification(n_samples=100, n_features=2, random_state=42)
kernel = 1.0 * RBF(1.0)
gpc = GaussianProcessClassifier(kernel=kernel, random_state=42)
gpc.fit(X, y)
proba = gpc.predict_proba(X[:5])
print(proba)