orthogonal_mp_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)[source]#

Gram 正交匹配追踪 (OMP)。

仅使用 Gram 矩阵 X.T * X 和乘积 X.T * y 来解决 n_targets 个正交匹配追踪问题。

用户指南中了解更多信息。

参数:
Gramarray-like of shape (n_features, n_features)

输入数据的Gram矩阵:X.T * X

Xyarray-like of shape (n_features,) or (n_features, n_targets)

输入目标乘以 XX.T * y

n_nonzero_coefsint, default=None

解中非零项的期望数量。如果为 None(默认值),则此值设置为 n_features 的 10%。

tolfloat, default=None

残差的最大平方范数。如果不是 None,则会覆盖 n_nonzero_coefs

norms_squaredarray-like of shape (n_targets,), default=None

y 的行向量的平方 L2 范数。如果 tol 不为 None,则必需。

copy_Grambool, default=True

算法是否必须复制 Gram 矩阵。只有当它已经是 Fortran 顺序时,False 值才有用,否则无论如何都会进行复制。

copy_Xybool, default=True

算法是否必须复制协方差向量 Xy。如果为 False,则可能会被覆盖。

return_pathbool, default=False

是否返回沿前向路径的非零系数的每个值。对于交叉验证很有用。

return_n_iterbool, default=False

是否返回迭代次数。

返回:
coefshape 为 (n_features,) 或 (n_features, n_targets) 的 ndarray

OMP 解的系数。如果 return_path=True,则包含整个系数路径。在这种情况下,其形状为 (n_features, n_features)(n_features, n_targets, n_features),并且对最后一个轴进行迭代会按活动特征的递增顺序产生系数。

n_iterslist or int

每个目标的活动特征数量。仅在 return_n_iter 设置为 True 时返回。

另请参阅

OrthogonalMatchingPursuit

正交匹配追踪模型 (OMP)。

orthogonal_mp

解决 n_targets 个正交匹配追踪问题。

lars_path

Compute Least Angle Regression or Lasso path using LARS algorithm.

sklearn.decomposition.sparse_encode

通用稀疏编码。结果的每一列都是 Lasso 问题的解。

注意事项

正交匹配追踪(Orthogonal matching pursuit)由 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])