Automatic penalty selection
Selecting an L1 regularization strength for ordinary regression.
Scikit-Learn · Class
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.
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.
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')| Name | Type | Description |
|---|---|---|
eps | float | Ratio between the smallest and largest alpha values on the path; default 1e-3. |
alphas | int | Number of alpha values tested on the path; default 100. |
fit_intercept | bool | Whether to calculate the intercept; default True. |
precompute | bool or 'auto' | Whether to use a precomputed Gram matrix; default 'auto'. |
max_iter | int | Maximum number of coordinate-descent iterations; default 1000. |
tol | float | Optimization tolerance; default 1e-4. |
copy_X | bool | Whether to copy the input data; default True. |
cv | int, cross-validation generator, iterable, or None | Cross-validation splitter configuration; default None, which uses five-fold cross-validation. |
verbose | bool | Whether to print progress; default False. |
n_jobs | int or None | Number of parallel jobs; default None. |
positive | bool | Whether to constrain coefficients to be positive; default False. |
random_state | int, RandomState, or None | Seed controlling randomized behavior; default None. |
A fitted LassoCV estimator with the selected alpha and fitted coefficients; the page documents attributes including alpha_, coef_, intercept_, mse_path_, and n_iter_.
eps controls the span of the generated penalty path.cv chooses how training and validation partitions are made.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.
Selecting an L1 regularization strength for ordinary regression.
Working with many predictors where sparse coefficients are useful.
Comparing candidate penalties using repeated training and validation partitions.
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.
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.
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.
LassoLassoLarsCVElasticNetCVMultiTaskLassoCV