OrthogonalMatchingPursuitCV#
- class sklearn.linear_model.OrthogonalMatchingPursuitCV(*, copy=True, fit_intercept=True, max_iter=None, cv=None, n_jobs=None, verbose=False)[source]#
交叉验证的正交匹配追踪模型 (OMP)。
参见词汇表条目 交叉验证估计器。
在用户指南中了解更多信息。
- 参数:
- copy布尔值, 默认为 True
设计矩阵 X 是否必须由算法复制。只有当 X 已经是 Fortran 顺序时,false 值才有用,否则无论如何都会进行复制。
- 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).
- max_iterint, default=None
要执行的最大迭代次数,因此要包含的最大特征数。如果是
n_features的 10%,则至少为 5(如果可用)。- cvint, cross-validation generator or iterable, default=None
确定交叉验证拆分策略。cv 的可能输入包括
None,使用默认的 5 折交叉验证,
整数,指定折数。
一个可迭代对象,产生索引数组形式的 (训练集, 测试集) 拆分。
For integer/None inputs,
KFoldis used.有关此处可使用的各种交叉验证策略,请参阅 用户指南。
版本 0.22 中已更改:如果为 None,
cv默认值从 3 折更改为 5 折。- n_jobsint, default=None
Number of CPUs to use during the cross validation.
Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means using all processors. See Glossary for more details.- verbosebool or int, default=False
Sets the verbosity amount.
- 属性:
- intercept_float or ndarray of shape (n_targets,)
决策函数中的独立项。
- coef_ndarray of shape (n_features,) or (n_targets, n_features)
参数向量(问题公式中的 w)。
- n_nonzero_coefs_int
在交叉验证折叠中给出最佳均方误差的非零系数的估计数量。
- n_iter_int or array-like
通过在所有折叠上进行交叉验证获得的最佳超参数重新拟合模型时,每个目标的活跃特征数量。
- 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_pathCompute Least Angle Regression or Lasso path using LARS algorithm.
Lars最小角回归模型,又名 LAR。
LassoLars使用最小角回归(又名 Lars)拟合的 Lasso 模型。
OrthogonalMatchingPursuit正交匹配追踪模型 (OMP)。
LarsCV交叉验证的最小角回归模型。
LassoLarsCV使用最小角回归拟合的交叉验证 Lasso 模型。
sklearn.decomposition.sparse_encode通用稀疏编码。结果的每一列都是 Lasso 问题的解。
注意事项
在
fit中,一旦通过交叉验证找到了非零系数的最佳数量,就会使用整个训练集再次拟合模型。示例
>>> from sklearn.linear_model import OrthogonalMatchingPursuitCV >>> from sklearn.datasets import make_regression >>> X, y = make_regression(n_features=100, n_informative=10, ... noise=4, random_state=0) >>> reg = OrthogonalMatchingPursuitCV(cv=5).fit(X, y) >>> reg.score(X, y) 0.9991 >>> reg.n_nonzero_coefs_ np.int64(10) >>> reg.predict(X[:1,]) array([-78.3854])
- fit(X, y, **fit_params)[source]#
Fit the model using X, y as training data.
- 参数:
- Xshape 为 (n_samples, n_features) 的 array-like
训练数据。
- yarray-like of shape (n_samples,)
目标值。如有必要,将被转换为 X 的 dtype。
- **fit_paramsdict
要传递给底层拆分器的参数。
Added in version 1.4: Only available if
enable_metadata_routing=True, which can be set by usingsklearn.set_config(enable_metadata_routing=True). See Metadata Routing User Guide for more details.
- 返回:
- selfobject
Returns an instance of self.
- get_metadata_routing()[source]#
获取此对象的元数据路由。
请查阅 用户指南,了解路由机制如何工作。
1.4 版本新增。
- 返回:
- routingMetadataRouter
封装路由信息的
MetadataRouter。
- 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\)。
注意事项
在调用回归器的
score时使用的 \(R^2\) 分数从 0.23 版本开始使用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$') OrthogonalMatchingPursuitCV[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
更新后的对象。