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 个正交匹配追踪问题。
在用户指南中了解更多信息。
- 参数:
- Gram形状为 (n_features, n_features) 的类数组
输入数据的 Gram 矩阵:
X.T * X。- Xy形状为 (n_features,) 或 (n_features, n_targets) 的类数组
输入目标值乘以
X的结果:X.T * y。- n_nonzero_coefsint, default=None
解中所需的非零项个数。如果为
None(默认值),该值被设置为 n_features 的 10%。- tolfloat, default=None
残差的最大平方范数。如果不是
None,将覆盖n_nonzero_coefs。- norms_squared形状为 (n_targets,) 的类数组,默认=None
y的行的 L2 范数的平方。如果tol不为 None,则必需。- copy_Grambool, default=True
算法是否必须复制 Gram 矩阵。仅当矩阵已经是 Fortran 顺序时,设为
False才有帮助,否则仍会进行复制。- copy_Xybool,默认=True
算法是否必须复制协方差向量
Xy。如果为False,它可能会被覆盖。- return_pathbool,默认=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_iters列表或整数
每个目标下的活跃特征数量。仅在
return_n_iter设置为 True 时返回。
另请参阅
OrthogonalMatchingPursuit正交匹配追踪模型 (OMP)。
orthogonal_mp解决 n_targets 个正交匹配追踪问题。
lars_pathCompute 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. (1993年12月), 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])