Implementation:Scikit learn Scikit learn Lars
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Feature Selection |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for Least Angle Regression (LAR) providing an efficient path-following algorithm for sparse linear models provided by scikit-learn.
Description
Lars (Least Angle Regression) implements the LARS algorithm, which produces a full piecewise linear solution path for linear regression. At each step, LARS finds the feature most correlated with the current residual and increases the corresponding coefficient in the direction of the correlation until another feature has as much correlation with the residual. The module also provides the lars_path function for computing the full LARS or Lasso regularization path, and LarsCV for cross-validated model selection along the regularization path.
Usage
Use Lars when you need an efficient algorithm for computing the full regularization path, when the number of features is much larger than the number of samples, or when you want to understand the order in which features enter the model. It is computationally efficient for problems with many features since it computes the exact solution path in the same cost as a single OLS fit.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/linear_model/_least_angle.py
Signature
class Lars(MultiOutputMixin, RegressorMixin, LinearModel):
def __init__(
self,
*,
fit_intercept=True,
verbose=False,
precompute="auto",
n_nonzero_coefs=500,
eps=np.finfo(float).eps,
copy_X=True,
fit_path=True,
jitter=None,
random_state=None,
):
def lars_path(X, y, Xy=None, *, Gram=None, max_iter=500,
alpha_min=0, method="lar", copy_X=True,
eps=np.finfo(float).eps, copy_Gram=True,
verbose=0, return_path=True, return_n_iter=False,
positive=False):
Import
from sklearn.linear_model import Lars, lars_path, LarsCV
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| fit_intercept | bool | No | Whether to calculate the intercept (default=True) |
| verbose | bool or int | No | Verbosity level (default=False) |
| precompute | bool, 'auto', or array-like | No | Whether to use a precomputed Gram matrix (default='auto') |
| n_nonzero_coefs | int | No | Target number of non-zero coefficients (default=500) |
| eps | float | No | Machine-precision regularization in Cholesky diagonal factors |
| copy_X | bool | No | Whether to copy X (default=True) |
| fit_path | bool | No | Whether to store the full path in coef_path_ (default=True) |
| jitter | float | No | Upper bound on uniform noise added to y for stability (default=None) |
| random_state | int or RandomState | No | Random seed for reproducibility when jittering |
Outputs
| Name | Type | Description |
|---|---|---|
| coef_ | ndarray of shape (n_features,) | Estimated coefficients |
| intercept_ | float | Independent term in the linear model |
| coef_path_ | ndarray of shape (n_features, n_alphas) | Full coefficient path (if fit_path=True) |
| alphas_ | ndarray of shape (n_alphas,) | Maximum of covariances at each iteration |
| active_ | list | Indices of active variables at the end of the path |
| n_iter_ | int | Number of iterations run |
Usage Examples
Basic Usage
from sklearn.linear_model import Lars
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=100, n_features=20, noise=5, random_state=42)
model = Lars(n_nonzero_coefs=10)
model.fit(X, y)
print("Active features:", model.active_)
print("Number of iterations:", model.n_iter_)