Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

LassoCV

LassoCV fits Lasso models over a regularization path and selects the penalty alpha by cross-validation. It uses coordinate descent and exposes the selected model and validation results.

How it works

LassoCV fits Lasso models across a regularization path and uses cross-validation to select the best penalty value. It uses coordinate descent, warm-starting each candidate from the closest previously fitted model to make path computation more efficient.

Syntax

class sklearn.linear_model.LassoCV(*, eps=0.001, alphas=100, fit_intercept=True, precompute='auto', max_iter=1000, tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=None, positive=False, random_state=None, selection='cyclic')

Parameters

NameTypeDescription
epsfloatRatio between the smallest and largest alpha values on the path; default 1e-3.
alphasintNumber of alpha values tested on the path; default 100.
fit_interceptboolWhether to calculate the intercept; default True.
precomputebool or 'auto'Whether to use a precomputed Gram matrix; default 'auto'.
max_iterintMaximum number of coordinate-descent iterations; default 1000.
tolfloatOptimization tolerance; default 1e-4.
copy_XboolWhether to copy the input data; default True.
cvint, cross-validation generator, iterable, or NoneCross-validation splitter configuration; default None, which uses five-fold cross-validation.
verboseboolWhether to print progress; default False.
n_jobsint or NoneNumber of parallel jobs; default None.
positiveboolWhether to constrain coefficients to be positive; default False.
random_stateint, RandomState, or NoneSeed controlling randomized behavior; default None.

Returns

A fitted LassoCV estimator with the selected alpha and fitted coefficients; the page documents attributes including alpha_, coef_, intercept_, mse_path_, and n_iter_.

Key points

  • It fits a sequence of Lasso models along a regularization path.
  • Cross-validation determines which candidate penalty produces the selected model.
  • Its optimization balances squared residual error against an L1 coefficient penalty.
  • eps controls the span of the generated penalty path.
  • cv chooses how training and validation partitions are made.
  • The estimator fits its Lasso models using coordinate descent.

Common mistakes

  • The selected model depends on cross-validation performance rather than a manually fixed penalty.
  • Path fitting reuses coefficients from a nearby penalty, so the estimator is designed to fit the sequence jointly rather than as unrelated models.

Example: Select a Lasso penalty by cross-validation

from sklearn.datasets import make_regression
from sklearn.linear_model import LassoCV

X, y = make_regression(n_samples=80, n_features=10, noise=4, random_state=0)
model = LassoCV(cv=5, random_state=0).fit(X, y)
print(model.alpha_)
print(model.predict(X[:1]))

This creates regression data, fits LassoCV with five-fold cross-validation, and prints the selected penalty and one prediction.

When to use it

Automatic penalty selection

Selecting an L1 regularization strength for ordinary regression.

Sparse feature modeling

Working with many predictors where sparse coefficients are useful.

Cross-validated model selection

Comparing candidate penalties using repeated training and validation partitions.

Interview questions

QWhat does LassoCV select?

LassoCV evaluates Lasso models over a regularization path and chooses the alpha with the best cross-validation result. Its objective combines squared prediction error with an L1 penalty on coefficients.

Follow-up: How does it differ from LassoLarsCV? LassoCV uses coordinate descent, whereas LassoLarsCV uses the LARS algorithm.

QHow does cv affect fitting?

The cv parameter controls the cross-validation splitting strategy. With None, the default five-fold strategy is used; an integer specifies the number of folds, while a splitter or iterable can provide explicit splits.

Follow-up: Why might explicit splits matter? They let the evaluation respect a domain-specific grouping or ordering scheme instead of ordinary folds.

QWhat do eps and alphas control?

eps controls the length of the automatically generated alpha path as the ratio of the smallest to largest alpha. The default is 1e-3, and alphas controls how many alpha values are considered, defaulting to 100 in the documented signature.

Follow-up: What is the trade-off in increasing the number of alphas? It explores the path more finely but increases computation.

  • Lasso
  • LassoLarsCV
  • ElasticNetCV
  • MultiTaskLassoCV

Source: LassoCV — scikit-learn 1.9.1 documentation. Checked 2026-10-15.