Kernel#

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

所有核函数的基类。

0.18 版本新增。

示例

>>> from sklearn.gaussian_process.kernels import Kernel, RBF
>>> import numpy as np
>>> class CustomKernel(Kernel):
...     def __init__(self, length_scale=1.0):
...         self.length_scale = length_scale
...     def __call__(self, X, Y=None):
...         if Y is None:
...             Y = X
...         return np.inner(X, X if Y is None else Y) ** 2
...     def diag(self, X):
...         return np.ones(X.shape[0])
...     def is_stationary(self):
...         return True
>>> kernel = CustomKernel(length_scale=2.0)
>>> X = np.array([[1, 2], [3, 4]])
>>> print(kernel(X))
[[ 25 121]
 [121 625]]
abstract __call__(X, Y=None, eval_gradient=False)[source]#

评估核函数。

property bounds#

返回 theta 的对数变换边界。

返回:
boundsndarray of shape (n_dims, 2)

核函数超参数 theta 的对数变换边界

clone_with_theta(theta)[source]#

返回一个带有给定超参数 theta 的自身克隆。

参数:
thetandarray of shape (n_dims,)

超参数

abstract diag(X)[source]#

返回核函数 k(X, X) 的对角线。

此方法的结果与 np.diag(self(X)) 相同;但是,由于只评估对角线,因此可以更高效地进行评估。

参数:
Xarray-like of shape (n_samples,)

返回的核函数 k(X, Y) 的左参数

返回:
K_diagndarray of shape (n_samples_X,)

核函数 k(X, X) 的对角线

get_params(deep=True)[source]#

获取此核函数的参数。

参数:
deepbool, default=True

如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数。

返回:
paramsdict

参数名称及其对应的值。

property hyperparameters#

返回所有超参数规格的列表。

abstract is_stationary()[source]#

返回核函数是否是平稳的。

property n_dims#

返回核函数非固定超参数的数量。

property requires_vector_input#

返回核函数是定义在固定长度特征向量上还是通用对象上。为了向后兼容,默认为 True。

set_params(**params)[source]#

设置此核函数的参数。

此方法适用于简单核函数和嵌套核函数。后者具有 <component>__<parameter> 形式的参数,因此可以更新嵌套对象的每个组件。

返回:
self
property theta#

返回(展平的、对数变换的)非固定超参数。

请注意,theta 通常是核函数超参数的对数变换值,因为这种搜索空间的表示形式更适合超参数搜索,例如长度尺度等超参数自然存在于对数尺度上。

返回:
thetandarray of shape (n_dims,)

核函数的非固定、对数变换超参数