OrthogonalMatchingPursuit#

class sklearn.linear_model.OrthogonalMatchingPursuit(*, n_nonzero_coefs=None, tol=None, fit_intercept=True, precompute='auto')[source]#

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

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

参数:
n_nonzero_coefsint, default=None

解中非零项的期望数量。如果设置了 tol,则忽略此参数。当 Nonetol 也为 None 时,此值设置为 n_features 的 10% 或 1,取两者中的较大值。

tolfloat, default=None

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

fit_interceptbool, default=True

Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (i.e. data is expected to be centered).

precompute‘auto’ or bool, default=’auto’

是否使用预计算的 Gram 和 Xy 矩阵来加快计算速度。当 n_targetsn_samples 非常大时,可提高性能。

属性:
coef_ndarray of shape (n_features,) or (n_targets, n_features)

参数向量(公式中的 w)。

intercept_float or ndarray of shape (n_targets,)

决策函数中的独立项。

n_iter_int or array-like

每个目标上的活动特征数量。

n_nonzero_coefs_int or None

解中非零系数的数量,如果设置了 tol,则为 None。如果 n_nonzero_coefs 为 None 且 tol 为 None,则此值设置为 n_features 的 10% 或 1,取两者中的较大值。

n_features_in_int

拟合 期间看到的特征数。

0.24 版本新增。

feature_names_in_shape 为 (n_features_in_,) 的 ndarray

fit 期间看到的特征名称。仅当 X 具有全部为字符串的特征名称时才定义。

1.0 版本新增。

另请参阅

orthogonal_mp

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

orthogonal_mp_gram

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

lars_path

Compute Least Angle Regression or Lasso path using LARS algorithm.

Lars

最小角回归模型,又名 LAR。

LassoLars

使用最小角回归(又名 Lars)拟合的 Lasso 模型。

sklearn.decomposition.sparse_encode

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

OrthogonalMatchingPursuitCV

交叉验证的正交匹配追踪模型 (OMP)。

注意事项

正交匹配追踪由 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.linear_model import OrthogonalMatchingPursuit
>>> from sklearn.datasets import make_regression
>>> X, y = make_regression(noise=4, random_state=0)
>>> reg = OrthogonalMatchingPursuit().fit(X, y)
>>> reg.score(X, y)
0.9991
>>> reg.predict(X[:1,])
array([-78.3854])
fit(X, y)[source]#

Fit the model using X, y as training data.

参数:
Xshape 为 (n_samples, n_features) 的 array-like

训练数据。

yshape 为 (n_samples,) 或 (n_samples, n_targets) 的 array-like

目标值。如有必要,将被转换为 X 的 dtype。

返回:
selfobject

Returns an instance of self.

get_metadata_routing()[source]#

获取此对象的元数据路由。

请查阅 用户指南,了解路由机制如何工作。

返回:
routingMetadataRequest

封装路由信息的 MetadataRequest

get_params(deep=True)[source]#

获取此估计器的参数。

参数:
deepbool, default=True

如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。

返回:
paramsdict

参数名称映射到其值。

predict(X)[source]#

使用线性模型进行预测。

参数:
Xarray-like or sparse matrix, shape (n_samples, n_features)

样本。

返回:
Carray, shape (n_samples,)

返回预测值。

score(X, y, sample_weight=None)[source]#

返回测试数据的 决定系数

决定系数 \(R^2\) 定义为 \((1 - \frac{u}{v})\),其中 \(u\) 是残差平方和 ((y_true - y_pred)** 2).sum()\(v\) 是总平方和 ((y_true - y_true.mean()) ** 2).sum()。最佳得分为 1.0,得分可能为负(因为模型可能任意地差)。一个总是预测 y 期望值(忽略输入特征)的常数模型将获得 \(R^2\) 得分 0.0。

参数:
Xshape 为 (n_samples, n_features) 的 array-like

测试样本。对于某些估计器,这可能是一个预先计算的核矩阵或一个通用对象列表,形状为 (n_samples, n_samples_fitted),其中 n_samples_fitted 是用于估计器拟合的样本数。

yshape 为 (n_samples,) 或 (n_samples, n_outputs) 的 array-like

X 的真实值。

sample_weightshape 为 (n_samples,) 的 array-like, default=None

样本权重。

返回:
scorefloat

self.predict(X) 相对于 y\(R^2\)

注意事项

自 0.23 版本起,对回归器调用 score 时使用的 \(R^2\) 得分使用 multioutput='uniform_average',以与 r2_score 的默认值保持一致。这会影响所有多输出回归器(除了 MultiOutputRegressor)的 score 方法。

set_params(**params)[source]#

设置此估计器的参数。

此方法适用于简单的估计器以及嵌套对象(如 Pipeline)。后者具有 <component>__<parameter> 形式的参数,以便可以更新嵌套对象的每个组件。

参数:
**paramsdict

估计器参数。

返回:
selfestimator instance

估计器实例。

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') OrthogonalMatchingPursuit[source]#

配置是否应请求元数据以传递给 score 方法。

请注意,此方法仅在以下情况下相关:此估计器用作 元估计器 中的子估计器,并且通过 enable_metadata_routing=True 启用了元数据路由(请参阅 sklearn.set_config)。请查看 用户指南 以了解路由机制的工作原理。

每个参数的选项如下:

  • True:请求元数据,如果提供则传递给 score。如果未提供元数据,则忽略该请求。

  • False:不请求元数据,元估计器不会将其传递给 score

  • None:不请求元数据,如果用户提供元数据,元估计器将引发错误。

  • str:应将元数据以给定别名而不是原始名称传递给元估计器。

默认值 (sklearn.utils.metadata_routing.UNCHANGED) 保留现有请求。这允许您更改某些参数的请求而不更改其他参数。

在版本 1.3 中新增。

参数:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

score 方法中 sample_weight 参数的元数据路由。

返回:
selfobject

更新后的对象。