OrthogonalMatchingPursuit#
- class sklearn.linear_model.OrthogonalMatchingPursuit(*, n_nonzero_coefs=None, tol=None, fit_intercept=True, precompute='auto')[源代码]#
垂直匹配追求模型(OMP)。
阅读更多的 User Guide .
- 参数:
- n_nonzero_coefsint,默认=无
解决方案中所需的非零条目数量。如果被忽视
tol
已设置。当None
和tol
也是None
,此值可以设置为n_features
或1,以较大者为准。- tolfloat,默认=无
剩余的最大平方规范。如果不是无,则重写n_非零_coefs。
- fit_intercept布尔,默认=True
是否计算此模型的拦截。如果设置为假,则计算中不会使用任何拦截(即数据预计居中)。
- precompute“Auto”或布尔,默认=“Auto”
是否使用预先计算的Gram和Xy矩阵来加速计算。提高性能时 n_targets 或 n_samples 非常大。请注意,如果您已经拥有此类矩阵,则可以将它们直接传递给fit方法。
- 属性:
- coef_形状的nd数组(n_features,)或(n_targets,n_features)
参数vector(公式中的w)。
- intercept_形状的float或ndray(n_targets,)
Independent term in decision function.
- n_iter_int或类数组
每个目标上的活动功能数量。
- n_nonzero_coefs_int或无
解决方案中非零系数的数量或
None
当tol
已设置。如果n_nonzero_coefs
没有,tol
是无此值设置为10%n_features
或1,以较大者为准。- n_features_in_int
期间看到的功能数量 fit .
Added in version 0.24.
- feature_names_in_ :nd形状数组 (
n_features_in_
,)nd数组形状( Names of features seen during fit. Defined only when
X
has feature names that are all strings.Added in version 1.0.
参见
orthogonal_mp
解决n_targets的垂直匹配追踪问题。
orthogonal_mp_gram
仅使用Gram矩阵X.T来解决n_targets的Orthogonal Matching Pursuit问题 * X and the product X.T * y.
lars_path
使用LARS算法计算最小角度回归或Lasso路径。
Lars
最小角度回归模型,又名拉尔。
LassoLars
Lasso模型与最小角度回归(又名最小角度回归)进行匹配拉斯。
sklearn.decomposition.sparse_encode
通用稀疏编码。结果的每一列都是Lasso问题的解决方案。
OrthogonalMatchingPursuitCV
交叉验证的垂直匹配追求模型(OMP)。
注意到
在G.马拉特,Z.张文,基于时频字典的匹配追踪,IEEE信号处理学报,第41卷,第12期。(1993年12月),pp. 3397-3415.(https://www.di.ens.fr/Mallat/papiers/MallatPursuit93.pdf)
该实现基于Rubinstein,R.,齐布列夫斯基,M. Elad,M.,使用批量垂直匹配追踪技术报告有效实现K-DID算法- CS Technion,2008年4月。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)[源代码]#
使用X,y作为训练数据来匹配模型。
- 参数:
- X形状类似阵列(n_samples,n_features)
训练数据。
- y形状类似阵列(n_samples,)或(n_samples,n_targets)
目标值。如有必要,将被转换为X的d类型。
- 返回:
- self对象
返回自我的实例。
- get_metadata_routing()[源代码]#
获取此对象的元数据路由。
请检查 User Guide 关于路由机制如何工作。
- 返回:
- routingMetadataRequest
A
MetadataRequest
封装路由信息。
- get_params(deep=True)[源代码]#
获取此估计器的参数。
- 参数:
- deep布尔,默认=True
如果为True,将返回此估计量和包含的作为估计量的子对象的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- predict(X)[源代码]#
Predict using the linear model.
- 参数:
- X类阵列或稀疏矩阵,形状(n_samples,n_features)
样品
- 返回:
- C数组,形状(n_samples,)
返回预测值。
- score(X, y, sample_weight=None)[源代码]#
返回预测的决定系数。
决定系数 \(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。- 参数:
- X形状类似阵列(n_samples,n_features)
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted)
, wheren_samples_fitted
is the number of samples used in the fitting for the estimator.- y形状的类似阵列(n_samples,)或(n_samples,n_outputs)
真正的价值观
X
.- sample_weight形状类似数组(n_samples,),默认=无
样本重量。
- 返回:
- score浮子
\(R^2\) 的
self.predict(X)
w.r.t.y
.
注意到
的 \(R^2\) 呼叫时使用的分数
score
在回归器上使用multioutput='uniform_average'
从0.23版本开始,与默认值保持一致r2_score
.这影响了score
所有多输出回归器的方法(除了MultiOutputRegressor
).
- set_params(**params)[源代码]#
设置此估计器的参数。
该方法适用于简单估计器以及嵌套对象(例如
Pipeline
).后者具有以下形式的参数<component>__<parameter>
以便可以更新嵌套对象的每个组件。- 参数:
- **paramsdict
估计参数。
- 返回:
- self估计器实例
估计实例。
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') OrthogonalMatchingPursuit [源代码]#
请求元数据传递给
score
法请注意,此方法仅适用于以下情况
enable_metadata_routing=True
(见sklearn.set_config
).请参阅 User Guide 关于路由机制如何工作。The options for each parameter are:
True
:元数据被请求并传递给score
如果提供的话。如果未提供元数据,则会忽略请求。False
:未请求元数据,元估计器不会将其传递给score
.None
:不请求元数据,如果用户提供元估计器,则元估计器将引发错误。str
:元数据应通过此给定别名而不是原始名称传递给元估计器。
默认 (
sklearn.utils.metadata_routing.UNCHANGED
)保留现有请求。这允许您更改某些参数的请求,而不是其他参数。Added in version 1.3.
备注
只有当该估计器用作元估计器的子估计器时,该方法才相关,例如在
Pipeline
.否则就没有效果了。- 参数:
- sample_weight字符串、真、假或无, 默认=sklearn.utils. metalics_Routing.UNChanged
元数据路由
sample_weight
参数score
.
- 返回:
- self对象
更新的对象。