OrthogonalMatchingPursuit#

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

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

更多信息请参阅 用户指南

Parameters:
n_nonzero_coefsint, 默认=None

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

tolfloat, 默认=None

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

fit_interceptbool, 默认=True

是否计算此模型的截距。如果设置为 false,则不会在计算中使用截距(即数据应已中心化)。

precompute‘auto’ 或 bool, 默认=’auto’

是否使用预计算的 Gram 和 Xy 矩阵以加速计算。当 n_targetsn_samples 非常大时,可以提高性能。请注意,如果您已经有这样的矩阵,可以直接传递给 fit 方法。

Attributes:
coef_ndarray of shape (n_features,) 或 (n_targets, n_features)

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

intercept_float 或 ndarray of shape (n_targets,)

决策函数中的独立项。

n_iter_int 或 array-like

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

n_nonzero_coefs_int 或 None

解决方案中的非零系数数量,或者当 tol 设置时为 None 。如果 n_nonzero_coefs 为 None 且 tol 为 None,此值要么设置为 n_features 的 10%,要么设置为 1,取两者中的较大值。

n_features_in_int

fit 过程中看到的特征数量。

Added in version 0.24.

feature_names_in_ndarray of shape ( n_features_in_ ,)

fit 过程中看到的特征名称。仅当 X 的所有特征名称均为字符串时定义。

Added in version 1.0.

See also

orthogonal_mp

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

orthogonal_mp_gram

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

lars_path

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

Lars

最小角回归模型,即 LAR。

LassoLars

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

sklearn.decomposition.sparse_encode

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

OrthogonalMatchingPursuitCV

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

Notes

正交匹配追踪由 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. 和 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

Examples

>>> 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)#

拟合模型使用 X, y 作为训练数据。

Parameters:
X形状为 (n_samples, n_features) 的类数组

训练数据。

y形状为 (n_samples,) 或 (n_samples, n_targets) 的类数组

目标值。如有必要,将被转换为 X 的数据类型。

Returns:
self对象

返回 self 的一个实例。

get_metadata_routing()#

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

请查看 用户指南 以了解路由机制的工作原理。

Returns:
routingMetadataRequest

MetadataRequest 封装的 路由信息。

get_params(deep=True)#

获取此估计器的参数。

Parameters:
deepbool, 默认=True

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

Returns:
paramsdict

参数名称映射到它们的值。

predict(X)#

使用线性模型进行预测。

Parameters:
Xarray-like 或 sparse matrix, shape (n_samples, n_features)

样本。

Returns:
Carray, shape (n_samples,)

返回预测值。

score(X, y, sample_weight=None)#

返回预测的决定系数。

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

Parameters:
Xarray-like of shape (n_samples, n_features)

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

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

X 的真实值。

sample_weightarray-like of shape (n_samples,), default=None

样本权重。

Returns:
scorefloat

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

Notes

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

set_params(**params)#

设置此估计器的参数。

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

Parameters:
**paramsdict

估计器参数。

Returns:
selfestimator instance

估计器实例。

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

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config ). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True : metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False : metadata is not requested and the meta-estimator will not pass it to score .

  • None : metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str : metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default ( sklearn.utils.metadata_routing.UNCHANGED ) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline . Otherwise it has no effect.

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

Metadata routing for sample_weight parameter in score .

Returns:
selfobject

The updated object.