sklearn.kernel_approximation.Nystroem?
class sklearn.kernel_approximation.Nystroem(kernel='rbf', *, gamma=None, coef0=None, degree=None, kernel_params=None, n_components=100, random_state=None)
[源碼]
使用訓練數據的子集近似核映射。
以數據的子集為基礎構造任意核的近似特征映射。
閱讀更多內容用戶指南.
新版本0.13。
參數 | 說明 |
---|---|
kernel | string or callable, default=”rbf” 要近似的內核映射。 一個callable應該接受兩個參數和作為參數傳遞給該對象的關鍵字參數kernel_params,并且返回一個浮點數。 |
gamma | float, default=None RBF, laplacian, polynomial, exponential chi2 和 sigmoid kernels的Gamma參數。內核部分給出默認值的解釋,請參閱sklearn.metrics.pairwise的文檔。 被其他內核忽略。 |
coef0 | float, default=None polynomial 和 sigmoid kernels的系數為零。 被其他內核忽略。 |
degree | float, default=None polynomial kernel的度。被其他內核忽略。 |
kernel_params | mapping of string to any, optional 作為可調用對象傳遞的內核函數的其他參數(關鍵字參數)。 |
n_components | int 要構建的特征數量。 多少個數據點將用于構造映射。 |
random_state | int, RandomState instance or None, optional (default=None) 偽隨機數生成器,用于控制均勻采樣,而無需替換訓練數據的n_component來構造基礎內核。 為多個函數調用傳遞可重復輸出的int值。 請參閱詞匯表。 |
屬性 | 說明 |
---|---|
components_ | array, shape (n_components, n_features) 用于構造特征圖的訓練點子集。 |
component_indices_ | array, shape (n_components) 訓練集中components_的索引。 |
normalization_ | array, shape (n_components, n_components) 嵌入所需的歸一化矩陣。components_上核矩陣的平方根。 |
另見
用隨機Fourier特征逼近RBF核。
sklearn.metrics.pairwise.kernel_metrics
內置內核列表。
參考文獻
1 Williams, C.K.I. and Seeger, M. “Using the Nystroem method to speed up kernel machines”, Advances in neural information processing systems 2001
2 T. Yang, Y. Li, M. Mahdavi, R. Jin and Z. Zhou “Nystroem Method vs Random Fourier Features: A Theoretical and Empirical Comparison”, Advances in Neural Information Processing Systems 2012
實例
>>> from sklearn import datasets, svm
>>> from sklearn.kernel_approximation import Nystroem
>>> X, y = datasets.load_digits(n_class=9, return_X_y=True)
>>> data = X / 16.
>>> clf = svm.LinearSVC()
>>> feature_map_nystroem = Nystroem(gamma=.2,
... random_state=1,
... n_components=300)
>>> data_transformed = feature_map_nystroem.fit_transform(data)
>>> clf.fit(data_transformed, y)
LinearSVC()
>>> clf.score(data_transformed, y)
0.9987...
方法 | 說明 |
---|---|
fit (self, X[, y]) |
擬合數據的估計量。 |
fit_transform (self, X[, y]) |
擬合數據,然后轉換它。 |
get_params (self[, deep]) |
獲取此估計器的參數。 |
set_params (self, **params) |
設置此估計器的參數。 |
transform (self, X) |
將特征映射應用于X。 |
__init__(self, kernel='rbf', *, gamma=None, coef0=None, degree=None, kernel_params=None, n_components=100, random_state=None)
[源碼]
初始化self, 請參閱help(type(self))以獲得準確的說明
fit(self, X, y=None)
[源碼]
擬合數據的估計量。
對訓練點的子集進行采樣,在此基礎上計算核并計算歸一化矩陣。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 訓練數據 |
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之間的核來計算一個近似特征圖。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 要轉換的數據。 |
返回值 | 說明 |
---|---|
X_transformed | array, shape=(n_samples, n_components) 轉換數據。 |