正交匹配追蹤 (Gram)#
- sklearn.linear_model.orthogonal_mp_gram(Gram, Xy, *, n_nonzero_coefs=None, tol=None, norms_squared=None, copy_Gram=True, copy_Xy=True, return_path=False, return_n_iter=False)[來源]#
Gram 正交匹配追蹤 (OMP)。
僅使用 Gram 矩陣 X.T * X 和乘積 X.T * y 解決 n_targets 個正交匹配追蹤問題。
在 使用者指南中閱讀更多內容。
- 參數:
- Gram形狀為 (n_features, n_features) 的類陣列
輸入資料的 Gram 矩陣:
X.T * X
。- Xy形狀為 (n_features,) 或 (n_features, n_targets) 的類陣列
輸入目標乘以
X
:X.T * y
。- n_nonzero_coefsint,預設值=None
解中非零項的期望數量。如果為
None
(預設值),則此值設定為 n_features 的 10%。- tolfloat,預設值為 None
殘差的最大平方範數。如果不是
None
,則會覆蓋n_nonzero_coefs
。- norms_squared類陣列,形狀為 (n_targets,),預設值為 None
y
的各列的 L2 範數平方。如果tol
不是 None 時為必要。- copy_Grambool,預設值為 True
演算法是否必須複製 Gram 矩陣。只有當 Gram 矩陣已經以 Fortran 順序排列時,
False
值才有幫助,否則無論如何都會進行複製。- copy_Xybool,預設值為 True
演算法是否必須複製共變異數向量
Xy
。如果為False
,則可能會被覆蓋。- return_pathbool,預設值為 False
是否返回前向路徑中每個非零係數的值。這對於交叉驗證很有用。
- return_n_iterbool,預設值為 False
是否返回迭代次數。
- 返回:
- coef形狀為 (n_features,) 或 (n_features, n_targets) 的 ndarray
OMP 解的係數。如果
return_path=True
,則包含整個係數路徑。在這種情況下,它的形狀為(n_features, n_features)
或(n_features, n_targets, n_features)
,並且迭代最後一個軸會產生依活動特徵的增加順序排列的係數。- n_iters列表或整數
每個目標的活動特徵數量。僅當
return_n_iter
設為 True 時才會返回。
另請參閱
OrthogonalMatchingPursuit
正交匹配追蹤模型 (OMP)。
orthogonal_mp
解決 n_targets 個正交匹配追蹤問題。
lars_path
使用 LARS 演算法計算最小角回歸或 Lasso 路徑。
sklearn.decomposition.sparse_encode
通用稀疏編碼。結果的每一列都是 Lasso 問題的解。
註解
正交匹配追蹤是在 G. 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_gram >>> X, y = make_regression(noise=4, random_state=0) >>> coef = orthogonal_mp_gram(X.T @ X, X.T @ y) >>> coef.shape (100,) >>> X[:1,] @ coef array([-78.68...])