sklearn.linear_model.lars_path

sklearn.linear_model.lars_path(X, y, Xy=None, *, Gram=None, max_iter=500, alpha_min=0, method='lar', copy_X=True, eps=2.220446049250313e-16, copy_Gram=True, verbose=0, return_path=True, return_n_iter=False, positive=False)

[源码]

使用LARS算法计算最小角度回归或套索(Lasso)路径[1]

在method=“ lars”的情况下优化目标是:

在method=“ lars”的情况下,仅以隐式方程的形式知道目标函数(请参见[1]中的讨论)

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

参数 说明
X None or array-like of shape (n_samples, n_features)
输入数据。注意,如果X为None,则必须指定Gram矩阵,即不能为None或False。
y None or array-like of shape (n_samples,)
输入目标。
Xy array-like of shape (n_samples,) or (n_samples, n_targets), default=None
Xy = np.dot(XT,y)可以预先计算。仅当预先计算了Gram矩阵时才有用。
Gram None, ‘auto’, array-like of shape (n_features, n_features), default=None
预计算的Gram矩阵(X'* X),如果设为'auto',则从给定的X预计算Gram矩阵,如果样本多于特征。
max_iter int, default=500
要执行的最大迭代次数,设置为无穷大,没有限制。
alpha_min float, default=0
沿路径的最小相关性。它对应于Lasso中的正则化参数alpha参数。
method {‘lar’, ‘lasso’}, default=’lar’
指定返回的模型。'lar'为Least Angle Regression,'lasso'为Lasso。
copy_X bool, default=True
如果False,则覆盖X
eps float, optional
Cholesky对角因子计算中的机器精度正则化。对于条件非常差的系统,可以增加这个值。默认情况下,使用np.finfo(np.float).eps
copy_Gram bool, default=True
如果False,则覆盖Gram
verbose int, default=0
控制输出的详细程度。
return_path bool, default=True
如果return_path==True则返回整个路径,否则仅返回路径的最后一点。
return_n_iter bool, default=False
是否返回迭代次数。
positive bool, default=False
将系数限制为> =0。仅在方法“Lasso”中允许使用这个选项。请注意,对于较小的alpha值,模型系数不会收敛到普通最小二乘解。通常,逐步Lars-Lasso算法所达到的系数只有最小的alpha值(当fit_path = True时,alphas_[alphas_ > 0.].min())才与坐标下降lasso_path函数的解一致。
返回值 说明
alphas array-like of shape (n_alphas + 1,)
每次迭代的最大协方差(绝对值)。 n_alphasmax_itern_features或节点中的路径的数alpha >= alpha_min,较小的那个。
active array-like of shape (n_alphas,)
路径末尾的活动变量的索引。
coefs array-like of shape (n_features, n_alphas + 1)
沿着路径的系数
n_iter int
运行的迭代次数。仅当return_n_iter设置为True时才返回。

另见:

lars_path_gram

lasso_path

lasso_path_gram

LassoLars

Lars

LassoLarsCV

LarsCV

sklearn.decomposition.sparse_encode

参考

1 “Least Angle Regression”, Efron et al. http://statweb.stanford.edu/~tibs/ftp/lars.pdf

2 Wikipedia entry on the Least-angle regression 3 [Wikipedia entry on the Lasso](https://en.wikipedia.org/wiki/Lasso_(statistics)

sklearn.linear_model.lars_path使用示例