當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python sklearn sparse_encode用法及代碼示例

本文簡要介紹python語言中 sklearn.decomposition.sparse_encode 的用法。

用法:

sklearn.decomposition.sparse_encode(X, dictionary, *, gram=None, cov=None, algorithm='lasso_lars', n_nonzero_coefs=None, alpha=None, copy_cov=True, init=None, max_iter=1000, n_jobs=None, check_input=True, verbose=0, positive=False)

稀疏編碼

結果的每一行都是稀疏編碼問題的解決方案。目標是找到一個稀疏數組code,這樣:

X ~= code * dictionary

在用戶指南中閱讀更多信息。

參數

Xndarray 形狀(n_samples,n_features)

數據矩陣。

dictionaryndarray 形狀(n_components,n_features)

用於解決數據稀疏編碼的字典矩陣。一些算法假定規範化的行以獲得有意義的輸出。

gramndarray 形狀(n_components,n_components),默認=None

預先計算的 Gram 矩陣,dictionary * dictionary'

covndarray 形狀(n_components,n_samples),默認=None

預先計算的協方差,dictionary' * X

algorithm{‘lasso_lars’, ‘lasso_cd’, ‘lars’, ‘omp’, ‘threshold’},默認='lasso_lars'

使用的算法:

  • 'lars':使用最小角度回歸法(linear_model.lars_path);
  • 'lasso_lars' : 使用 Lars 計算 Lasso 解;
  • 'lasso_cd' :使用坐標下降法計算 Lasso 解(linear_model.Lasso)。 lasso_lars如果估計的組件稀疏,會更快;
  • 'omp':使用正交匹配追蹤估計稀疏解;
  • 'threshold' :將小於投影 dictionary * data' 的正則化的所有係數壓縮為零。
n_nonzero_coefs整數,默認=無

解的每列中要定位的非零係數的數量。這僅由algorithm='lars'algorithm='omp' 使用,並在omp 情況下被alpha 覆蓋。如果 None ,那麽 n_nonzero_coefs=int(n_features / 10)

alpha浮點數,默認=無

如果 algorithm='lasso_lars'algorithm='lasso_cd'alpha 是應用於 L1 範數的懲罰。如果 algorithm='threshold'alpha 是閾值的絕對值,低於該閾值的係數將被壓縮為零。如果 algorithm='omp'alpha 是容差參數:目標重建誤差的值。在這種情況下,它會覆蓋 n_nonzero_coefs 。如果 None ,默認為 1。

copy_cov布爾,默認=真

是否複製預計算的協方差矩陣;如果 False ,它可能會被覆蓋。

initndarray 形狀(n_samples,n_components),默認=None

稀疏代碼的初始化值。僅在 algorithm='lasso_cd' 時使用。

max_iter整數,默認=1000

algorithm='lasso_cd''lasso_lars' 時要執行的最大迭代次數。

n_jobs整數,默認=無

要運行的並行作業數。 None 表示 1,除非在 joblib.parallel_backend 上下文中。 -1 表示使用所有處理器。有關詳細信息,請參閱詞匯表。

check_input布爾,默認=真

如果 False ,則不會檢查輸入數組 X 和字典。

verbose整數,默認=0

控製詳細程度;越高,消息越多。

positive布爾,默認=假

查找編碼時是否強製執行積極性。

返回

codendarray 形狀(n_samples,n_components)

稀疏的代碼

相關用法


注:本文由純淨天空篩選整理自scikit-learn.org大神的英文原創作品 sklearn.decomposition.sparse_encode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。