class sklearn.gaussian_process.kernels.Matern(length_scale=1.0, length_scale_bounds=1e-05, 100000.0, nu=1.5) [source]

Matern kernel. The class of Matern kernels is a generalization of the RBF. It has an additional parameter \(\nu\) which controls the smoothness of the resulting function. The smaller \(\nu\), the less smooth the approximated function is. As \(\nu\rightarrow\infty\), the kernel becomes equivalent to the RBF kernel. When \(\nu = 1/2\), the Matérn kernel becomes identical to the absolute exponential kernel. Important intermediate values are \(\nu=1.5\) (once differentiable functions) and \(\nu=2.5\) (twice differentiable functions). The kernel is given by:  \[k(x_i, x_j) = \frac{1}{\Gamma(\nu)2^{\nu-1}}\Bigg( \frac{\sqrt{2\nu}}{l} d(x_i , x_j ) \Bigg)^\nu K_\nu\Bigg( \frac{\sqrt{2\nu}}{l} d(x_i , x_j )\Bigg)\] where \(d(\cdot,\cdot)\) is the Euclidean distance, \(K_{\nu}(\cdot)\) is a modified Bessel function and \(\Gamma(\cdot)\) is the gamma function. See [1], Chapter 4, Section 4.2, for details regarding the different variants of the Matern kernel. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat or ndarray of shape (n_features,), default=1.0

The length scale of the kernel. If a float, an isotropic kernel is used. If an array, an anisotropic kernel is used where each dimension of l defines the length-scale of the respective feature dimension.
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.
nufloat, default=1.5

The parameter nu controlling the smoothness of the learned function. The smaller nu, the less smooth the approximated function is. For nu=inf, the kernel becomes equivalent to the RBF kernel and for nu=0.5 to the absolute exponential kernel. Important intermediate values are nu=1.5 (once differentiable functions) and nu=2.5 (twice differentiable functions). Note that values of nu not in [0.5, 1.5, 2.5, inf] incur a considerably higher computational cost (appr. 10 times higher) since they require to evaluate the modified Bessel function. Furthermore, in contrast to l, nu is kept fixed to its initial value and not optimized.    Attributes
 anisotropic

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_length_scale

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 load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import Matern
>>> X, y = load_iris(return_X_y=True)
>>> kernel = 1.0 * Matern(length_scale=1.0, nu=1.5)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9866...
>>> gpc.predict_proba(X[:2,:])
array([[0.8513..., 0.0368..., 0.1117...],
        [0.8086..., 0.0693..., 0.1220...]])
 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.Matern
class sklearn.gaussian_process.kernels.Matern(length_scale=1.0, length_scale_bounds=1e-05, 100000.0, nu=1.5) [source]

Matern kernel. The class of Matern kernels is a generalization of the RBF. It has an additional parameter \(\nu\) which controls the smoothness of the resulting function. The smaller \(\nu\), the less smooth the approximated function is. As \(\nu\rightarrow\infty\), the kernel becomes equivalent to the RBF kernel. When \(\nu = 1/2\), the Matérn kernel becomes identical to the absolute exponential kernel. Important intermediate values are \(\nu=1.5\) (once differentiable functions) and \(\nu=2.5\) (twice differentiable functions). The kernel is given by:  \[k(x_i, x_j) = \frac{1}{\Gamma(\nu)2^{\nu-1}}\Bigg( \frac{\sqrt{2\nu}}{l} d(x_i , x_j ) \Bigg)^\nu K_\nu\Bigg( \frac{\sqrt{2\nu}}{l} d(x_i , x_j )\Bigg)\] where \(d(\cdot,\cdot)\) is the Euclidean distance, \(K_{\nu}(\cdot)\) is a modified Bessel function and \(\Gamma(\cdot)\) is the gamma function. See [1], Chapter 4, Section 4.2, for details regarding the different variants of the Matern kernel. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat or ndarray of shape (n_features,), default=1.0

The length scale of the kernel. If a float, an isotropic kernel is used. If an array, an anisotropic kernel is used where each dimension of l defines the length-scale of the respective feature dimension.
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.
nufloat, default=1.5

The parameter nu controlling the smoothness of the learned function. The smaller nu, the less smooth the approximated function is. For nu=inf, the kernel becomes equivalent to the RBF kernel and for nu=0.5 to the absolute exponential kernel. Important intermediate values are nu=1.5 (once differentiable functions) and nu=2.5 (twice differentiable functions). Note that values of nu not in [0.5, 1.5, 2.5, inf] incur a considerably higher computational cost (appr. 10 times higher) since they require to evaluate the modified Bessel function. Furthermore, in contrast to l, nu is kept fixed to its initial value and not optimized.    Attributes
 anisotropic

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_length_scale

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 load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import Matern
>>> X, y = load_iris(return_X_y=True)
>>> kernel = 1.0 * Matern(length_scale=1.0, nu=1.5)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9866...
>>> gpc.predict_proba(X[:2,:])
array([[0.8513..., 0.0368..., 0.1117...],
        [0.8086..., 0.0693..., 0.1220...]])
 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.Matern

  Illustration of prior and posterior Gaussian process for different kernels


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


__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.PairwiseKernel(gamma=1.0, gamma_bounds=1e-05, 100000.0, metric='linear', pairwise_kernels_kwargs=None) [source]

Wrapper for kernels in sklearn.metrics.pairwise. A thin wrapper around the functionality of the kernels in sklearn.metrics.pairwise.  Note: Evaluation of eval_gradient is not analytic but numeric and all

kernels support only isotropic distances. The parameter gamma is considered to be a hyperparameter and may be optimized. The other kernel parameters are set directly at initialization and are kept fixed.    New in version 0.18.   Parameters

gammafloat, default=1.0

Parameter gamma of the pairwise kernel specified by metric. It should be positive.
gamma_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘gamma’. If set to “fixed”, ‘gamma’ cannot be changed during hyperparameter tuning.
metric{“linear”, “additive_chi2”, “chi2”, “poly”, “polynomial”, “rbf”, “laplacian”, “sigmoid”, “cosine”} or callable, default=”linear”

The metric to use when calculating kernel between instances in a feature array. If metric is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS. If metric is “precomputed”, X is assumed to be a kernel matrix. Alternatively, if metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays from X as input and return a value indicating the distance between them.
pairwise_kernels_kwargsdict, default=None

All entries of this dict (if any) are passed as keyword arguments to the pairwise kernel function.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_gamma

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 load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import PairwiseKernel
>>> X, y = load_iris(return_X_y=True)
>>> kernel = PairwiseKernel(metric='rbf')
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9733...
>>> gpc.predict_proba(X[:2,:])
array([[0.8880..., 0.05663..., 0.05532...],
       [0.8676..., 0.07073..., 0.06165...]])
 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.PairwiseKernel
class sklearn.gaussian_process.kernels.PairwiseKernel(gamma=1.0, gamma_bounds=1e-05, 100000.0, metric='linear', pairwise_kernels_kwargs=None) [source]

Wrapper for kernels in sklearn.metrics.pairwise. A thin wrapper around the functionality of the kernels in sklearn.metrics.pairwise.  Note: Evaluation of eval_gradient is not analytic but numeric and all

kernels support only isotropic distances. The parameter gamma is considered to be a hyperparameter and may be optimized. The other kernel parameters are set directly at initialization and are kept fixed.    New in version 0.18.   Parameters

gammafloat, default=1.0

Parameter gamma of the pairwise kernel specified by metric. It should be positive.
gamma_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

The lower and upper bound on ‘gamma’. If set to “fixed”, ‘gamma’ cannot be changed during hyperparameter tuning.
metric{“linear”, “additive_chi2”, “chi2”, “poly”, “polynomial”, “rbf”, “laplacian”, “sigmoid”, “cosine”} or callable, default=”linear”

The metric to use when calculating kernel between instances in a feature array. If metric is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS. If metric is “precomputed”, X is assumed to be a kernel matrix. Alternatively, if metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays from X as input and return a value indicating the distance between them.
pairwise_kernels_kwargsdict, default=None

All entries of this dict (if any) are passed as keyword arguments to the pairwise kernel function.    Attributes

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_gamma

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 load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import PairwiseKernel
>>> X, y = load_iris(return_X_y=True)
>>> kernel = PairwiseKernel(metric='rbf')
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9733...
>>> gpc.predict_proba(X[:2,:])
array([[0.8880..., 0.05663..., 0.05532...],
       [0.8676..., 0.07073..., 0.06165...]])
 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


class sklearn.gaussian_process.kernels.Product(k1, k2) [source]

The Product kernel takes two kernels \(k_1\) and \(k_2\) and combines them via  \[k_{prod}(X, Y) = k_1(X, Y) * k_2(X, Y)\] Note that the __mul__ magic method is overridden, so Product(RBF(), RBF()) is equivalent to using the * operator with RBF() * RBF(). Read more in the User Guide.  New in version 0.18.   Parameters

k1Kernel

The first base-kernel of the product-kernel
k2Kernel

The second base-kernel of the product-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 stationary.
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, Product,
...            ConstantKernel)
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Product(ConstantKernel(2), RBF())
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
1.0
>>> kernel
1.41**2 * RBF(length_scale=1)
 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 stationary.

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.Product
class sklearn.gaussian_process.kernels.Product(k1, k2) [source]

The Product kernel takes two kernels \(k_1\) and \(k_2\) and combines them via  \[k_{prod}(X, Y) = k_1(X, Y) * k_2(X, Y)\] Note that the __mul__ magic method is overridden, so Product(RBF(), RBF()) is equivalent to using the * operator with RBF() * RBF(). Read more in the User Guide.  New in version 0.18.   Parameters

k1Kernel

The first base-kernel of the product-kernel
k2Kernel

The second base-kernel of the product-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 stationary.
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, Product,
...            ConstantKernel)
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Product(ConstantKernel(2), RBF())
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
1.0
>>> kernel
1.41**2 * RBF(length_scale=1)
 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 stationary.

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


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 stationary.


__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.RationalQuadratic(length_scale=1.0, alpha=1.0, length_scale_bounds=1e-05, 100000.0, alpha_bounds=1e-05, 100000.0) [source]

Rational Quadratic kernel. The RationalQuadratic kernel can be seen as a scale mixture (an infinite sum) of RBF kernels with different characteristic length scales. It is parameterized by a length scale parameter \(l>0\) and a scale mixture parameter \(\alpha>0\). Only the isotropic variant where length_scale \(l\) is a scalar is supported at the moment. The kernel is given by:  \[k(x_i, x_j) = \left( 1 + \frac{d(x_i, x_j)^2 }{ 2\alpha l^2}\right)^{-\alpha}\] where \(\alpha\) is the scale mixture parameter, \(l\) is the length scale of the kernel and \(d(\cdot,\cdot)\) is the Euclidean distance. For advice on how to set the parameters, see e.g. [1]. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat > 0, default=1.0

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

Scale mixture parameter
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.
alpha_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

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

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_alpha
hyperparameter_length_scale

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
David Duvenaud (2014). “The Kernel Cookbook: Advice on Covariance functions”.   Examples >>> from sklearn.datasets import load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import Matern
>>> X, y = load_iris(return_X_y=True)
>>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9733...
>>> gpc.predict_proba(X[:2,:])
array([[0.8881..., 0.0566..., 0.05518...],
        [0.8678..., 0.0707... , 0.0614...]])
 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)

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.RationalQuadratic
class sklearn.gaussian_process.kernels.RationalQuadratic(length_scale=1.0, alpha=1.0, length_scale_bounds=1e-05, 100000.0, alpha_bounds=1e-05, 100000.0) [source]

Rational Quadratic kernel. The RationalQuadratic kernel can be seen as a scale mixture (an infinite sum) of RBF kernels with different characteristic length scales. It is parameterized by a length scale parameter \(l>0\) and a scale mixture parameter \(\alpha>0\). Only the isotropic variant where length_scale \(l\) is a scalar is supported at the moment. The kernel is given by:  \[k(x_i, x_j) = \left( 1 + \frac{d(x_i, x_j)^2 }{ 2\alpha l^2}\right)^{-\alpha}\] where \(\alpha\) is the scale mixture parameter, \(l\) is the length scale of the kernel and \(d(\cdot,\cdot)\) is the Euclidean distance. For advice on how to set the parameters, see e.g. [1]. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat > 0, default=1.0

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

Scale mixture parameter
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.
alpha_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

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

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_alpha
hyperparameter_length_scale

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
David Duvenaud (2014). “The Kernel Cookbook: Advice on Covariance functions”.   Examples >>> from sklearn.datasets import load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import Matern
>>> X, y = load_iris(return_X_y=True)
>>> kernel = RationalQuadratic(length_scale=1.0, alpha=1.5)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9733...
>>> gpc.predict_proba(X[:2,:])
array([[0.8881..., 0.0566..., 0.05518...],
        [0.8678..., 0.0707... , 0.0614...]])
 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)

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.RationalQuadratic

  Illustration of prior and posterior Gaussian process for different kernels

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


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


__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)

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.RBF(length_scale=1.0, length_scale_bounds=1e-05, 100000.0) [source]

Radial-basis function kernel (aka squared-exponential kernel). The RBF kernel is a stationary kernel. It is also known as the “squared exponential” kernel. It is parameterized by a length scale parameter \(l>0\), which can either be a scalar (isotropic variant of the kernel) or a vector with the same number of dimensions as the inputs X (anisotropic variant of the kernel). The kernel is given by:  \[k(x_i, x_j) = \exp\left(- \frac{d(x_i, x_j)^2}{2l^2} \right)\] where \(l\) is the length scale of the kernel and \(d(\cdot,\cdot)\) is the Euclidean distance. For advice on how to set the length scale parameter, see e.g. [1]. This kernel is infinitely differentiable, which implies that GPs with this kernel as covariance function have mean square derivatives of all orders, and are thus very smooth. See [2], Chapter 4, Section 4.2, for further details of the RBF kernel. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat or ndarray of shape (n_features,), default=1.0

The length scale of the kernel. If a float, an isotropic kernel is used. If an array, an anisotropic kernel is used where each dimension of l defines the length-scale of the respective feature dimension.
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.    Attributes
 anisotropic

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_length_scale

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
David Duvenaud (2014). “The Kernel Cookbook: Advice on Covariance functions”.
2
Carl Edward Rasmussen, Christopher K. I. Williams (2006). “Gaussian Processes for Machine Learning”. The MIT Press.   Examples >>> from sklearn.datasets import load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import RBF
>>> X, y = load_iris(return_X_y=True)
>>> kernel = 1.0 * RBF(1.0)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9866...
>>> gpc.predict_proba(X[:2,:])
array([[0.8354..., 0.03228..., 0.1322...],
       [0.7906..., 0.0652..., 0.1441...]])
 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.RBF
class sklearn.gaussian_process.kernels.RBF(length_scale=1.0, length_scale_bounds=1e-05, 100000.0) [source]

Radial-basis function kernel (aka squared-exponential kernel). The RBF kernel is a stationary kernel. It is also known as the “squared exponential” kernel. It is parameterized by a length scale parameter \(l>0\), which can either be a scalar (isotropic variant of the kernel) or a vector with the same number of dimensions as the inputs X (anisotropic variant of the kernel). The kernel is given by:  \[k(x_i, x_j) = \exp\left(- \frac{d(x_i, x_j)^2}{2l^2} \right)\] where \(l\) is the length scale of the kernel and \(d(\cdot,\cdot)\) is the Euclidean distance. For advice on how to set the length scale parameter, see e.g. [1]. This kernel is infinitely differentiable, which implies that GPs with this kernel as covariance function have mean square derivatives of all orders, and are thus very smooth. See [2], Chapter 4, Section 4.2, for further details of the RBF kernel. Read more in the User Guide.  New in version 0.18.   Parameters

length_scalefloat or ndarray of shape (n_features,), default=1.0

The length scale of the kernel. If a float, an isotropic kernel is used. If an array, an anisotropic kernel is used where each dimension of l defines the length-scale of the respective feature dimension.
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.    Attributes
 anisotropic

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_length_scale

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
David Duvenaud (2014). “The Kernel Cookbook: Advice on Covariance functions”.
2
Carl Edward Rasmussen, Christopher K. I. Williams (2006). “Gaussian Processes for Machine Learning”. The MIT Press.   Examples >>> from sklearn.datasets import load_iris
>>> from sklearn.gaussian_process import GaussianProcessClassifier
>>> from sklearn.gaussian_process.kernels import RBF
>>> X, y = load_iris(return_X_y=True)
>>> kernel = 1.0 * RBF(1.0)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9866...
>>> gpc.predict_proba(X[:2,:])
array([[0.8354..., 0.03228..., 0.1322...],
       [0.7906..., 0.0652..., 0.1441...]])
 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.RBF

  Plot classification probability

  Classifier comparison

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

  Gaussian process classification (GPC) on iris dataset

  Illustration of prior and posterior Gaussian process for different kernels

  Probabilistic predictions with Gaussian process classification (GPC)

  Gaussian process regression (GPR) with noise-level estimation

  Gaussian Processes regression: basic introductory example

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


__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.Sum(k1, k2) [source]

The Sum kernel takes two kernels \(k_1\) and \(k_2\) and combines them via  \[k_{sum}(X, Y) = k_1(X, Y) + k_2(X, Y)\] Note that the __add__ magic method is overridden, so Sum(RBF(), RBF()) is equivalent to using the + operator with RBF() + RBF(). Read more in the User Guide.  New in version 0.18.   Parameters

k1Kernel

The first base-kernel of the sum-kernel
k2Kernel

The second base-kernel of the sum-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 stationary.
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, Sum, ConstantKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Sum(ConstantKernel(2), RBF())
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
1.0
>>> kernel
1.41**2 + RBF(length_scale=1)
 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.    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 stationary.

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.Sum
class sklearn.gaussian_process.kernels.Sum(k1, k2) [source]

The Sum kernel takes two kernels \(k_1\) and \(k_2\) and combines them via  \[k_{sum}(X, Y) = k_1(X, Y) + k_2(X, Y)\] Note that the __add__ magic method is overridden, so Sum(RBF(), RBF()) is equivalent to using the + operator with RBF() + RBF(). Read more in the User Guide.  New in version 0.18.   Parameters

k1Kernel

The first base-kernel of the sum-kernel
k2Kernel

The second base-kernel of the sum-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 stationary.
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, Sum, ConstantKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = Sum(ConstantKernel(2), RBF())
>>> gpr = GaussianProcessRegressor(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
1.0
>>> kernel
1.41**2 + RBF(length_scale=1)
 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.    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 stationary.

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


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 stationary.


__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.    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.WhiteKernel(noise_level=1.0, noise_level_bounds=1e-05, 100000.0) [source]

White kernel. The main use-case of this kernel is as part of a sum-kernel where it explains the noise of the signal as independently and identically normally-distributed. The parameter noise_level equals the variance of this noise.  \[k(x_1, x_2) = noise\_level \text{ if } x_i == x_j \text{ else } 0\] Read more in the User Guide.  New in version 0.18.   Parameters

noise_levelfloat, default=1.0

Parameter controlling the noise level (variance)
noise_level_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

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

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_noise_level

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 DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel(noise_level=0.5)
>>> 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

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.WhiteKernel
class sklearn.gaussian_process.kernels.WhiteKernel(noise_level=1.0, noise_level_bounds=1e-05, 100000.0) [source]

White kernel. The main use-case of this kernel is as part of a sum-kernel where it explains the noise of the signal as independently and identically normally-distributed. The parameter noise_level equals the variance of this noise.  \[k(x_1, x_2) = noise\_level \text{ if } x_i == x_j \text{ else } 0\] Read more in the User Guide.  New in version 0.18.   Parameters

noise_levelfloat, default=1.0

Parameter controlling the noise level (variance)
noise_level_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)

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

bounds

Returns the log-transformed bounds on the theta.  hyperparameter_noise_level

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 DotProduct, WhiteKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = DotProduct() + WhiteKernel(noise_level=0.5)
>>> 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

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.WhiteKernel

  Comparison of kernel ridge and Gaussian process regression

  Gaussian process regression (GPR) with noise-level estimation

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


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


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


__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.


sklearn.get_config() [source]

Retrieve current values for configuration set by set_config  Returns

configdict

Keys are parameter names that can be passed to set_config.      See also
config_context

Context manager for global scikit-learn configuration.
set_config

Set global scikit-learn configuration.


class sklearn.impute.IterativeImputer(estimator=None, *, missing_values=nan, sample_posterior=False, max_iter=10, tol=0.001, n_nearest_features=None, initial_strategy='mean', imputation_order='ascending', skip_complete=False, min_value=- inf, max_value=inf, verbose=0, random_state=None, add_indicator=False) [source]

Multivariate imputer that estimates each feature from all the others. A strategy for imputing missing values by modeling each feature with missing values as a function of other features in a round-robin fashion. Read more in the User Guide.  New in version 0.21.   Note This estimator is still experimental for now: the predictions and the API might change without any deprecation cycle. To use it, you need to explicitly import enable_iterative_imputer: >>> # explicitly require this experimental feature
>>> from sklearn.experimental import enable_iterative_imputer  # noqa
>>> # now you can import normally from sklearn.impute
>>> from sklearn.impute import IterativeImputer
   Parameters

estimatorestimator object, default=BayesianRidge()

The estimator to use at each step of the round-robin imputation. If sample_posterior is True, the estimator must support return_std in its predict method.
missing_valuesint, np.nan, default=np.nan

The placeholder for the missing values. All occurrences of missing_values will be imputed. For pandas’ dataframes with nullable integer dtypes with missing values, missing_values should be set to np.nan, since pd.NA will be converted to np.nan.
sample_posteriorboolean, default=False

Whether to sample from the (Gaussian) predictive posterior of the fitted estimator for each imputation. Estimator must support return_std in its predict method if set to True. Set to True if using IterativeImputer for multiple imputations.
max_iterint, default=10

Maximum number of imputation rounds to perform before returning the imputations computed during the final round. A round is a single imputation of each feature with missing values. The stopping criterion is met once max(abs(X_t - X_{t-1}))/max(abs(X[known_vals])) < tol, where X_t is X at iteration t. Note that early stopping is only
applied if ``sample_posterior=False`.
tolfloat, default=1e-3

Tolerance of the stopping condition.
n_nearest_featuresint, default=None

Number of other features to use to estimate the missing values of each feature column. Nearness between features is measured using the absolute correlation coefficient between each feature pair (after initial imputation). To ensure coverage of features throughout the imputation process, the neighbor features are not necessarily nearest, but are drawn with probability proportional to correlation for each imputed target feature. Can provide significant speed-up when the number of features is huge. If None, all features will be used.
initial_strategystr, default=’mean’

Which strategy to use to initialize the missing values. Same as the strategy parameter in SimpleImputer Valid values: {“mean”, “median”, “most_frequent”, or “constant”}.
imputation_orderstr, default=’ascending’

The order in which the features will be imputed. Possible values:  “ascending”

From features with fewest missing values to most.  “descending”

From features with most missing values to fewest.  “roman”

Left to right.  “arabic”

Right to left.  “random”

A random order for each round.
skip_completeboolean, default=False

If True then features with missing values during transform which did not have any missing values during fit will be imputed with the initial imputation method only. Set to True if you have many features with no missing values at both fit and transform time to save compute.
min_valuefloat or array-like of shape (n_features,), default=-np.inf

Minimum possible imputed value. Broadcast to shape (n_features,) if scalar. If array-like, expects shape (n_features,), one min value for each feature. The default is -np.inf.  Changed in version 0.23: Added support for array-like.
max_valuefloat or array-like of shape (n_features,), default=np.inf

Maximum possible imputed value. Broadcast to shape (n_features,) if scalar. If array-like, expects shape (n_features,), one max value for each feature. The default is np.inf.  Changed in version 0.23: Added support for array-like.
verboseint, default=0

Verbosity flag, controls the debug messages that are issued as functions are evaluated. The higher, the more verbose. Can be 0, 1, or 2.
random_stateint, RandomState instance or None, default=None

The seed of the pseudo random number generator to use. Randomizes selection of estimator features if n_nearest_features is not None, the imputation_order if random, and the sampling from posterior if sample_posterior is True. Use an integer for determinism. See the Glossary.
add_indicatorboolean, default=False

If True, a MissingIndicator transform will stack onto output of the imputer’s transform. This allows a predictive estimator to account for missingness despite imputation. If a feature has no missing values at fit/train time, the feature won’t appear on the missing indicator even if there are missing values at transform/test time.    Attributes

initial_imputer_object of type SimpleImputer

Imputer used to initialize the missing values.
imputation_sequence_list of tuples

Each tuple has (feat_idx, neighbor_feat_idx, estimator), where feat_idx is the current feature to be imputed, neighbor_feat_idx is the array of other features used to impute the current feature, and estimator is the trained estimator used for the imputation. Length is self.n_features_with_missing_ *
self.n_iter_.
n_iter_int

Number of iteration rounds that occurred. Will be less than self.max_iter if early stopping criterion was reached.
n_features_with_missing_int

Number of features with missing values.
indicator_MissingIndicator

Indicator used to add binary indicators for missing values. None if add_indicator is False.
random_state_RandomState instance

RandomState instance that is generated either from a seed, the random number generator or by np.random.      See also
SimpleImputer

Univariate imputation of missing values.    Notes To support imputation in inductive mode we store each feature’s estimator during the fit phase, and predict without refitting (in order) during the transform phase. Features which contain all missing values at fit are discarded upon transform. References
1
Stef van Buuren, Karin Groothuis-Oudshoorn (2011). “mice: Multivariate Imputation by Chained Equations in R”. Journal of Statistical Software 45: 1-67.
2
S. F. Buck, (1960). “A Method of Estimation of Missing Values in Multivariate Data Suitable for use with an Electronic Computer”. Journal of the Royal Statistical Society 22(2): 302-306.   Examples >>> import numpy as np
>>> from sklearn.experimental import enable_iterative_imputer
>>> from sklearn.impute import IterativeImputer
>>> imp_mean = IterativeImputer(random_state=0)
>>> imp_mean.fit([[7, 2, 3], [4, np.nan, 6], [10, 5, 9]])
IterativeImputer(random_state=0)
>>> X = [[np.nan, 2, 3], [4, np.nan, 6], [10, np.nan, 9]]
>>> imp_mean.transform(X)
array([[ 6.9584...,  2.       ,  3.        ],
       [ 4.       ,  2.6000...,  6.        ],
       [10.       ,  4.9999...,  9.        ]])
 Methods
fit(X[, y]) Fits the imputer on X and return self.
fit_transform(X[, y]) Fits the imputer on X and return the transformed X.
get_params([deep]) Get parameters for this estimator.
set_params(**params) Set the parameters of this estimator.
transform(X) Imputes all missing values in X.
fit(X, y=None) [source]

Fits the imputer on X and return self.  Parameters

Xarray-like, shape (n_samples, n_features)

Input data, where “n_samples” is the number of samples and “n_features” is the number of features.
yignored
  Returns

selfobject

Returns self.

fit_transform(X, y=None) [source]

Fits the imputer on X and return the transformed X.  Parameters

Xarray-like, shape (n_samples, n_features)

Input data, where “n_samples” is the number of samples and “n_features” is the number of features.
yignored.
  Returns

Xtarray-like, shape (n_samples, n_features)

The imputed input data.

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.

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.

transform(X) [source]

Imputes all missing values in X. Note that this is stochastic, and that if random_state is not fixed, repeated calls, or permuted input, will yield different results.  Parameters

Xarray-like of shape (n_samples, n_features)

The input data to complete.    Returns

Xtarray-like, shape (n_samples, n_features)

The imputed input data.