ExpSineSquared#
- class sklearn.gaussian_process.kernels.ExpSineSquared(length_scale=1.0, periodicity=1.0, length_scale_bounds=(1e-05, 100000.0), periodicity_bounds=(1e-05, 100000.0))[source]#
Exp-Sine-Squared 核(又名周期性核)。
The ExpSineSquared kernel allows one to model functions which repeat themselves exactly. It is parameterized by a length scale parameter \(l>0\) and a periodicity parameter \(p>0\). Only the isotropic variant where \(l\) is a scalar is supported at the moment. The kernel is given by
\[k(x_i, x_j) = \text{exp}\left(- \frac{ 2\sin^2(\pi d(x_i, x_j)/p) }{ l^ 2} \right)\]where \(l\) is the length scale of the kernel, \(p\) the periodicity of the kernel and \(d(\cdot,\cdot)\) is the Euclidean distance.
在 用户指南 中阅读更多内容。
版本 0.18 新增。
- 参数:
- length_scalefloat > 0, default=1.0
The length scale of the kernel.
- periodicityfloat > 0, default=1.0
The periodicity of the kernel.
- length_scale_bounds一对 float >= 0 或 “fixed”,默认值=(1e-5, 1e5)
“length_scale” 的下限和上限。如果设置为 “fixed”,则在超参数调整期间不能更改 “length_scale”。
- periodicity_boundspair of floats >= 0 or “fixed”, default=(1e-5, 1e5)
The lower and upper bound on ‘periodicity’. If set to “fixed”, ‘periodicity’ cannot be changed during hyperparameter tuning.
示例
>>> from sklearn.datasets import make_friedman2 >>> from sklearn.gaussian_process import GaussianProcessRegressor >>> from sklearn.gaussian_process.kernels import ExpSineSquared >>> X, y = make_friedman2(n_samples=50, noise=0, random_state=0) >>> kernel = ExpSineSquared(length_scale=1, periodicity=1) >>> gpr = GaussianProcessRegressor(kernel=kernel, alpha=5, ... random_state=0).fit(X, y) >>> gpr.score(X, y) 0.0144 >>> gpr.predict(X[:2,:], return_std=True) (array([425.6, 457.5]), array([0.3894, 0.3467]))
- __call__(X, Y=None, eval_gradient=False)[source]#
返回核 k(X, Y) 及其可选的梯度。
- 参数:
- Xndarray of shape (n_samples_X, n_features)
返回的核 k(X, Y) 的左参数
- Yndarray of shape (n_samples_Y, n_features), default=None
返回的核 k(X, Y) 的右参数。如果为 None,则改为计算 k(X, X)。
- eval_gradientbool, default=False
确定是否计算关于核超参数对数的梯度。仅当 Y 为 None 时支持。
- 返回:
- Kndarray of shape (n_samples_X, n_samples_Y)
核 k(X, Y)
- K_gradientndarray of shape (n_samples_X, n_samples_X, n_dims), optional
核 k(X, X) 关于核超参数对数的梯度。仅当
eval_gradient为 True 时返回。
- property bounds#
返回 theta 的对数变换边界。
- 返回:
- boundsndarray of shape (n_dims, 2)
核超参数 theta 的对数变换边界
- diag(X)[source]#
返回核 k(X, X) 的对角线。
此方法的结果与 np.diag(self(X)) 相同;然而,由于只评估对角线,它可以更有效地评估。
- 参数:
- Xndarray of shape (n_samples_X, n_features)
返回的核 k(X, Y) 的左参数
- 返回:
- K_diagndarray of shape (n_samples_X,)
核 k(X, X) 的对角线
- get_params(deep=True)[source]#
获取此核的参数。
- 参数:
- deepbool, default=True
如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- property hyperparameter_length_scale#
Returns the length scale
- property hyperparameters#
返回所有超参数规范的列表。
- property n_dims#
返回核的非固定超参数的数量。
- property requires_vector_input#
返回核是定义在固定长度特征向量上还是定义在一般对象上。为了向后兼容,默认为 True。
- set_params(**params)[source]#
设置此核的参数。
此方法适用于简单核以及嵌套核。后者具有
<component>__<parameter>形式的参数,因此可以更新嵌套对象的每个组件。- 返回:
- self
- property theta#
返回(展平的、对数变换的)非固定超参数。
请注意,theta 通常是核超参数的对数变换值,因为这种搜索空间的表示形式更适合超参数搜索,因为像长度尺度这样的超参数自然存在于对数尺度上。
- 返回:
- thetandarray of shape (n_dims,)
核的非固定、对数变换超参数