sklearn.linear_model.Lars

class sklearn.linear_model.Lars(*, fit_intercept=True, verbose=False, normalize=True, precompute='auto', n_nonzero_coefs=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, jitter=None, random_state=None)

[源码]

最小角度回归模型,又称LAR。

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

参数 说明
fit_intercept bool, default=True
是否计算此模型的截距。如果设置为False,则在计算中将不使用截距(即,数据应居中)。
verbose bool or int, default=False
详细程度
normalize bool, default=True
fit_intercept设置为False 时,将忽略此参数。如果为True,则在回归之前通过减去均值并除以l2-范数来对回归变量X进行归一化。如果你希望标准化,请先使用 sklearn.preprocessing.StandardScaler,然后调用fit 估算器并设置normalize=False
precompute bool, ‘auto’ or array-like , default=’auto’
是否使用预先计算的Gram矩阵来加快计算速度。Gram矩阵也可以作为参数传递。
n_nonzero_coefs int, default=500
非零系数的目标数量。使用np.inf时无限制。
eps float, optional
Cholesky对角因子计算中的机器精度正则化。对于病态系统,请增加此值。与某些基于迭代优化的算法中的tol参数不同,此参数不控制优化的容忍度。默认情况下,使用np.finfo(np.float).eps
copy_X bool, default=True
如果True,将复制X;否则X可能会被覆盖。
fit_path bool, default=True
如果为True,则完整路径将存储在coef_path_属性中。如果针对一个大问题或多个目标计算解决方案,设置fit_pathFalse会导致加速,尤其是对于较小的alpha。
jitter float, default=None
要添加到y值的均匀噪声参数的上限 ,以满足模型一次计算的假设。可能会对稳定性有所帮助。
random_state int, RandomState instance or None (default)
确定噪声的随机数生成模式。为多个函数调用传递一个整数来实现重复输出。请参阅词汇表。如果jitter为None则忽略此参数。
属性 说明
alphas_ array-like of shape (n_alphas + 1,)|list of n_targets such arrays
每次迭代的最大协方差(绝对值)。 n_alphasn_nonzero_coefsn_features,以较小者为准。
active_ list, length = n_alphas|list of n_targets such lists
路径末尾的活动变量的索引。
coef_path_ array-like of shape (n_features, n_alphas + 1)|list of n_targets such arrays
沿路径的系数的变化值。如果fit_path参数为False,则此参数不可用。
coef_ array-like of shape (n_features,) or (n_targets, n_features)
参数向量(目标公式中的w)。
intercept_ float or array-like of shape (n_targets,)
目标函数中的截距。
n_iter_ array-like or int
lars_path为每个目标查找alpha网格所花费的迭代次数。

另见

示例

>>> from sklearn import linear_model
>>> reg = linear_model.Lars(n_nonzero_coefs=1)
>>> reg.fit([[-11], [00], [11]], [-1.11110-1.1111])
Lars(n_nonzero_coefs=1)
>>> print(reg.coef_)
0. -1.11...]

方法

方法 说明
fit(X, y[, Xy]) 使用X,y作为训练数据拟合模型。
get_params([deep]) 获取此估计器的参数。
predict(X) 使用线性模型进行预测。
score(X, y[, sample_weight]) 返回预测的确定系数R ^ 2。
set_params(**params) 设置此估算器的参数。
__init__(*, fit_intercept=True, verbose=False, normalize=True, precompute='auto', n_nonzero_coefs=500, eps=2.220446049250313e-16, copy_X=True, fit_path=True, jitter=None, random_state=None)

[源码]

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

fit(X, y, Xy=None)

[源码]

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

参数 说明
X array-like of shape (n_samples, n_features)
训练数据。
y array-like of shape (n_samples,) or (n_samples, n_targets)
目标值。
Xy array-like of shape (n_samples,) or (n_samples, n_targets), default=None
Xy = np.dot(XT,y)可以预先计算。仅当预先计算了Gram矩阵时才有用。
返回值 说明
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
估计器实例。