Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `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)

  Compute Least Angle Regression or Lasso path using the LARS algorithm [1].

  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.

  Parameters:
    X None or array-like of shape (n_samples, n_features)

      Input data. Note that if X is `None` then the Gram matrix must be specified, i.e., cannot be `None` or `False`.

    y None or array-like of shape (n_samples,)

      Input targets.

    Xy array-like of shape (n_features,) or (n_features, n_targets), default=None

      `Xy = np.dot(X.T, y)` that can be precomputed. It is useful only when the Gram matrix is precomputed.

    Gram None, ‘auto’, array-like of shape (n_features, n_features), default=None

      Precomputed Gram matrix (X’ * X), if `'auto'`, the Gram matrix is precomputed from the given X, if there are more samples than features.

    max_iter int, default=500

      Maximum number of iterations to perform, set to infinity for no limit.

    alpha_min float, default=0

      Minimum correlation along the path. It corresponds to the regularization parameter `alpha` in the Lasso.

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

      Specifies the returned model. Select `'lar'` for Least Angle Regression, `'lasso'` for the Lasso.

    copy_X bool, default=True

      If `False`, `X` is overwritten.

    eps float, 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_Gram bool, default=True

      If `False`, `Gram` is overwritten.

    verbose int, default=0

      Controls output verbosity.

    return_path bool, default=True

      If `True`, returns the entire path, else returns only the last point of the path.

    return_n_iter bool, default=False

      Whether to return the number of iterations.

    positive bool, default=False

      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.

  Returns:
    alphas array-like of shape (n_alphas + 1,)

      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.

    active array-like of shape (n_alphas,)

      Indices of active variables at the end of the path.

    coefs array-like of shape (n_features, n_alphas + 1)

      Coefficients along the path.

    n_iter int

      Number of iterations run. Returned only if return_n_iter is set to True.

  See also

  `lars_path_gram`

    Compute LARS path in the sufficient stats mode.

  `lasso_path`

    Compute Lasso path with coordinate descent.

  `LassoLars`

    Lasso model fit with Least Angle Regression a.k.a. Lars.

  `Lars`

    Least Angle Regression model a.k.a. LAR.

  `LassoLarsCV`

    Cross-validated Lasso, using the LARS algorithm.

  `LarsCV`

    Cross-validated Least Angle Regression model.

  `sklearn.decomposition.sparse_encode`

    Sparse coding.

  References

  [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

## Examples using `sklearn.linear_model.lars_path`

Lasso path using LARS

Lasso path using LARS