Kernel#
- class sklearn.gaussian_process.kernels.Kernel[來源]#
所有核函數的基底類別。
在版本 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 的對數轉換邊界。
- 傳回值:
- bounds形狀為 (n_dims, 2) 的 ndarray
核函數的超參數 theta 的對數轉換邊界
- abstract diag(X)[來源]#
傳回核函數 k(X, X) 的對角線。
此方法的結果與 np.diag(self(X)) 相同;但是,由於僅評估對角線,因此可以更有效率地進行評估。
- 參數:
- X形狀為 (n_samples,) 的類陣列
傳回的核函數 k(X, Y) 的左側引數
- 傳回值:
- K_diag形狀為 (n_samples_X,) 的 ndarray
核函數 k(X, X) 的對角線
- get_params(deep=True)[來源]#
取得此核函數的參數。
- 參數:
- deep布林值,預設值為 True
如果為 True,將傳回此估算器和包含的子物件(即估算器)的參數。
- 傳回值:
- params字典
參數名稱對應到其值。
- property hyperparameters#
傳回所有超參數規格的清單。
- property n_dims#
傳回核函數的非固定超參數數量。
- property requires_vector_input#
傳回核函數是在固定長度特徵向量還是泛型物件上定義。為了向後相容,預設值為 True。
- set_params(**params)[來源]#
設定此核函數的參數。
此方法適用於簡單核函數以及巢狀核函數。後者的參數形式為
<component>__<parameter>
,因此可以更新巢狀物件的每個元件。- 傳回值:
- self
- property theta#
傳回(扁平化、對數轉換的)非固定超參數。
請注意,theta 通常是核函數超參數的對數轉換值,因為這種搜尋空間的表示形式更適合超參數搜尋,因為長度尺度等超參數自然地存在於對數尺度上。
- 傳回值:
- theta形狀為 (n_dims,) 的 ndarray
核函數的非固定、對數轉換超參數