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

正交匹配追踪 (OMP)。

解决 n_targets 个正交匹配追踪问题。一个问题实例的形式为:

当使用 n_nonzero_coefs 参数化非零系数的数量时:argmin ||y - Xgamma||^2 约束条件 ||gamma||_0 <= n_{nonzero coefs}

当使用参数 tol 参数化误差时:argmin ||gamma||_0 约束条件 ||y - Xgamma||^2 <= tol

用户指南 中阅读更多信息。

参数:
Xarray-like of shape (n_samples, n_features)

输入数据。假定列具有单位范数。

yndarray of shape (n_samples,) or (n_samples, n_targets)

输入目标。

n_nonzero_coefsint, default=None

解中所需的非零条目数量。如果为 None (默认),则此值设置为 n_features 的 10%。

tolfloat, default=None

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

precompute‘auto’ or bool, default=False

是否执行预计算。当 n_targets 或 n_samples 非常大时,可提高性能。

copy_Xbool, default=True

设计矩阵 X 是否必须由算法复制。只有当 X 已经按照 Fortran 顺序排列时,false 值才有用,否则无论如何都会进行复制。

return_pathbool, default=False

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

return_n_iterbool, default=False

是否返回迭代次数。

返回:
coefndarray of shape (n_features,) or (n_features, n_targets)

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

n_itersarray-like or int

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

另请参阅

OrthogonalMatchingPursuit

正交匹配追踪模型。

orthogonal_mp_gram

使用 Gram 矩阵和乘积 X.T * y 解决 OMP 问题。

lars_path

使用 LARS 算法计算最小角回归或 Lasso 路径。

sklearn.decomposition.sparse_encode

稀疏编码。

注释

正交匹配追踪(Orthogonal matching pursuit)由 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. 和 Elad, M.,于 2008 年 4 月发表的《Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal Matching Pursuit Technical Report - CS Technion》。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])