lars_path_gram#

sklearn.linear_model.lars_path_gram(Xy, Gram, *, n_samples, max_iter=500, alpha_min=0, method='lar', copy_X=True, eps=np.float64(2.220446049250313e-16), copy_Gram=True, verbose=0, return_path=True, return_n_iter=False, positive=False)[source]#

足够统计模式下的 lars_path。

当 method=’lasso’ 时,优化的目标函数为

(1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1

当 method=’lar’ 时,目标函数仅以隐式方程的形式已知(参见 [1] 中的讨论)。

Read more in the User Guide.

参数:
Xy形状为 (n_features,) 的 ndarray

Xy = X.T @ y.

Gram形状为 (n_features, n_features) 的 ndarray

Gram = X.T @ X.

n_samplesint

等效的样本大小。

max_iterint, default=500

要执行的最大迭代次数,设置为无穷大表示没有限制。

alpha_minfloat, default=0

沿路径的最小相关性。它对应于 Lasso 中的正则化参数 alpha。

method{‘lar’, ‘lasso’}, default=’lar’

指定返回的模型。选择 'lar' 表示最小角回归 (Least Angle Regression),选择 'lasso' 表示 Lasso。

copy_Xbool, default=True

如果为 False,则 X 将被覆盖。

epsfloat, default=np.finfo(float).eps

The machine-precision regularization in the computation of the Cholesky diagonal factors. Increase this for very ill-conditioned systems. Unlike the tol parameter in some iterative optimization-based algorithms, this parameter does not control the tolerance of the optimization.

copy_Grambool, default=True

如果为 False,则 Gram 将被覆盖。

verboseint, default=0

控制输出的详细程度。

return_pathbool, default=True

如果 return_path==True,则返回整个路径;否则,仅返回路径的最后一个点。

return_n_iterbool, default=False

是否返回迭代次数。

positivebool, default=False

限制系数 >= 0。此选项仅在 method ‘lasso’ 时允许。请注意,对于较小的 alpha 值,模型系数不会收敛到普通最小二乘解。只有当 alpha 值达到逐步 Lars-Lasso 算法达到的最小 alpha 值(当 fit_path=True 时为 alphas_[alphas_ > 0.].min())时,系数才通常与坐标下降 lasso_path 函数的解一致。

返回:
alphas形状为 (n_alphas + 1,) 的 ndarray

每次迭代中协方差的最大值(绝对值)。n_alphasmax_itern_features 或路径中 alpha >= alpha_min 的节点数中较小的一个。

active形状为 (n_alphas,) 的 ndarray

路径结束时活动变量的索引。

coefs形状为 (n_features, n_alphas + 1) 的 ndarray

路径上的系数。

n_iter整型

运行的迭代次数。仅当 return_n_iter 设置为 True 时返回。

另请参阅

lars_path_gram

计算 LARS 路径。

lasso_path

使用坐标下降计算 Lasso 路径。

LassoLars

使用最小角回归(又名 Lars)拟合的 Lasso 模型。

Lars

最小角回归模型,又名 LAR。

LassoLarsCV

使用 LARS 算法的交叉验证 Lasso。

LarsCV

交叉验证的最小角回归模型。

sklearn.decomposition.sparse_encode

稀疏编码。

References

[1]

“最小角回归”(Least Angle Regression),Efron et al. http://statweb.stanford.edu/~tibs/ftp/lars.pdf

示例

>>> from sklearn.linear_model import lars_path_gram
>>> from sklearn.datasets import make_regression
>>> X, y, true_coef = make_regression(
...    n_samples=100, n_features=5, n_informative=2, coef=True, random_state=0
... )
>>> true_coef
array([ 0.        ,  0.        ,  0.        , 97.9, 45.7])
>>> alphas, _, estimated_coef = lars_path_gram(X.T @ y, X.T @ X, n_samples=100)
>>> alphas.shape
(3,)
>>> estimated_coef
array([[ 0.     ,  0.     ,  0.     ],
       [ 0.     ,  0.     ,  0.     ],
       [ 0.     ,  0.     ,  0.     ],
       [ 0.     , 46.96, 97.99],
       [ 0.     ,  0.     , 45.70]])