sklearn.kernel_approximation.RBFSampler?

class sklearn.kernel_approximation.RBFSampler(*, gamma=1.0, n_components=100,random_state=None)

[源碼]

用Fourier變換的Carlo approximation近似逼近RBF的特征映射。

它實現了Random Kitchen Sinks的一種變體。[1]

閱讀更多內容用戶指南.

參數 說明
gamma float
RBF核參數:exp(-gamma * x^2)
n_components int
每個原始特征的Carlo approximation樣本數。等于計算特征空間的維數。
random_state int, RandomState instance or None, optional (default=None)
偽隨機數發生器在擬合訓練數據時控制隨機權值和隨機偏移的產生。通過多個函數調用傳遞可重復輸出的int值。 請參閱詞匯表
屬性 說明
random_offset_ ndarray of shape (n_components,), dtype=float64
用于計算特征空間n_components維度中的投影的隨機偏移量。
random_weights_ ndarray of shape (n_features, n_components), dtype=float64
從RBF內核的Fourier變換得出的隨機投影方向。

參見A. Rahimi 和 Benjamin Recht的Random Features for Large-Scale Kernel Machines

[1] “Weighted Sums of Random Kitchen Sinks: Replacing minimization with randomization in learning” by A. Rahimi and Benjamin Recht. (https://people.eecs.berkeley.edu/~brecht/papers/08.rah.rec.nips.pdf)

實例

>>> from sklearn.kernel_approximation import RBFSampler
>>> from sklearn.linear_model import SGDClassifier
>>> X = [[00], [11], [10], [01]]
>>> y = [0011]
>>> rbf_feature = RBFSampler(gamma=1, random_state=1)
>>> X_features = rbf_feature.fit_transform(X)
>>> clf = SGDClassifier(max_iter=5, tol=1e-3)
>>> clf.fit(X_features, y)
SGDClassifier(max_iter=5)
>>> clf.score(X_features, y)
方法 說明
fit(self, X[, y]) 用X擬合模型。
fit_transform(self, X[, y]) 擬合數據,然后將其轉換
get_params(self[, deep]) 獲取此估計量的參數。
set_params(self, **params) 設置此估計量的參數。
transform(self, X) 將近似特征映射應用于X。
__init__(self, *, gamma=1.0, n_components=100, random_state=None)

[源碼]

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

fit(self, X, y=None)

[源碼]

擬合數據,然后對其進行轉換。

使用可選參數Fit_params將轉換器安裝到X和y,并返回轉換版本的X。

參數 說明
X {array-like, sparse matrix}, shape (n_samples, n_features)
訓練數據,其中樣本數為n_samples,特征數為n_features。
返回值 說明
self object
返回transformer
fit_transform(self,X, y=None, **fit_params)

[源碼]

擬合數據,然后轉換它。

使用可選參數fit_params將transformer擬合到X和y,并返回X的轉換版本。

參數 說明
x {array-like, sparse matrix, dataframe} of shape (n_samples, n_features)
y ndarray of shape (n_samples,), default=None
目標值。
**fit_params dict
其他擬合參數。
返回值 說明
X_new ndarray array of shape (n_samples, n_features_new)
變換數組
get_params(self, deep=True)

[來源]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算量和作為估算量的所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
set_params(self, **params)

[源碼]

設置此估計量的參數。

該方法適用于簡單的估計量以及嵌套對象(例如pipelines)。 后者的參數格式為 __ ,以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估計參數
返回值 說明
self object
估計實例
transform(self, X)

[源碼]

將近似特征映射應用于X。

參數 說明
X {array-like, sparse matrix}, shape (n_samples, n_features)
新的數據,其中n_SAMPLE中的樣本數,n_Features是特征的個數。
返回值 說明
X_new array-like, shape (n_samples, n_components)

sklearn.kernel_approximation.RBFSampler使用示例?