Compute Least Angle Regression or Lasso path using the LARS algorithm.
The optimization objective for the case method=’lasso’ is:
(1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1
in the case of method=’lar’, the objective function is only known in the form of an implicit equation (see discussion in [1]).
Read more in the User Guide.
Input data. If X is None, Gram must also be None. If only the Gram matrix is available, use lars_path_gram instead.
Input targets.
Xy = X.T @ y that can be precomputed. It is useful only when the Gram matrix is precomputed.
Precomputed Gram matrix X.T @ X, if 'auto', the Gram matrix is precomputed from the given X, if there are more samples than features.
Maximum number of iterations to perform, set to infinity for no limit.
Minimum correlation along the path. It corresponds to the regularization parameter alpha in the Lasso.
Specifies the returned model. Select 'lar' for Least Angle Regression, 'lasso' for the Lasso.
If False, X is overwritten.
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.
If False, Gram is overwritten.
Controls output verbosity.
If True, returns the entire path, else returns only the last point of the path.
Whether to return the number of iterations.
Restrict coefficients to be >= 0. This option is only allowed with method ‘lasso’. Note that the model coefficients will not converge to the ordinary-least-squares solution for small values of alpha. Only coefficients up to the smallest alpha value (alphas_[alphas_ > 0.].min() when fit_path=True) reached by the stepwise Lars-Lasso algorithm are typically in congruence with the solution of the coordinate descent lasso_path function.
Maximum of covariances (in absolute value) at each iteration. n_alphas is either max_iter, n_features, or the number of nodes in the path with alpha >= alpha_min, whichever is smaller.
Indices of active variables at the end of the path.
Coefficients along the path.
Number of iterations run. Returned only if return_n_iter is set to True.
See also
lars_path_gramCompute LARS path in the sufficient stats mode.
lasso_pathCompute Lasso path with coordinate descent.
LassoLarsLasso model fit with Least Angle Regression a.k.a. Lars.
LarsLeast Angle Regression model a.k.a. LAR.
LassoLarsCVCross-validated Lasso, using the LARS algorithm.
LarsCVCross-validated Least Angle Regression model.
sklearn.decomposition.sparse_encodeSparse coding.
“Least Angle Regression”, Efron et al. http://statweb.stanford.edu/~tibs/ftp/lars.pdf
>>> from sklearn.linear_model import lars_path
>>> 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(X, y)
>>> alphas.shape
(3,)
>>> estimated_coef
array([[ 0. , 0. , 0. ],
[ 0. , 0. , 0. ],
[ 0. , 0. , 0. ],
[ 0. , 46.96..., 97.99...],
[ 0. , 0. , 45.70...]])
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.linear_model.lars_path.html