sklearn.gaussian_process.RationalQuadratic?

class sklearn.gaussian_process.kernels.RationalQuadratic(length_scale=1.0, alpha=1.0, length_scale_bounds=(1e-05100000.0), alpha_bounds=(1e-05100000.0))

[源碼]

有理二次內核。

有理二次核可以看作是具有不同特征長度尺度的RBF核的尺度混合物(無窮和)。它由一個長度標度參數和一個標度混合參數來參數化。目前只支持縱向尺度為標量的各向同性變量。核函數為:

其中為尺度混合參數,為核的長度尺度,為歐氏距離。有關如何設置參數的建議,請參見 [1]。

用戶指南中閱讀更多內容。

新版本 0.18 。

參數 說明
length_scale float > 0, default=1.0
核的長度尺度。
alpha float > 0, default=1.0
規模的混合參數
length_scale_bounds pair of floats >= 0 or “fixed”, default=(1e-5, 1e5)
length_scale上的下界和上界。如果設置為“固定”,則“length_scale”在超參數調優期間無法更改。
alpha_bounds pair of floats >= 0 or “fixed”, default=(1e-5, 1e5)
alpha的下界和上界。如果設置為“固定”,“alpha”在超參數調優期間不能改變。
屬性 說明
bounds 返回的對數變換界限。
hyperparameter_alpha
hyperparameter_length_scale
hyperparameters 返回所有超參數規范的列表。
n_dims) 返回內核的非固定超參數的數量。
requires_vector_input 返回內核是在固定長度的特征向量上定義的還是在通用對象上定義的。
theta) 返回(扁平的、對數轉換的)非固定超參數。

References

示例

>>> 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 = RationalQuadratic(length_scale=1.0, alpha=1.5)
>>> gpc = GaussianProcessClassifier(kernel=kernel,
...         random_state=0).fit(X, y)
>>> gpc.score(X, y)
0.9733...
>>> gpc.predict_proba(X[:2,:])
array([[0.8881..., 0.0566..., 0.05518...],
        [0.8678..., 0.0707... , 0.0614...]])

方法

方法 說明
__call__(self, X[, Y, eval_gradient]) 返回核函數k(X, Y)和它的梯度。
clone_with_theta(self, theta) 返回帶有給定超參數theta的self的克隆。
diag(self, X) 返回核函數k(X, X)的對角線。
get_params(self[, deep]) 獲取這個內核的參數。
is_stationary(self) 返回內核是否靜止。
set_params(self, **params) 設置這個內核的參數。
__init__(self, length_scale=1.0, length_scale_bounds=(1e-05100000.0))

[源碼]

初始化self. See 請參閱help(type(self))以獲得準確的說明 。

 __call__(self, X, Y=None, eval_gradient=False)

[源碼]

返回核函數k(X, Y)和它的梯度。

參數 說明
X ndarray of shape (n_samples_X, n_features)
返回核函數k(X, Y)的左參數
Y ndarray of shape (n_samples_Y, n_features), default=None
返回的核函數k(X, Y)的正確參數。如果沒有,則計算k(X, X)。
eval_gradient bool, default=False
確定關于核超參數的梯度是否確定。只有當Y沒有的時候才被支持。
返回值 說明
K ndarray of shape (n_samples_X, n_samples_Y)
內核k (X, Y)
K_gradient ndarray of shape (n_samples_X, n_samples_X, n_dims), optional
核函數k(X, X)關于核函數超參數的梯度。只有當eval_gradient為真時才返回。
property bounds

返回的對數變換界限。

返回值 說明
bounds ndarray of shape (n_dims, 2)
核函數超參數的對數變換界限
clone_with_theta(self, theta)

[源碼]

返回帶有給定超參數theta的self的克隆。

參數 說明
theta ndarray of shape (n_dims,)
的hyperparameters
diag(self, X)

[源碼]

返回核函數k(X, X)的對角線。

該方法的結果與np.diag(self(X))相同;但是,由于只計算對角,因此可以更有效地計算它。

參數 說明
X ndarray of shape (n_samples_X, n_features)
返回核函數k(X, Y)的左參數
返回值 說明
K_diag ndarray of shape (n_samples_X,)
核k(X, X)的對角線
get_params(self, deep=True)

[源碼]

獲取這個內核的參數。

參數 說明
deep bool, default=True
如果為真,將返回此估計器的參數以及包含的作為估計器的子對象。
返回值 說明
params dict
參數名稱映射到它們的值。
property hyperparameters

返回所有超參數的列表。

is_stationary(self)

[源碼]

返回內核是否靜止。

property n_dims

返回內核的非固定超參數的數量。

property requires_vector_input

返回內核是在固定長度的特征向量上定義的還是在通用對象上定義的。向后兼容性的默認值為True。

set_params(self, **params)

[源碼]

設置這個內核的參數。

該方法適用于簡單估計量和嵌套對象。后者具有形式為<component>_<parameter>的參數,這樣就讓更新嵌套對象的每個組件成為了可能。

返回值 說明
self -
property theta

返回(扁平的、對數轉換的)非固定超參數。

注意,theta通常是內核超參數的對數變換值,因為這種搜索空間的表示更適合超參數搜索,因為像長度尺度這樣的超參數自然存在于對數尺度上。

返回值 說明
theta ndarray of shape (n_dims,)
核函數的非固定、對數變換超參數