sklearn.kernel_approximation.AdditiveChi2Sampler?

class sklearn.kernel_approximation.AdditiveChi2Sampler(*, sample_steps=2, sample_interval=None)

[源碼]

AdditiveChi2Sampler內核的近似特征圖

在一定的區間內對核特征進行Fourier變換采樣。

由于要逼近的核是可加的,所以輸入向量的分量可以單獨處理。原始空間中的每個條目被轉換為2*SAMPLE_STEP+1特性,其中SAMPLE_STEP是該方法的一個參數。SAMPLE_STEP的典型值包括1、2和3。

可以計算某些數據范圍的抽樣間隔的最佳選擇(參見參考)。默認值應該是合理的。

閱讀更多內容用戶指南.

參數 說明
sample_steps int, optional
給出(復)取樣點的數目。
sample_interval float, optional
采樣間隔,當SAMPLE_STEP不在{1,2,3}中時必須指定。
屬性 說明
sample_interval_ float
存儲采樣間隔如果SAMPLE_STEP不在{1,2,3}中指定為參數。

另見

此估算器近似近加和卡方內核的版本,由metric.additive_chi2計算。

參考文獻

1 See “Efficient additive kernels via explicit feature maps” A. Vedaldi and A. Zisserman, Pattern Analysis and Machine Intelligence, 2011

實例

>>> from sklearn.datasets import load_digits
>>> from sklearn.linear_model import SGDClassifier
>>> from sklearn.kernel_approximation import AdditiveChi2Sampler
>>> X, y = load_digits(return_X_y=True)
>>> chi2sampler = AdditiveChi2Sampler(sample_steps=2)
>>> X_transformed = chi2sampler.fit_transform(X, y)
>>> clf = SGDClassifier(max_iter=5, random_state=0, tol=1e-3)
>>> clf.fit(X_transformed, y)
SGDClassifier(max_iter=5, random_state=0)
>>> clf.score(X_transformed, y)
0.9499...
方法 說明
fit(self, X[, y]) 設置參數
fit_transform(self, X[, y]) 適合數據,然后轉換它。
get_params(self[, deep]) 獲取此估計器的參數。
set_params(self, **params) 設置此估計器的參數。
transform(self, X) 將近似特征映射應用于X。
__init__(self, *, sample_steps=2, sample_interval=None)

[源碼]

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

fit(self, X, y=None)

[源碼]

設置參數

參數 說明
X array-like, shape (n_samples, n_features)
訓練數據,其中n個樣本中的樣本數和n個特征數就是特征數。
返回值 說明
self object
返回 transformer
fit_transform(self, X, y=None,**fit_params)

[源碼]

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

使用可選參數fit_params將轉換器擬合到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} of shape (n_samples, n_features)
返回值 說明
X_new {array, sparse matrix}, shape = (n_samples, n_features * (2*sample_steps + 1))
返回值是否為稀疏矩陣數組取決于輸入X的類型。