内核#
- class sklearn.gaussian_process.kernels.Kernel[源代码]#
所有内核的Base Class。
Added in version 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]]
- property bounds#
返回theta的log转换边界。
- 返回:
- bounds形状的nd数组(n_dims,2)
核超参数theta的log转换界限
- abstractmethod diag(X)[源代码]#
Returns the diagonal of the kernel k(X, X).
该方法的结果与mp.diag(self(X))相同;但是,由于仅评估对角线,因此可以更有效地评估它。
- 参数:
- X形状类似阵列(n_samples,)
返回的内核k(X,Y)的左参数
- 返回:
- K_diag形状的nd数组(n_samples_X,)
核k(X,X)的对角线
- get_params(deep=True)[源代码]#
获取此内核的参数。
- 参数:
- deep布尔,默认=True
如果为True,将返回此估计量和包含的作为估计量的子对象的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- property hyperparameters#
返回所有超参数规范的列表。
- property n_dims#
返回内核非固定超参数的数量。
- property requires_vector_input#
返回内核是在固定长度特征载体上还是在通用对象上定义的。默认为True以实现向后兼容性。
- set_params(**params)[源代码]#
Set the parameters of this kernel.
该方法适用于简单内核和嵌套内核。后者具有以下形式的参数
<component>__<parameter>
以便可以更新嵌套对象的每个组件。- 返回:
- 自我
- property theta#
返回(拉平、日志转换)非固定超参数。
注意,theta通常是内核超参数的对数变换值,因为搜索空间的这种表示更适合超参数搜索,因为像长度尺度这样的超参数自然存在于对数尺度上。
- 返回:
- theta形状的nd数组(n_dims,)
内核的非固定的、经过log转换的超参数