ConstantKernel#

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

常数核。

可以用作积核的一部分,其中它可以缩放其他因子(核)的幅度,也可以用作和核的一部分,其中它可以修改高斯过程的平均值。

\[k(x_1, x_2) = constant\_value \;\forall\; x_1, x_2\]

添加一个常数内核相当于添加一个常数::

kernel = RBF() + ConstantKernel(constant_value=2)

与以下内容相同:

kernel = RBF() + 2

阅读更多的 User Guide .

Added in version 0.18.

参数:
constant_valuefloat,默认=1.0

定义协方差的常数值:k(x_1,x_2)= constant_Value

constant_value_bounds浮点数对>= 0或“固定”,默认=(1 e-5,1 e5)

上下限 constant_value .如果设置为“固定”, constant_value 超参数调整期间无法更改。

示例

>>> from sklearn.datasets import make_friedman2
>>> from sklearn.gaussian_process import GaussianProcessRegressor
>>> from sklearn.gaussian_process.kernels import RBF, ConstantKernel
>>> X, y = make_friedman2(n_samples=500, noise=0, random_state=0)
>>> kernel = RBF() + ConstantKernel(constant_value=2)
>>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5,
...         random_state=0).fit(X, y)
>>> gpr.score(X, y)
0.3696...
>>> gpr.predict(X[:1,:], return_std=True)
(array([606.1...]), array([0.24...]))
__call__(X, Y=None, eval_gradient=False)[源代码]#

返回内核k(X,Y)以及可选的其梯度。

参数:
X类似阵列的形状(n_samples_X,n_features)或对象列表

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

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

返回的内核k(X,Y)的正确参数。如果无,则改为计算k(X,X)。

eval_gradient布尔,默认=假

确定是否计算相对于内核超参数日志的梯度。仅当Y为无时支持。

返回:
K形状的nd数组(n_samples_X,n_samples_Y)

核k(X,Y)

K_gradientnd形状数组(n_samples_X,n_samples_X,n_dims), 任择

核k(X,X)相对于核超参数log的梯度。仅当eval_gradient为True时返回。

property bounds#

返回theta的log转换边界。

返回:
bounds形状的nd数组(n_dims,2)

核超参数theta的log转换界限

clone_with_theta(theta)[源代码]#

返回具有给定超参数theta的自我克隆。

参数:
theta形状的nd数组(n_dims,)

超参数

diag(X)[源代码]#

Returns the diagonal of the kernel k(X, X).

该方法的结果与mp.diag(self(X))相同;但是,由于仅评估对角线,因此可以更有效地评估它。

参数:
X类似阵列的形状(n_samples_X,n_features)或对象列表

参数传递到内核。

返回:
K_diag形状的nd数组(n_samples_X,)

核k(X,X)的对角线

get_params(deep=True)[源代码]#

获取此内核的参数。

参数:
deep布尔,默认=True

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

返回:
paramsdict

参数名称映射到其值。

property hyperparameters#

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

is_stationary()[源代码]#

返回内核是否静止。

property n_dims#

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

property requires_vector_input#

内核是否仅适用于固定长度的特征载体。

set_params(**params)[源代码]#

Set the parameters of this kernel.

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

返回:
自我
property theta#

返回(拉平、日志转换)非固定超参数。

注意,theta通常是内核超参数的对数变换值,因为搜索空间的这种表示更适合超参数搜索,因为像长度尺度这样的超参数自然存在于对数尺度上。

返回:
theta形状的nd数组(n_dims,)

内核的非固定的、经过log转换的超参数