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在用户指南中了解更多信息。
- 参数:
- Xshape 为 (n_samples, n_features) 的 array-like
输入数据。假定列具有单位范数。
- 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’ 或 bool, default=False
是否执行预计算。当 n_targets 或 n_samples 非常大时,可提高性能。
- copy_Xbool, default=True
设计矩阵 X 是否必须由算法复制。只有当 X 已经是 Fortran 顺序时,False 值才有帮助,否则仍会进行复制。
- return_pathbool, default=False
是否返回前向路径上非零系数的每个值。对交叉验证很有用。
- return_n_iterbool, default=False
是否返回迭代次数。
- 返回:
- coefshape 为 (n_features,) 或 (n_features, n_targets) 的 ndarray
OMP 解的系数。如果
return_path=True,则包含整个系数路径。在这种情况下,其 shape 为 (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_pathCompute Least Angle Regression or Lasso path using LARS algorithm.
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])