sklearn.linear_model.OrthogonalMatchingPursuit

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

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

用户指南中阅读更多内容。

参数 说明
n_nonzero_coefs int, optional
解决方案中所需的非零项数。如果为None(默认),则此值设置为n_features的10%。
tol float, optional
残数的最大范数。如果不是None,则覆盖n_nonzero_coefs。
fit_intercept boolean, optional
是否计算该模型的截距。如果设置为false,则在计算中将不使用截距(即,数据应是中心化的)。
normalize boolean, optional, default True
fit_intercept设置为False 时,将忽略此参数。如果为True,则在回归之前通过减去均值并除以l2-范数来对回归变量X进行归一化。如果你希望标准化,请先使用 sklearn.preprocessing.StandardScaler,然后调用fit 估算器并设置normalize=False
precompute {True, False, ‘auto’}, default ‘auto’
是否使用预先计算的Gram和Xy矩阵来加快计算速度。当n_targetsn_samples非常大时提高性能。请注意,如果已经有这样的矩阵,则可以将它们直接传递给fit方法。
属性 说明
coef_ array, shape (n_features,) or (n_targets, n_features)
参数向量(公式中的w)
intercept_ float or array, shape (n_targets,)
目标函数中的截距。
n_iter_ int or array-like
每个目标上的活动特征数量。

另见

正交匹配追踪是在G. Mallat,Z. Zhang中引入的,《时频字典的匹配追踪》,IEEE Transactions on Signal Processing,Vol。41,No.12(1993年12月),第3397-3415页。(http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)

此实现基于R.Rubinstein,M.Zibulevsky和M.Elad的《使用批正交匹配追踪技术报告有效实现K-SVD算法》,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[, copy_X]) 使用X,y作为训练数据拟合模型。
get_params([deep]) 获取此估计量的参数。
predict(X) 使用线性模型进行预测。
score(X, y[, sample_weight]) 返回预测的确定系数R ^ 2。
set_params(**params) 设置此估算器的参数。
__init__(standard ='aic',*,fit_intercept = True,verbose = False,normalize = True,precompute ='auto',max_iter = 500,eps = 2.220446049250313e-16,copy_X = True,positive = False )

[源码]

初始化self, 请参阅help(type(self))以获得准确的说明。

fit(X, y, copy_X=None)

[源码]

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

参数 说明
X array-like of shape (n_samples, n_features) 训练数据。
y array-like of shape (n_samples,) 目标值。如有必要,将强制转换为X的数据类型
copy_X bool, default=None 如果设置了此参数,它将覆盖实例创建时选择的copy_X。如果True,X将被复制;否则X可能会被覆盖。
返回值 说明
self object 返回估计器实例
get_params(deep=True)

[源码]

获取此估计量的参数。

参数 说明
deep bool, default=True 如果为True,则将返回此估算器和所包含子对象的参数。
返回值 说明
params mapping of string to any 参数名称映射到其值。
predict(X)

[源码]

使用线性模型进行预测。

参数 说明
X array_like or sparse matrix, shape (n_samples, n_features) 样本数据
返回值 说明
C array, shape (n_samples,) 返回预测值。
score(X, y, sample_weight=None)

[源码]

返回预测的确定系数R ^ 2。

系数R ^ 2定义为(1- 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 array-like of shape (n_samples, n_features) 测试样本。对于某些估计量,这可以是预先计算的内核矩阵或通用对象列表,形状为(n_samples,n_samples_fitted),其中n_samples_fitted是用于拟合估计器的样本数。
y array-like of shape (n_samples,) or (n_samples, n_outputs) X的真实值。
sample_weight array-like of shape (n_samples,), default=None 样本权重。
返回值 说明
score float 预测值与真实值的R^2。

调用回归器中的score时使用的R2分数,multioutput='uniform_average'从0.23版开始使用 ,与r2_score默认值保持一致。这会影响多输出回归的score方法( MultiOutputRegressor除外)。

set_params(**params)

[源码]

设置此估计器的参数。

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

参数 说明
**params dict 估计器参数。
返回值 说明
self object 估计器实例。

sklearn.linear_model.OrthogonalMatchingPursuit使用示例