sklearn.gaussian_process.GaussianProcessRegressor
class sklearn.gaussian_process.GaussianProcessRegressor(kernel=None, *, alpha=1e-10, optimizer='fmin_l_bfgs_b', n_restarts_optimizer=0, normalize_y=False, copy_X_train=True, random_state=None) [source]

Gaussian process regression (GPR). The implementation is based on Algorithm 2.1 of Gaussian Processes for Machine Learning (GPML) by Rasmussen and Williams. In addition to standard scikit-learn estimator API, GaussianProcessRegressor:  allows prediction without prior fitting (based on the GP prior) provides an additional method sample_y(X), which evaluates samples drawn from the GPR (prior or posterior) at given inputs exposes a method log_marginal_likelihood(theta), which can be used externally for other ways of selecting hyperparameters, e.g., via Markov chain Monte Carlo.  Read more in the User Guide.  New in version 0.18.   Parameters

kernelkernel instance, default=None

The kernel specifying the covariance function of the GP. If None is passed, the kernel ConstantKernel(1.0, constant_value_bounds="fixed"
* RBF(1.0, length_scale_bounds="fixed") is used as default. Note that the kernel hyperparameters are optimized during fitting unless the bounds are marked as “fixed”.
alphafloat or ndarray of shape (n_samples,), default=1e-10

Value added to the diagonal of the kernel matrix during fitting. This can prevent a potential numerical issue during fitting, by ensuring that the calculated values form a positive definite matrix. It can also be interpreted as the variance of additional Gaussian measurement noise on the training observations. Note that this is different from using a WhiteKernel. If an array is passed, it must have the same number of entries as the data used for fitting and is used as datapoint-dependent noise level. Allowing to specify the noise level directly as a parameter is mainly for convenience and for consistency with Ridge.
optimizer“fmin_l_bfgs_b” or callable, default=”fmin_l_bfgs_b”

Can either be one of the internally supported optimizers for optimizing the kernel’s parameters, specified by a string, or an externally defined optimizer passed as a callable. If a callable is passed, it must have the signature: def optimizer(obj_func, initial_theta, bounds):
    # * 'obj_func' is the objective function to be minimized, which
    #   takes the hyperparameters theta as parameter and an
    #   optional flag eval_gradient, which determines if the
    #   gradient is returned additionally to the function value
    # * 'initial_theta': the initial value for theta, which can be
    #   used by local optimizers
    # * 'bounds': the bounds on the values of theta
    ....
    # Returned are the best found hyperparameters theta and
    # the corresponding value of the target function.
    return theta_opt, func_min
 Per default, the ‘L-BGFS-B’ algorithm from scipy.optimize.minimize is used. If None is passed, the kernel’s parameters are kept fixed. Available internal optimizers are: 'fmin_l_bfgs_b'

n_restarts_optimizerint, default=0

The number of restarts of the optimizer for finding the kernel’s parameters which maximize the log-marginal likelihood. The first run of the optimizer is performed from the kernel’s initial parameters, the remaining ones (if any) from thetas sampled log-uniform randomly from the space of allowed theta-values. If greater than 0, all bounds must be finite. Note that n_restarts_optimizer == 0 implies that one run is performed.
normalize_ybool, default=False

Whether the target values y are normalized, the mean and variance of the target values are set equal to 0 and 1 respectively. This is recommended for cases where zero-mean, unit-variance priors are used. Note that, in this implementation, the normalisation is reversed before the GP predictions are reported.  Changed in version 0.23.
copy_X_trainbool, default=True

If True, a persistent copy of the training data is stored in the object. Otherwise, just a reference to the training data is stored, which might cause predictions to change if the data is modified externally.
random_stateint, RandomState instance or None, default=None

Determines random number generation used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.    Attributes

X_train_array-like of shape (n_samples, n_features) or list of object

Feature vectors or other representations of training data (also required for prediction).
y_train_array-like of shape (n_samples,) or (n_samples, n_targets)

Target values in training data (also required for prediction)
kernel_kernel instance

The kernel used for prediction. The structure of the kernel is the same as the one passed as parameter but with optimized hyperparameters
L_array-like of shape (n_samples, n_samples)

Lower-triangular Cholesky decomposition of the kernel in X_train_
alpha_array-like of shape (n_samples,)

Dual coefficients of training data points in kernel space
log_marginal_likelihood_value_float

The log-marginal-likelihood of self.kernel_.theta     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel()
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3680...
>>> gpr.predict(X[:2,:], return_std=True)
(array([653.0..., 592.1...]), array([316.6..., 316.6...]))
 Methods
fit(X, y) Fit Gaussian process regression model.
get_params([deep]) Get parameters for this estimator.
log_marginal_likelihood([theta, …]) Returns log-marginal likelihood of theta for training data.
predict(X[, return_std, return_cov]) Predict using the Gaussian process regression model
sample_y(X[, n_samples, random_state]) Draw samples from Gaussian process and evaluate at X.
score(X, y[, sample_weight]) Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params) Set the parameters of this estimator.
fit(X, y) [source]

Fit Gaussian process regression model.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Feature vectors or other representations of training data.
yarray-like of shape (n_samples,) or (n_samples, n_targets)

Target values    Returns

selfreturns an instance of self.

get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

log_marginal_likelihood(theta=None, eval_gradient=False, clone_kernel=True) [source]

Returns log-marginal likelihood of theta for training data.  Parameters

thetaarray-like of shape (n_kernel_params,) default=None

Kernel hyperparameters for which the log-marginal likelihood is evaluated. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
eval_gradientbool, default=False

If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If True, theta must not be None.
clone_kernelbool, default=True

If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.    Returns

log_likelihoodfloat

Log-marginal likelihood of theta for training data.
log_likelihood_gradientndarray of shape (n_kernel_params,), optional

Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.

predict(X, return_std=False, return_cov=False) [source]

Predict using the Gaussian process regression model We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) or covariance (return_cov=True). Note that at most one of the two can be requested.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Query points where the GP is evaluated.
return_stdbool, default=False

If True, the standard-deviation of the predictive distribution at the query points is returned along with the mean.
return_covbool, default=False

If True, the covariance of the joint predictive distribution at the query points is returned along with the mean.    Returns

y_meanndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution a query points.
y_stdndarray of shape (n_samples,), optional

Standard deviation of predictive distribution at query points. Only returned when return_std is True.
y_covndarray of shape (n_samples, n_samples), optional

Covariance of joint predictive distribution a query points. Only returned when return_cov is True.

sample_y(X, n_samples=1, random_state=0) [source]

Draw samples from Gaussian process and evaluate at X.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Query points where the GP is evaluated.
n_samplesint, default=1

The number of samples drawn from the Gaussian process
random_stateint, RandomState instance or None, default=0

Determines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.    Returns

y_samplesndarray of shape (n_samples_X, [n_output_dims], n_samples)

Values of n_samples samples drawn from Gaussian process and evaluated at query points.

score(X, y, sample_weight=None) [source]

Return the coefficient of determination \(R^2\) of the prediction. The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.  Parameters

Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.
sample_weightarray-like of shape (n_samples,), default=None

Sample weights.    Returns

scorefloat

\(R^2\) of self.predict(X) wrt. y.     Notes The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).

set_params(**params) [source]

Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.

 Examples using sklearn.gaussian_process.GaussianProcessRegressor

  Comparison of kernel ridge and Gaussian process regression

  Illustration of prior and posterior Gaussian process for different kernels

  Gaussian process regression (GPR) with noise-level estimation

  Gaussian Processes regression: basic introductory example

  Gaussian process regression (GPR) on Mauna Loa CO2 data.

  Gaussian processes on discrete data structures


fit(X, y) [source]

Fit Gaussian process regression model.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Feature vectors or other representations of training data.
yarray-like of shape (n_samples,) or (n_samples, n_targets)

Target values    Returns

selfreturns an instance of self.


get_params(deep=True) [source]

Get parameters for this estimator.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


log_marginal_likelihood(theta=None, eval_gradient=False, clone_kernel=True) [source]

Returns log-marginal likelihood of theta for training data.  Parameters

thetaarray-like of shape (n_kernel_params,) default=None

Kernel hyperparameters for which the log-marginal likelihood is evaluated. If None, the precomputed log_marginal_likelihood of self.kernel_.theta is returned.
eval_gradientbool, default=False

If True, the gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta is returned additionally. If True, theta must not be None.
clone_kernelbool, default=True

If True, the kernel attribute is copied. If False, the kernel attribute is modified, but may result in a performance improvement.    Returns

log_likelihoodfloat

Log-marginal likelihood of theta for training data.
log_likelihood_gradientndarray of shape (n_kernel_params,), optional

Gradient of the log-marginal likelihood with respect to the kernel hyperparameters at position theta. Only returned when eval_gradient is True.


predict(X, return_std=False, return_cov=False) [source]

Predict using the Gaussian process regression model We can also predict based on an unfitted model by using the GP prior. In addition to the mean of the predictive distribution, also its standard deviation (return_std=True) or covariance (return_cov=True). Note that at most one of the two can be requested.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Query points where the GP is evaluated.
return_stdbool, default=False

If True, the standard-deviation of the predictive distribution at the query points is returned along with the mean.
return_covbool, default=False

If True, the covariance of the joint predictive distribution at the query points is returned along with the mean.    Returns

y_meanndarray of shape (n_samples, [n_output_dims])

Mean of predictive distribution a query points.
y_stdndarray of shape (n_samples,), optional

Standard deviation of predictive distribution at query points. Only returned when return_std is True.
y_covndarray of shape (n_samples, n_samples), optional

Covariance of joint predictive distribution a query points. Only returned when return_cov is True.


sample_y(X, n_samples=1, random_state=0) [source]

Draw samples from Gaussian process and evaluate at X.  Parameters

Xarray-like of shape (n_samples, n_features) or list of object

Query points where the GP is evaluated.
n_samplesint, default=1

The number of samples drawn from the Gaussian process
random_stateint, RandomState instance or None, default=0

Determines random number generation to randomly draw samples. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.    Returns

y_samplesndarray of shape (n_samples_X, [n_output_dims], n_samples)

Values of n_samples samples drawn from Gaussian process and evaluated at query points.


score(X, y, sample_weight=None) [source]

Return the coefficient of determination \(R^2\) of the prediction. The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.  Parameters

Xarray-like of shape (n_samples, n_features)

Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True values for X.
sample_weightarray-like of shape (n_samples,), default=None

Sample weights.    Returns

scorefloat

\(R^2\) of self.predict(X) wrt. y.     Notes The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).


set_params(**params) [source]

Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Parameters

**paramsdict

Estimator parameters.    Returns

selfestimator instance

Estimator instance.


class sklearn.gaussian_process.kernels.CompoundKernel(kernels) [source]

Kernel which is composed of a set of other kernels.  New in version 0.18.   Parameters

kernelslist of Kernels

The other kernels    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on discrete structures.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.gaussian_process.kernels import WhiteKernel
>>> from sklearn.gaussian_process.kernels import RBF
>>> from sklearn.gaussian_process.kernels import CompoundKernel
>>> kernel = CompoundKernel(
...     [WhiteKernel(noise_level=3.0), RBF(length_scale=2.0)])
>>> print(kernel.bounds)
[[-11.51292546  11.51292546]
 [-11.51292546  11.51292546]]
>>> print(kernel.n_dims)
2
>>> print(kernel.theta)
[1.09861229 0.69314718]
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient. Note that this compound kernel returns the results of all simple kernel stacked along an additional axis.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object, default=None

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y, n_kernels)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims, n_kernels), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X, n_kernels)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on discrete structures.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


sklearn.gaussian_process.kernels.CompoundKernel
class sklearn.gaussian_process.kernels.CompoundKernel(kernels) [source]

Kernel which is composed of a set of other kernels.  New in version 0.18.   Parameters

kernelslist of Kernels

The other kernels    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on discrete structures.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.gaussian_process.kernels import WhiteKernel
>>> from sklearn.gaussian_process.kernels import RBF
>>> from sklearn.gaussian_process.kernels import CompoundKernel
>>> kernel = CompoundKernel(
...     [WhiteKernel(noise_level=3.0), RBF(length_scale=2.0)])
>>> print(kernel.bounds)
[[-11.51292546  11.51292546]
 [-11.51292546  11.51292546]]
>>> print(kernel.n_dims)
2
>>> print(kernel.theta)
[1.09861229 0.69314718]
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient. Note that this compound kernel returns the results of all simple kernel stacked along an additional axis.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object, default=None

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y, n_kernels)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims, n_kernels), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X, n_kernels)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on discrete structures.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta


clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters


diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X, n_kernels)

Diagonal of kernel k(X, X)


get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


property hyperparameters
Returns a list of all hyperparameter specifications.


is_stationary() [source]

Returns whether the kernel is stationary.


property n_dims
Returns the number of non-fixed hyperparameters of the kernel.


property requires_vector_input
Returns whether the kernel is defined on discrete structures.


set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self


property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient. Note that this compound kernel returns the results of all simple kernel stacked along an additional axis.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object, default=None

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y, n_kernels)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims, n_kernels), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.


class sklearn.gaussian_process.kernels.ConstantKernel(constant_value=1.0, constant_value_bounds=1e-05, 100000.0) [source]

Constant kernel. Can be used as part of a product-kernel where it scales the magnitude of the other factor (kernel) or as part of a sum-kernel, where it modifies the mean of the Gaussian process.  \[k(x_1, x_2) = constant\_value \;\forall\; x_1, x_2\] Adding a constant kernel is equivalent to adding a constant: kernel = RBF() + ConstantKernel(constant_value=2)
 is the same as: kernel = RBF() + 2
 Read more in the User Guide.  New in version 0.18.   Parameters

constant_valuefloat, default=1.0

The constant value which defines the covariance: k(x_1, x_2) = constant_value
constant_value_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on constant_value. If set to “fixed”, constant_value cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_constant_value

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Whether the kernel works only on fixed-length feature vectors.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import RBF, ConstantKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = RBF() + ConstantKernel(constant_value=2)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3696...
>>> gpr.predict(X[:1,:], return_std=True)
(array([606.1...]), array([0.24...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Whether the kernel works only on fixed-length feature vectors.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


sklearn.gaussian_process.kernels.ConstantKernel
class sklearn.gaussian_process.kernels.ConstantKernel(constant_value=1.0, constant_value_bounds=1e-05, 100000.0) [source]

Constant kernel. Can be used as part of a product-kernel where it scales the magnitude of the other factor (kernel) or as part of a sum-kernel, where it modifies the mean of the Gaussian process.  \[k(x_1, x_2) = constant\_value \;\forall\; x_1, x_2\] Adding a constant kernel is equivalent to adding a constant: kernel = RBF() + ConstantKernel(constant_value=2)
 is the same as: kernel = RBF() + 2
 Read more in the User Guide.  New in version 0.18.   Parameters

constant_valuefloat, default=1.0

The constant value which defines the covariance: k(x_1, x_2) = constant_value
constant_value_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on constant_value. If set to “fixed”, constant_value cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_constant_value

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Whether the kernel works only on fixed-length feature vectors.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import RBF, ConstantKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = RBF() + ConstantKernel(constant_value=2)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3696...
>>> gpr.predict(X[:1,:], return_std=True)
(array([606.1...]), array([0.24...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Whether the kernel works only on fixed-length feature vectors.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel

 Examples using sklearn.gaussian_process.kernels.ConstantKernel

  Illustration of prior and posterior Gaussian process for different kernels

  Iso-probability lines for Gaussian Processes classification (GPC)

  Gaussian Processes regression: basic introductory example


property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta


diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)


property requires_vector_input
Whether the kernel works only on fixed-length feature vectors.


__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_X, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.


class sklearn.gaussian_process.kernels.DotProduct(sigma_0=1.0, sigma_0_bounds=1e-05, 100000.0) [source]

Dot-Product kernel. The DotProduct kernel is non-stationary and can be obtained from linear regression by putting \(N(0, 1)\) priors on the coefficients of \(x_d (d = 1, . . . , D)\) and a prior of \(N(0, \sigma_0^2)\) on the bias. The DotProduct kernel is invariant to a rotation of the coordinates about the origin, but not translations. It is parameterized by a parameter sigma_0 \(\sigma\) which controls the inhomogenity of the kernel. For \(\sigma_0^2 =0\), the kernel is called the homogeneous linear kernel, otherwise it is inhomogeneous. The kernel is given by  \[k(x_i, x_j) = \sigma_0 ^ 2 + x_i \cdot x_j\] The DotProduct kernel is commonly combined with exponentiation. See [1], Chapter 4, Section 4.2, for further details regarding the DotProduct kernel. Read more in the User Guide.  New in version 0.18.   Parameters

sigma_0float >= 0, default=1.0

Parameter controlling the inhomogenity of the kernel. If sigma_0=0, the kernel is homogenous.
sigma_0_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘sigma_0’. If set to “fixed”, ‘sigma_0’ cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_sigma_0

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     References
1
Carl Edward Rasmussen, Christopher K. I. Williams (2006). “Gaussian Processes for Machine Learning”. The MIT Press.   Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel()
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3680...
>>> gpr.predict(X[:2,:], return_std=True)
(array([653.0..., 592.1...]), array([316.6..., 316.6...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y).    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X).

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


sklearn.gaussian_process.kernels.DotProduct
class sklearn.gaussian_process.kernels.DotProduct(sigma_0=1.0, sigma_0_bounds=1e-05, 100000.0) [source]

Dot-Product kernel. The DotProduct kernel is non-stationary and can be obtained from linear regression by putting \(N(0, 1)\) priors on the coefficients of \(x_d (d = 1, . . . , D)\) and a prior of \(N(0, \sigma_0^2)\) on the bias. The DotProduct kernel is invariant to a rotation of the coordinates about the origin, but not translations. It is parameterized by a parameter sigma_0 \(\sigma\) which controls the inhomogenity of the kernel. For \(\sigma_0^2 =0\), the kernel is called the homogeneous linear kernel, otherwise it is inhomogeneous. The kernel is given by  \[k(x_i, x_j) = \sigma_0 ^ 2 + x_i \cdot x_j\] The DotProduct kernel is commonly combined with exponentiation. See [1], Chapter 4, Section 4.2, for further details regarding the DotProduct kernel. Read more in the User Guide.  New in version 0.18.   Parameters

sigma_0float >= 0, default=1.0

Parameter controlling the inhomogenity of the kernel. If sigma_0=0, the kernel is homogenous.
sigma_0_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘sigma_0’. If set to “fixed”, ‘sigma_0’ cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_sigma_0

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     References
1
Carl Edward Rasmussen, Christopher K. I. Williams (2006). “Gaussian Processes for Machine Learning”. The MIT Press.   Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel()
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3680...
>>> gpr.predict(X[:2,:], return_std=True)
(array([653.0..., 592.1...]), array([316.6..., 316.6...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y).    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X).

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel

 Examples using sklearn.gaussian_process.kernels.DotProduct

  Illustration of Gaussian process classification (GPC) on the XOR dataset

  Illustration of prior and posterior Gaussian process for different kernels

  Iso-probability lines for Gaussian Processes classification (GPC)


clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters


diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y).    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X).


get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


property hyperparameters
Returns a list of all hyperparameter specifications.


is_stationary() [source]

Returns whether the kernel is stationary.


property n_dims
Returns the number of non-fixed hyperparameters of the kernel.


property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.


set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self


property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.


class sklearn.gaussian_process.kernels.Exponentiation(kernel, exponent) [source]

The Exponentiation kernel takes one base kernel and a scalar parameter \(p\) and combines them via  \[k_{exp}(X, Y) = k(X, Y) ^p\] Note that the __pow__ magic method is overridden, so Exponentiation(RBF(), 2) is equivalent to using the ** operator with RBF() ** 2. Read more in the User Guide.  New in version 0.18.   Parameters

kernelKernel

The base kernel
exponentfloat

The exponent for the base kernel    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on discrete structures.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import (RationalQuadratic,
...            Exponentiation)
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Exponentiation(RationalQuadratic(), exponent=2)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.419...
>>> gpr.predict(X[:1,:], return_std=True)
(array([635.5...]), array([0.559...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_Y, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on discrete structures.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


sklearn.gaussian_process.kernels.Exponentiation
class sklearn.gaussian_process.kernels.Exponentiation(kernel, exponent) [source]

The Exponentiation kernel takes one base kernel and a scalar parameter \(p\) and combines them via  \[k_{exp}(X, Y) = k(X, Y) ^p\] Note that the __pow__ magic method is overridden, so Exponentiation(RBF(), 2) is equivalent to using the ** operator with RBF() ** 2. Read more in the User Guide.  New in version 0.18.   Parameters

kernelKernel

The base kernel
exponentfloat

The exponent for the base kernel    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on discrete structures.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import (RationalQuadratic,
...            Exponentiation)
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Exponentiation(RationalQuadratic(), exponent=2)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.419...
>>> gpr.predict(X[:1,:], return_std=True)
(array([635.5...]), array([0.559...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_Y, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on discrete structures.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta


diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Argument to the kernel.    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)


property hyperparameters
Returns a list of all hyperparameter.


property requires_vector_input
Returns whether the kernel is defined on discrete structures.


__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xarray-like of shape (n_samples_X, n_features) or list of object

Left argument of the returned kernel k(X, Y)
Yarray-like of shape (n_samples_Y, n_features) or list of object, default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.


class sklearn.gaussian_process.kernels.ExpSineSquared(length_scale=1.0, periodicity=1.0, length_scale_bounds=1e-05, 100000.0, periodicity_bounds=1e-05, 100000.0) [source]

Exp-Sine-Squared kernel (aka periodic kernel). The ExpSineSquared kernel allows one to model functions which repeat themselves exactly. It is parameterized by a length scale parameter \(l>0\) and a periodicity parameter \(p>0\). Only the isotropic variant where \(l\) is a scalar is supported at the moment. The kernel is given by:  \[k(x_i, x_j) = \text{exp}\left(- \frac{ 2\sin^2(\pi d(x_i, x_j)/p) }{ l^ 2} \right)\] where \(l\) is the length scale of the kernel, \(p\) the periodicity of the kernel and \(d(\\cdot,\\cdot)\) is the Euclidean distance. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat > 0, default=1.0

The length scale of the kernel.
periodicityfloat > 0, default=1.0

The periodicity of the kernel.
length_scale_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘length_scale’. If set to “fixed”, ‘length_scale’ cannot be changed during hyperparameter tuning.
periodicity_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘periodicity’. If set to “fixed”, ‘periodicity’ cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameter_length_scale

Returns the length scale  hyperparameter_periodicity

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import ExpSineSquared
>>> X, y = make_friedman2(n_samples=50, noise=0, random_state=0)
>>> kernel = ExpSineSquared(length_scale=1, periodicity=1)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.0144...
>>> gpr.predict(X[:2,:], return_std=True)
(array([425.6..., 457.5...]), array([0.3894..., 0.3467...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameter_length_scale
Returns the length scale

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


sklearn.gaussian_process.kernels.ExpSineSquared
class sklearn.gaussian_process.kernels.ExpSineSquared(length_scale=1.0, periodicity=1.0, length_scale_bounds=1e-05, 100000.0, periodicity_bounds=1e-05, 100000.0) [source]

Exp-Sine-Squared kernel (aka periodic kernel). The ExpSineSquared kernel allows one to model functions which repeat themselves exactly. It is parameterized by a length scale parameter \(l>0\) and a periodicity parameter \(p>0\). Only the isotropic variant where \(l\) is a scalar is supported at the moment. The kernel is given by:  \[k(x_i, x_j) = \text{exp}\left(- \frac{ 2\sin^2(\pi d(x_i, x_j)/p) }{ l^ 2} \right)\] where \(l\) is the length scale of the kernel, \(p\) the periodicity of the kernel and \(d(\\cdot,\\cdot)\) is the Euclidean distance. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat > 0, default=1.0

The length scale of the kernel.
periodicityfloat > 0, default=1.0

The periodicity of the kernel.
length_scale_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘length_scale’. If set to “fixed”, ‘length_scale’ cannot be changed during hyperparameter tuning.
periodicity_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘periodicity’. If set to “fixed”, ‘periodicity’ cannot be changed during hyperparameter tuning.    Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameter_length_scale

Returns the length scale  hyperparameter_periodicity

hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Examples >>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import ExpSineSquared
>>> X, y = make_friedman2(n_samples=50, noise=0, random_state=0)
>>> kernel = ExpSineSquared(length_scale=1, periodicity=1)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.0144...
>>> gpr.predict(X[:2,:], return_std=True)
(array([425.6..., 457.5...]), array([0.3894..., 0.3467...]))
 Methods
__call__(X[, Y, eval_gradient]) Return the kernel k(X, Y) and optionally its gradient.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameter_length_scale
Returns the length scale

property hyperparameters
Returns a list of all hyperparameter specifications.

is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel

 Examples using sklearn.gaussian_process.kernels.ExpSineSquared

  Comparison of kernel ridge and Gaussian process regression

  Illustration of prior and posterior Gaussian process for different kernels

  Gaussian process regression (GPR) on Mauna Loa CO2 data.


clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters


diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)


get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


property hyperparameters
Returns a list of all hyperparameter specifications.


property hyperparameter_length_scale
Returns the length scale


is_stationary() [source]

Returns whether the kernel is stationary.


property n_dims
Returns the number of non-fixed hyperparameters of the kernel.


property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.


set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self


property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


__call__(X, Y=None, eval_gradient=False) [source]

Return the kernel k(X, Y) and optionally its gradient.  Parameters

Xndarray of shape (n_samples_X, n_features)

Left argument of the returned kernel k(X, Y)
Yndarray of shape (n_samples_Y, n_features), default=None

Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.
eval_gradientbool, default=False

Determines whether the gradient with respect to the log of the kernel hyperparameter is computed. Only supported when Y is None.    Returns

Kndarray of shape (n_samples_X, n_samples_Y)

Kernel k(X, Y)
K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional

The gradient of the kernel k(X, X) with respect to the log of the hyperparameter of the kernel. Only returned when eval_gradient is True.


class sklearn.gaussian_process.kernels.Hyperparameter(name, value_type, bounds, n_elements=1, fixed=None) [source]

A kernel hyperparameter’s specification in form of a namedtuple.  New in version 0.18.   Attributes

namestr

The name of the hyperparameter. Note that a kernel using a hyperparameter with name “x” must have the attributes self.x and self.x_bounds
value_typestr

The type of the hyperparameter. Currently, only “numeric” hyperparameters are supported.
boundspair of floats >= 0 or “fixed”

The lower and upper bound on the parameter. If n_elements>1, a pair of 1d array with n_elements each may be given alternatively. If the string “fixed” is passed as bounds, the hyperparameter’s value cannot be changed.
n_elementsint, default=1

The number of elements of the hyperparameter value. Defaults to 1, which corresponds to a scalar hyperparameter. n_elements > 1 corresponds to a hyperparameter which is vector-valued, such as, e.g., anisotropic length-scales.
fixedbool, default=None

Whether the value of this hyperparameter is fixed, i.e., cannot be changed during hyperparameter tuning. If None is passed, the “fixed” is derived based on the given bounds.     Examples >>> from sklearn.gaussian_process.kernels import ConstantKernel
>>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import Hyperparameter
>>> X, y = make_friedman2(n_samples=50, noise=0, random_state=0)
>>> kernel = ConstantKernel(constant_value=1.0,
...    constant_value_bounds=(0.0, 10.0))
 We can access each hyperparameter: >>> for hyperparameter in kernel.hyperparameters:
...    print(hyperparameter)
Hyperparameter(name='constant_value', value_type='numeric',
bounds=array([[ 0., 10.]]), n_elements=1, fixed=False)
 >>> params = kernel.get_params()
>>> for key in sorted(params): print(f"{key} : {params[key]}")
constant_value : 1.0
constant_value_bounds : (0.0, 10.0)
 Methods
count(value, /) Return number of occurrences of value.
index(value[, start, stop]) Return first index of value.
__call__(*args, **kwargs)
Call self as a function.

bounds
Alias for field number 2

count(value, /)
Return number of occurrences of value.

fixed
Alias for field number 4

index(value, start=0, stop=sys.maxsize, /)
Return first index of value. Raises ValueError if the value is not present.

n_elements
Alias for field number 3

name
Alias for field number 0

value_type
Alias for field number 1


sklearn.gaussian_process.kernels.Hyperparameter
class sklearn.gaussian_process.kernels.Hyperparameter(name, value_type, bounds, n_elements=1, fixed=None) [source]

A kernel hyperparameter’s specification in form of a namedtuple.  New in version 0.18.   Attributes

namestr

The name of the hyperparameter. Note that a kernel using a hyperparameter with name “x” must have the attributes self.x and self.x_bounds
value_typestr

The type of the hyperparameter. Currently, only “numeric” hyperparameters are supported.
boundspair of floats >= 0 or “fixed”

The lower and upper bound on the parameter. If n_elements>1, a pair of 1d array with n_elements each may be given alternatively. If the string “fixed” is passed as bounds, the hyperparameter’s value cannot be changed.
n_elementsint, default=1

The number of elements of the hyperparameter value. Defaults to 1, which corresponds to a scalar hyperparameter. n_elements > 1 corresponds to a hyperparameter which is vector-valued, such as, e.g., anisotropic length-scales.
fixedbool, default=None

Whether the value of this hyperparameter is fixed, i.e., cannot be changed during hyperparameter tuning. If None is passed, the “fixed” is derived based on the given bounds.     Examples >>> from sklearn.gaussian_process.kernels import ConstantKernel
>>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import Hyperparameter
>>> X, y = make_friedman2(n_samples=50, noise=0, random_state=0)
>>> kernel = ConstantKernel(constant_value=1.0,
...    constant_value_bounds=(0.0, 10.0))
 We can access each hyperparameter: >>> for hyperparameter in kernel.hyperparameters:
...    print(hyperparameter)
Hyperparameter(name='constant_value', value_type='numeric',
bounds=array([[ 0., 10.]]), n_elements=1, fixed=False)
 >>> params = kernel.get_params()
>>> for key in sorted(params): print(f"{key} : {params[key]}")
constant_value : 1.0
constant_value_bounds : (0.0, 10.0)
 Methods
count(value, /) Return number of occurrences of value.
index(value[, start, stop]) Return first index of value.
__call__(*args, **kwargs)
Call self as a function.

bounds
Alias for field number 2

count(value, /)
Return number of occurrences of value.

fixed
Alias for field number 4

index(value, start=0, stop=sys.maxsize, /)
Return first index of value. Raises ValueError if the value is not present.

n_elements
Alias for field number 3

name
Alias for field number 0

value_type
Alias for field number 1

 Examples using sklearn.gaussian_process.kernels.Hyperparameter

  Gaussian processes on discrete data structures


count(value, /)
Return number of occurrences of value.


index(value, start=0, stop=sys.maxsize, /)
Return first index of value. Raises ValueError if the value is not present.


__call__(*args, **kwargs)
Call self as a function.


sklearn.gaussian_process.kernels.Kernel
class sklearn.gaussian_process.kernels.Kernel [source]

Base class for all kernels.  New in version 0.18.   Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Methods
__call__(X[, Y, eval_gradient]) Evaluate the kernel.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
abstract __call__(X, Y=None, eval_gradient=False) [source]

Evaluate the kernel.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

abstract diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples,)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

abstract is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel

 Examples using sklearn.gaussian_process.kernels.Kernel

  Gaussian processes on discrete data structures


class sklearn.gaussian_process.kernels.Kernel [source]

Base class for all kernels.  New in version 0.18.   Attributes

bounds

Returns the log-transformed bounds on the theta.
hyperparameters

Returns a list of all hyperparameter specifications.
n_dims

Returns the number of non-fixed hyperparameters of the kernel.
requires_vector_input

Returns whether the kernel is defined on fixed-length feature vectors or generic objects.
theta

Returns the (flattened, log-transformed) non-fixed hyperparameters.     Methods
__call__(X[, Y, eval_gradient]) Evaluate the kernel.
clone_with_theta(theta) Returns a clone of self with given hyperparameters theta.
diag(X) Returns the diagonal of the kernel k(X, X).
get_params([deep]) Get parameters of this kernel.
is_stationary() Returns whether the kernel is stationary.
set_params(**params) Set the parameters of this kernel.
abstract __call__(X, Y=None, eval_gradient=False) [source]

Evaluate the kernel.

property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta

clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters

abstract diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples,)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)

get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.

property hyperparameters
Returns a list of all hyperparameter specifications.

abstract is_stationary() [source]

Returns whether the kernel is stationary.

property n_dims
Returns the number of non-fixed hyperparameters of the kernel.

property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.

set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self

property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


property bounds
Returns the log-transformed bounds on the theta.  Returns

boundsndarray of shape (n_dims, 2)

The log-transformed bounds on the kernel’s hyperparameters theta


clone_with_theta(theta) [source]

Returns a clone of self with given hyperparameters theta.  Parameters

thetandarray of shape (n_dims,)

The hyperparameters


abstract diag(X) [source]

Returns the diagonal of the kernel k(X, X). The result of this method is identical to np.diag(self(X)); however, it can be evaluated more efficiently since only the diagonal is evaluated.  Parameters

Xarray-like of shape (n_samples,)

Left argument of the returned kernel k(X, Y)    Returns

K_diagndarray of shape (n_samples_X,)

Diagonal of kernel k(X, X)


get_params(deep=True) [source]

Get parameters of this kernel.  Parameters

deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.    Returns

paramsdict

Parameter names mapped to their values.


property hyperparameters
Returns a list of all hyperparameter specifications.


abstract is_stationary() [source]

Returns whether the kernel is stationary.


property n_dims
Returns the number of non-fixed hyperparameters of the kernel.


property requires_vector_input
Returns whether the kernel is defined on fixed-length feature vectors or generic objects. Defaults to True for backward compatibility.


set_params(**params) [source]

Set the parameters of this kernel. The method works on simple kernels as well as on nested kernels. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.  Returns
 self


property theta
Returns the (flattened, log-transformed) non-fixed hyperparameters. Note that theta are typically the log-transformed values of the kernel’s hyperparameters as this representation of the search space is more amenable for hyperparameter search, as hyperparameters like length-scales naturally live on a log-scale.  Returns

thetandarray of shape (n_dims,)

The non-fixed, log-transformed hyperparameters of the kernel


abstract __call__(X, Y=None, eval_gradient=False) [source]

Evaluate the kernel.