orthogonal_mp# (正交匹配追踪)
- sklearn.linear_model.orthogonal_mp(X, y, *, n_nonzero_coefs=None, tol=None, precompute=False, copy_X=True, return_path=False, return_n_iter=False)[原始碼]#
正交匹配追蹤 (Orthogonal Matching Pursuit, OMP)。
解決 n_targets 個正交匹配追蹤問題。問題實例的形式如下:
當使用
n_nonzero_coefs
參數化非零係數的數量時:argmin ||y - Xgamma||^2,條件是 ||gamma||_0 <= n_{nonzero coefs}當使用
tol
參數化誤差時:argmin ||gamma||_0,條件是 ||y - Xgamma||^2 <= tol詳情請參閱使用者指南。
- 參數:
- X類陣列 (array-like),形狀為 (n_samples, n_features)
輸入資料。假設各列具有單位範數。
- yndarray,形狀為 (n_samples,) 或 (n_samples, n_targets)
輸入目標值。
- n_nonzero_coefs整數 (int),預設為 None
解中所需的非零項數量。如果為 None(預設),則此值設定為 n_features 的 10%。
- tol浮點數 (float),預設為 None
殘差的最大平方範數。如果不是 None,則覆寫 n_nonzero_coefs。
- precompute‘auto’ 或 布林值 (bool),預設為 False
是否執行預先計算。當 n_targets 或 n_samples 非常大時,可以提高效能。
- copy_X布林值 (bool),預設為 True
演算法是否必須複製設計矩陣 X。只有在 X 已是 Fortran 順序時,值為 False 才有用,否則無論如何都會進行複製。
- return_path布林值 (bool),預設為 False
是否沿著前向路徑返回每個非零係數的值。對交叉驗證很有用。
- return_n_iter布林值 (bool),預設為 False
是否返回迭代次數。
- 返回:
- coefndarray,形狀為 (n_features,) 或 (n_features, n_targets)
OMP 解的係數。如果
return_path=True
,則包含整個係數路徑。在這種情況下,其形狀為 (n_features, n_features) 或 (n_features, n_targets, n_features),並且迭代最後一個軸會產生活動特徵按遞增順序排列的係數。- n_iters類陣列 (array-like) 或 整數 (int)
每個目標的活動特徵數量。僅在
return_n_iter
設定為 True 時返回。
另請參閱
OrthogonalMatchingPursuit
正交匹配追蹤模型。
orthogonal_mp_gram
使用 Gram 矩陣和 X.T * y 的乘積來解決 OMP 問題。
lars_path
使用 LARS 演算法計算最小角度迴歸或 Lasso 路徑。
sklearn.decomposition.sparse_encode
稀疏編碼。
註解
正交匹配追蹤是在 S. Mallat, Z. Zhang, Matching pursuits with time-frequency dictionaries, IEEE Transactions on Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415 中引入的。( https://www.di.ens.fr/~mallat/papiers/MallatPursuit93.pdf)
此實作基於 Rubinstein, R., Zibulevsky, M. and Elad, M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal Matching Pursuit Technical Report - CS Technion, April 2008. https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf
範例
>>> from sklearn.datasets import make_regression >>> from sklearn.linear_model import orthogonal_mp >>> X, y = make_regression(noise=4, random_state=0) >>> coef = orthogonal_mp(X, y) >>> coef.shape (100,) >>> X[:1,] @ coef array([-78.68...])