马特恩#
- class sklearn.gaussian_process.kernels.Matern(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), nu=1.5)[源代码]#
Matern内核。
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 theRBF
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).内核由下式给出:
\[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.
阅读更多的 User Guide .
Added in version 0.18.
- 参数:
- length_scalefloat or ndarray of shape(n_features,),default=1.0
内核的长度规模。如果是float,则使用各向同性内核。如果是数组,则使用各向异性核,其中l的每个维度定义了相应特征维度的长度尺度。
- length_scale_bounds浮点数对>= 0或“固定”,默认=(1 e-5,1 e5)
“long_scale”的下限和上限。如果设置为“fixed”,则在超参数调优期间无法更改“long_scale”。
- nufloat,默认=1.5
参数nu控制学习函数的平滑度。nu越小,逼近的函数越不光滑。对于nu=inf,核等效于RBS核,对于nu=0.5,核等效于绝对指数核。重要的中间值是nu=1.5(一次可微函数)和nu=2.5(两次可微函数)。注意,nu的值不在 [0.5, 1.5, 2.5, inf] 产生相当高的计算成本(大约。高10倍),因为他们需要评估修改后的贝塞尔函数。此外,与l相反,nu保持固定在其初始值并且未优化。
引用
[1]Carl Edward Rasmussen, Christopher K. I. Williams (2006). "Gaussian Processes for Machine Learning". The MIT Press. <http://www.gaussianprocess.org/gpml/>
_示例
>>> 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...]])
- __call__(X, Y=None, eval_gradient=False)[源代码]#
返回内核k(X,Y)以及可选的其梯度。
- 参数:
- X形状的nd数组(n_samples_X,n_features)
返回的内核k(X,Y)的左参数
- Y形状的nd数组(n_samples_Y,n_features),默认=无
返回的内核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
是真的
- property bounds#
返回theta的log转换边界。
- 返回:
- bounds形状的nd数组(n_dims,2)
核超参数theta的log转换界限
- diag(X)[源代码]#
Returns the diagonal of the kernel k(X, X).
该方法的结果与mp.diag(self(X))相同;但是,由于仅评估对角线,因此可以更有效地评估它。
- 参数:
- X形状的nd数组(n_samples_X,n_features)
返回的内核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转换的超参数