sklearn.decomposition.MiniBatchDictionaryLearning?
class sklearn.decomposition.MiniBatchDictionaryLearning(n_components=None, *, alpha=1, n_iter=1000, fit_algorithm='lars', n_jobs=None, batch_size=3, shuffle=True, dict_init=None, transform_algorithm='omp', transform_n_nonzero_coefs=None, transform_alpha=None, verbose=False, split_sign=False, random_state=None, positive_code=False, positive_dict=False, transform_max_iter=1000)
Mini-batch字典學習
找到能用稀疏代碼表示數據的字典(一組原子)。
解決優化問題:
(U^*,V^*) = argmin 0.5 || Y - U V ||_2^2 + alpha * || U ||_1
(U,V)
with || V_k ||_2 = 1 for all 0 <= k < n_components
在用戶指南中閱讀更多內容
參數 | 說明 |
---|---|
n_components | int 要提取的字典元素的數量 |
alpha | float 稀疏控制參數 |
n_iter | int 要執行的迭代總數 |
fit_algorithm | {‘lars’, ‘cd’} cd:使用坐標下降法計算lasso解(linear_model.lars_path)。如果估計的組件是稀疏的,Lars會更快。 |
n_jobs | int or None, optional (default=None) 要運行的并行作業數量。沒有一個是1,除非在joblib。parallel_backend上下文。-1表示使用所有處理器。更多細節請參見術語表。 |
batch_size |
int 每批樣品的數量 |
shuffle | bool 是否在成批前對樣品進行洗牌 |
dict_init | array of shape (n_components, n_features) 用于熱重啟場景的字典的初始值 |
transform_algorithm | {‘lasso_lars’, ‘lasso_cd’, ‘lars’, ‘omp’, ‘threshold’} 用于轉換數據的算法。lars:使用最小角度回歸法(linear_model.lars_path) lasso_lars:使用lars計算Lasso解lasso_cd:使用坐標下降法計算Lasso解(linear_model.Lasso)如果估計的組件是稀疏的,lasso_lars會更快。omp:使用正交匹配追蹤估計稀疏解閾值:將投影字典中所有小于alpha的系數都壓縮為零* X ' |
transform_n_nonzero_coefs | int, 0.1 * n_features by default在解的每一列中目標的非零系數的數目。這只被algorithm='lars'和algorithm='omp'使用,在 omp 情況下被alpha 覆蓋。 |
transform_alpha | float, 1. by default 如果 algorithm'lasso_lars' 或algorithm='lasso_cd' ,則alpha 是對L1范數的懲罰。如果algorithm='threshold' ,alpha 是閾值的絕對值,低于這個閾值,系數將被壓縮為零。若algorithm='omp' ,則alpha 為容差參數:目標重構誤差的值。在本例中,它覆蓋n_nonzero_coefs 。 |
verbose | bool, optional (default: False) 控制程序的冗長。 |
split_sign | bool, False by default 是否將稀疏特征向量分割為其負部分和正部分的連接。這可以提高下游分類器的性能。 |
random_state | int, RandomState instance or None, optional (default=None) 用于在沒有指定dict_init時初始化字典,在shuffle被設置為True時隨機變換數據,以及更新字典。在多個函數調用中傳遞可重復的結果。看到術語表。 新版本0.20。 |
positive_code | bool 在尋找代碼時是否加強積極性。 |
positive_dict | bool 查找字典時是否要加強積極性。 新版本0.20。 |
transform_max_iter | int, optional (default=1000) 如果algorithm='lasso_cd'或lasso_lars,則執行的最大迭代次數。 新版本0.22。 |
屬性 | 說明 |
---|---|
components_ | array, [n_components, n_features] 從數據中提取的樣本 |
inner_stats_ | tuple of (A, B) ndarrays 由算法保存的內部充分的統計信息。保留它們在在線設置中很有用,以避免丟失演進的歷史,但它們對最終用戶不應該有任何用處。A (n_components, n_components)是字典協方差矩陣。B (n_features, n_components)是數據近似矩陣 |
n_iter_ | int 運行的迭代次數。 |
iter_offset_ | int 以前執行的數據批的迭代次數。 |
random_state_ | RandomState 由種子、隨機數生成器或np.random生成的RandomState實例。 |
另見:
筆記
參考文獻
J. Mairal, F. Bach, J. Ponce, G. Sapiro, 2009: Online dictionary learning for sparse coding (https://www.di.ens.fr/sierra/pdfs/icml09.pdf)
方法
方法 | 說明 |
---|---|
fit (self, X[, y]) |
根據X中的數據擬合模型。 |
fit_transform (self, X[, y]) |
擬合數據,然后轉換它。 |
get_params (self[, deep]) |
獲取這個估計器的參數。 |
partial_fit (self, X[, y, iter_offset]) |
使用X中的數據作為一個小批更新模型。 |
set_params (self, **params) |
設置這個估計器的參數。 |
transform (self, X) |
將數據編碼為字典原子的稀疏組合。 |
__init__(n_components=None, *, alpha=1, n_iter=1000, fit_algorithm='lars', n_jobs=None, batch_size=3, shuffle=True, dict_init=None, transform_algorithm='omp', transform_n_nonzero_coefs=None, transform_alpha=None, verbose=False, split_sign=False, random_state=None, positive_code=False, positive_dict=False, transform_max_iter=1000)
該方法適用于簡單估計器和嵌套對象(如管道)。后者具有形式為
fit(self, X, y=None)
根據X中的數據擬合模型。
參數 | 說明 |
---|---|
X | array-like, shape (n_samples, n_features) 訓練向量,其中樣本數量中的n_samples和n_features為feature的數量。 |
y | Ignored |
返回值 | 說明 |
---|---|
self | object 返回實例本身。 |
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 如果為真,將返回此估計器的參數以及包含的作為估計器的子對象。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到它們的值。 |
`partial_fit`(self, X, y=None, iter_offset=None)
使用X中的數據作為一個mini-batch更新模型。
參數 | 說明 |
---|---|
X | array-like, shape (n_samples, n_features) 訓練向量,其中樣本數量中的n_samples和n_features為feature的數量。 |
y | Ignored |
iter_offset | integer, optional 在調用partial_fit之前執行的數據批的迭代次數。這是可選的:如果沒有傳遞數字,則使用對象的內存。 |
返回值 | 說明 |
---|---|
self | object 返回實例本身。 |
set_params(self, params)
設置這個估計器的參數。
該方法適用于簡單估計器和嵌套對象(如管道)。后者具有形式為
參數 | 說明 |
---|---|
**params | dict 估計器參數 |
返回值 | 說明 |
---|---|
self | object 估計器實例。 |
transform(self, X)
將數據編碼為字典原子的稀疏組合。
編碼方法由對象參數transform_algorithm
決定。
參數 | 說明 |
---|---|
X | array of shape (n_samples, n_features) 要轉換的測試數據,必須具有與用于訓練模型的數據相同數量的特征。 |
返回值 | 說明書 |
---|---|
X_new | array, shape (n_samples, n_components) 轉換過的數據。 |