Ridge regression stabilizes a fitted model by shrinking all slopes continuously toward zero. Lasso asks a different question: can regularization also produce a shorter fitted rule by setting some slopes exactly to zero? We begin with a one-variable calculation, use it to build a multivariable algorithm, and then examine what a sparse fit means when predictors are correlated.
Learning goals
By the end of this lecture, you should be able to:
write the lasso objective using centered and standardized data;
derive the one-variable soft-thresholding rule and explain why it can return exactly zero;
explain how signal strength and the penalty affect selection across repeated samples;
explain how coordinate descent and warm starts produce a lasso solution path;
interpret a cross-validation curve without using the test set to choose the penalty; and
compare the behavior of ridge, lasso, and elastic net when predictors are correlated.
How lasso creates sparsity
We begin with the limitation of ridge regression, define the lasso objective, and then use the one-variable problem to explain exact zeros and repeated selection.
Why ridge does not produce a sparse model
Ridge regression stabilizes a linear model by shrinking its slopes toward zero. It usually does not make them exactly zero. If a dataset has hundreds of predictors, a ridge fit will therefore usually contain hundreds of nonzero slopes, even when many of them are very small.
Sometimes we want a sparse model that uses only part of the available predictor set. The lasso replaces ridge’s squared-coefficient penalty with a sum of absolute values. This small change has an important consequence: for a range of penalty values, some fitted slopes are exactly zero.
Lasso still has the bias-variance trade-off from Week 3. Shrinkage introduces bias, but it can reduce sampling variation and improve prediction. The new feature is sparsity. Because prediction and recovery of the true variable set are different goals, we will use cross-validation to choose a predictive rule and interpret its nonzero coefficients cautiously.
Guiding question. What feature of the lasso penalty makes exact zeros possible, and what do those zeros mean when predictors are correlated?
We first answer this in a one-predictor problem. We then use the same calculation to understand selection across repeated samples, coordinate descent, a complete lasso path, and correlated predictors.
Define the lasso objective
Continue the ridge notation from Week 3. The matrix again contains centered, standardized covariate columns, is the centered response, and the intercept is fitted separately. Ridge and lasso use the same data transformation. Only the penalty changes.
Let contain the covariates on their original scales, and let contain the responses. Here is the number of slope covariates and is the total number of fitted coefficients after including the unpenalized intercept. As with ridge regression, the penalty should not depend on whether a variable is recorded in meters or millimeters. We therefore center and standardize each covariate using the current training data. Let denote the resulting matrix, and let
be the centered response. Throughout this lecture, the lasso estimate is
where
The optimization variable contains the slopes on the standardized predictor scale. The squared-error term measures lack of fit. The penalty has the same value for positive and negative slopes of equal magnitude. The tuning parameter determines how strongly we prefer smaller slopes.
When , the objective reduces to least squares.
As increases, the slopes are pulled more strongly toward zero.
The intercept is not penalized. After fitting the centered problem, it is recovered from the training means.
ImportantScaling is part of the fitted method
The centers and scales must be computed from the observations used to fit a model. During cross-validation, each validation fold is transformed using the centers and scales from the other folds. Computing them once from the full dataset would allow validation information to enter the fit.
The one-variable problem
The difference between ridge and lasso is easiest to see with one centered and standardized covariate , so that
Define
In a one-predictor least-squares fit, is the fitted slope. Expanding the squared-error term gives
Therefore, after removing terms that do not depend on , the lasso objective becomes
The absolute-value term has a corner at zero, so we consider the two smooth sides separately.
If , then , and
Setting this derivative to zero gives . This answer lies on the positive side only when .
If , then , and
The stationary point is now , and it lies on the negative side only when .
What happens when ? Immediately to the left of zero, the derivative is . Immediately to the right, it is . The objective decreases as it approaches zero from the left and increases after it passes zero. Its minimum is therefore exactly at zero.
Combining the three cases gives the soft-thresholding operator
Here denotes the positive part of .
The fitted coefficient is not rounded to zero after optimization. Zero is the exact minimizer whenever the least-squares slope is no larger than the threshold in absolute value.
Compare ridge and lasso in one variable. Ridge gives , so a nonzero least-squares slope approaches zero smoothly. Lasso subtracts from the slope’s absolute size and stops at zero. The corner of the absolute-value penalty creates this threshold.
WarningThe numerical value of the penalty depends on the objective
The threshold is because the squared-error term is divided by . If a book or software package uses a different constant, the same fitted model may be labeled by a different numerical penalty. Compare the full objectives before comparing values of .
Watch the minimizer move
The next figure fixes the least-squares slope at . Increasing moves the minimizer toward zero. Once , zero becomes the exact minimizer.
The one-variable lasso objective for three penalty values. The marked minimizer reaches zero once the penalty exceeds the absolute least-squares slope.
Show the reproducible code
import numpy as npimport matplotlib.pyplot as plt# The corner in the absolute-value penalty moves the exact minimizer to zero.a =1beta_grid = np.linspace(-0.5, 1.6, 500)lambda_values = [0, 0.6, 1.2]curve_colors = ["#2F6FB3", "#C84A16", "#13294B"]fig, ax = plt.subplots(figsize=(7, 4.5))for lam, color inzip(lambda_values, curve_colors): objective =0.5* (beta_grid - a) **2+ lam * np.abs(beta_grid) beta_hat = np.sign(a) *max(abs(a) - lam, 0) ax.plot( beta_grid, objective, color=color, linewidth=2, label=f"lambda = {lam}", ) ax.scatter( beta_hat,0.5* (beta_hat - a) **2+ lam *abs(beta_hat), color=color, s=35, )ax.set(xlabel=r"$\beta$", ylabel="Objective value", ylim=(0, 2.4))ax.legend(frameon=False)ax.spines[["top", "right"]].set_visible(False)fig.tight_layout()plt.show()
The one-variable lasso objective for three penalty values. The marked minimizer reaches zero once the penalty exceeds the absolute least-squares slope.
The curves do not show a numerical rounding rule. They show a change in the location of the mathematical minimizer.
Decreasing signals and repeated selection
Soft thresholding explains why one fitted coefficient can equal zero. It does not imply that the same variables will be selected in every sample. The score depends on the response noise, so a variable near the threshold may be selected in one sample and omitted in another.
To isolate this effect, consider a fixed standardized design with observations and orthogonal covariates:
Generate the response from
where every covariate has a nonzero coefficient, but the signal decreases with :
For this orthogonal design, the score for covariate satisfies
and the fitted coefficient is
We independently repeat the response simulation 200 times. At each of three fixed penalties, we record whether each coefficient is nonzero and its absolute fitted magnitude. No new mathematical notation is needed for an individual run because every run applies the same calculation.
Because the distribution of each score has already been derived, we can generate the scores directly rather than reconstructing the full response vector in every repetition. The R and Python simulations use the same model and parameter values. Their exact draws differ because the two languages use different random-number generators.
Predict the simulation before viewing it. Which covariates should be selected most often? What should happen to the selection frequencies and fitted magnitudes when increases?
Across 200 repetitions, stronger signals are selected more often. A larger penalty lowers both selection frequencies and average fitted magnitudes.
Show the reproducible code
par(old_par_signal)
Show the reproducible code
import numpy as npimport matplotlib.pyplot as pltrng = np.random.default_rng(43240)n =100p =20n_simulations_py =200beta =0.4** np.sqrt(np.arange(1, p +1))lambda_values = np.array([0.15, 0.07, 0.02])curve_colors = ["#C84A16", "#2F6FB3", "#13294B"]# Under orthogonality, each score has this normal distribution.a_scores_py = rng.normal( loc=beta, scale=1/ np.sqrt(n), size=(n_simulations_py, p),)# Dimensions are simulation, covariate, and penalty.beta_hat_py = np.stack( [ np.sign(a_scores_py) * np.maximum(np.abs(a_scores_py) - lam, 0)for lam in lambda_values ], axis=2,)selection_frequency_py = (np.abs(beta_hat_py) >1e-10).mean(axis=0)mean_magnitude_py = np.abs(beta_hat_py).mean(axis=0)fig, axes = plt.subplots(1, 2, figsize=(9, 4.4))for l, (lam, color) inenumerate(zip(lambda_values, curve_colors)): axes[0].plot( np.arange(1, p +1), selection_frequency_py[:, l], color=color, linewidth=2, label=fr"$\lambda={lam}$", ) axes[1].plot( np.arange(1, p +1), mean_magnitude_py[:, l], color=color, linewidth=2, label=fr"$\lambda={lam}$", )axes[0].set( xlabel="Covariate j", ylabel="Selection frequency", ylim=(0, 1))axes[1].plot( np.arange(1, p +1), beta, color="#4B5563", linewidth=2, linestyle="--", label="true magnitude",)axes[1].set(xlabel="Covariate j", ylabel=r"Mean $|\widehat\beta_j|$")for ax in axes: ax.legend(frameon=False) ax.spines[["top", "right"]].set_visible(False)fig.tight_layout()plt.show()
Across 200 repetitions, stronger signals are selected more often. A larger penalty lowers both selection frequencies and average fitted magnitudes.
The first covariates carry the strongest signals and are selected in nearly every repetition. Later covariates have smaller nonzero coefficients, so response noise more often moves their scores inside the interval . Increasing the penalty widens that interval, lowers selection frequencies, and shrinks the coefficients that remain nonzero.
This orthogonal-design benchmark isolates signal strength from competition among covariates. It gives us a clean reference point before returning to lasso geometry and the multivariable algorithm. The controlled example later in the lecture adds correlation, where two covariates can carry nearly the same predictive information and compete to represent it.
Different prediction targets can also favor different penalty values. At a target such as , the fitted conditional mean depends only on . A strong coordinate may favor less shrinkage, while a weak coordinate may benefit from more variance reduction. Ordinary cross-validation still selects one penalty because it averages validation loss across the observed covariate distribution rather than optimizing prediction at one specially chosen target.
A geometric explanation
For every positive penalty, there is a corresponding constraint size for which the lasso solution also solves
The factor is omitted here because multiplying the constrained objective by a positive constant does not change its minimizer. The penalty value and constraint size are not the same number. Their relationship depends on the observed data and need not be one-to-one when solutions are nonunique.
In two dimensions, the constraint is a diamond with corners on the coordinate axes. A least-squares contour can first touch the diamond at a corner, and a corner has one coordinate equal to zero. The ridge constraint is round, so first contact does not usually occur on an axis.
The same least-squares loss under L1 and L2 constraints. The bold ellipse is the first contour to touch each constraint. In this example, lasso touches the diamond at a corner with a zero second coefficient, while ridge touches the circle with both coefficients nonzero.
This picture helps explain why exact zeros are common, but the one-variable calculation gives the direct mathematical reason: an entire interval of scores is mapped to zero.
From the one-variable rule to a solution path
Coordinate descent and warm starts
With several covariates, the columns of need not be orthogonal. Changing one slope changes the residual seen by the others, so the coefficients cannot generally be found by applying soft thresholding once to each separate least-squares slope.
Week 3 used gradient descent to move all ridge coefficients together in a downhill direction. Coordinate descent instead holds all but one coefficient fixed and solves the remaining one-variable lasso problem exactly. Both are algorithms for minimizing a fixed objective; neither chooses the penalty.
To update slope , form the partial residual
The corresponding one-variable score is
Because each standardized column satisfies , the update is
After updating one coefficient, the algorithm moves to the next. It cycles through all predictors until the coefficients change by less than a chosen tolerance.
To calculate a full path, begin with a large penalty for which every slope is zero. Then decrease and use the previous solution as the starting point for the next fit. This is called a warm start. Nearby penalty values usually have nearby solutions, so warm starts save substantial computation.
For standardized predictors, all slopes are zero whenever
The shared grid below starts at . For the generated sample, this value exceeds for the full training sample and for every cross-validation training fold. Thus, every fitted path begins at the all-zero slope vector.
The lasso objective is convex, so exact convergence gives a global minimizer. A numerical stopping tolerance gives an approximation to that minimizer. Full column rank guarantees a unique coefficient vector. Rank deficiency permits, but does not require, multiple coefficient minimizers. Even when the coefficients are not unique, the fitted vector is unique. This is one reason to be cautious when interpreting which member of a correlated group is nonzero.
Stepwise and stagewise regression are different
Forward stepwise regression adds one predictor to the model in a full fitting step. Forward stagewise regression begins with all slopes at zero and repeatedly makes a small change to the coefficient that most reduces the current residual sum of squares. Because the residuals are reconsidered after every small move, a predictor can receive many updates along the path.
The lasso path is closely related to least-angle and forward-stagewise paths, which explains why variables appear gradually as the penalty decreases. These paths are not identical for every predictor configuration, and none of them should be interpreted as a universal ranking of variable importance. Coordinate descent is the computational method we use here because each update follows directly from the soft-thresholding calculation.
Fitting, tuning, and comparing regularized models
We now follow one controlled dataset from generation through fitting, cross-validation, and comparison with standard software.
A controlled example with correlated predictors
We now generate one dataset with 120 training observations, 80 final test observations, and eight predictors. The response has conditional mean
Only , , and appear in this data-generating mean. The error has a standard normal distribution. The raw predictors are generated so that and in the population.
The following chunk generates one realization. We use a separate seed for the fold assignments so that changing the response simulation later does not silently change the cross-validation folds. The saved CSV is only a bridge that lets the later Python chunk use exactly the same observations.
Show the reproducible code
set.seed(43204)n_train_r <-120n_test_r <-80p <-8n_r <- n_train_r + n_test_r# Begin with independent standard normal variables.independent_draws_r <-matrix(rnorm(n_r * p),nrow = n_r,ncol = p)X_raw_r <- independent_draws_rX_raw_r[, 2] <-0.92* X_raw_r[, 1] +sqrt(1-0.92^2) * independent_draws_r[, 2]X_raw_r[, 4] <-0.75* X_raw_r[, 3] +sqrt(1-0.75^2) * independent_draws_r[, 4]X_raw_r[, 6] <-3.5* independent_draws_r[, 6]colnames(X_raw_r) <-paste0("x", seq_len(p))# Generate the response from the stated sparse regression model.y_r <-0.25+1.40* X_raw_r[, 1] -1.10* X_raw_r[, 3] +0.70* X_raw_r[, 5] +rnorm(n_r)# Create five balanced folds among the training observations.set.seed(43205)fold_r <-rep(NA_integer_, n_r)fold_r[seq_len(n_train_r)] <-sample(rep(1:5, each = n_train_r /5))lasso_data_r <-data.frame(row_id =seq_len(n_r),split =rep(c("train", "test"), c(n_train_r, n_test_r)),fold = fold_r, X_raw_r,y_reg = y_r,check.names =FALSE)dir.create("data/week-04", recursive =TRUE, showWarnings =FALSE)write.csv( lasso_data_r,"data/week-04/lasso-simulation.csv",row.names =FALSE)training_rows_r <- lasso_data_r$split =="train"round(c(`Cor(x1, x2)`=cor(lasso_data_r$x1[training_rows_r], lasso_data_r$x2[training_rows_r]),`Cor(x3, x4)`=cor(lasso_data_r$x3[training_rows_r], lasso_data_r$x4[training_rows_r])), 3)
Cor(x1, x2) Cor(x3, x4)
0.897 0.780
The sample correlations differ slightly from their population values because this is one random realization. Still, a correlated predictor can carry much of the same predictive information as a predictor that appears in the generating equation.
From this point forward, R and Python use the data generated above: the same response values, the same training and test split, the same five cross-validation folds, and the same decreasing grid of penalty values. Within each fit, the predictors are centered and standardized using only the observations available for training.
Predict the path before viewing it. As moves from a large value toward zero, consider:
When should the first coefficients move away from zero?
Could or enter even though it does not appear in the generating equation?
If two fitted models keep different members of a correlated pair, must their test errors be very different?
Fit the shared path in R and Python
The following implementations show the coordinate update directly. Applied software uses the same basic idea together with additional computational shortcuts.
The objective uses standardized coefficients. To express the fitted model on the original predictor scale, use
Thus the same prediction is on standardized predictors or on raw predictors. The code uses beta_hat_raw when it retains the raw-scale coefficients.
Lasso coefficient paths on the original predictor scale. The dashed orange line marks the minimum-error penalty, and the dotted navy line marks the one-standard-error penalty.
Five-fold cross-validation MSE along the lasso path. Error bars are one standard error across folds. The horizontal dotted line shows the one-standard-error limit.
Show the reproducible code
# Use the same observations generated and saved above.import numpy as npimport pandas as pdimport matplotlib.pyplot as pltlasso_data_py = pd.read_csv("data/week-04/lasso-simulation.csv")p =8features_py = [f"x{j}"for j inrange(1, p +1)]lambda_grid_py = np.array([1.7, 1.5, 1.2, 0.8, 0.5, 0.3, 0.2, 0.12,0.08, 0.05, 0.03, 0.015,])train_py = lasso_data_py["split"].eq("train").to_numpy()X_train_raw_py = lasso_data_py.loc[train_py, features_py].to_numpy()y_train_py = lasso_data_py.loc[train_py, "y_reg"].to_numpy()fold_py = lasso_data_py.loc[train_py, "fold"].to_numpy()# Center and standardize using the training observations.x_bar_py = X_train_raw_py.mean(axis=0)s_py = np.sqrt(((X_train_raw_py - x_bar_py) **2).mean(axis=0))X = (X_train_raw_py - x_bar_py) / s_pyy_centered_py = y_train_py - y_train_py.mean()def soft_threshold_py(value, threshold):return np.sign(value) * np.maximum(np.abs(value) - threshold, 0.0)# Each coordinate update is the one-variable soft-thresholding solution.lam =0.12beta_hat_py = np.zeros(X.shape[1])for k inrange(5000): beta_old_py = beta_hat_py.copy()for j inrange(X.shape[1]): r_j = ( y_centered_py- X @ beta_hat_py+ X[:, j] * beta_hat_py[j] ) a_j = np.mean(X[:, j] * r_j) beta_hat_py[j] = soft_threshold_py(a_j, lam)if np.max(np.abs(beta_hat_py - beta_old_py)) <1e-10:break# Convert the standardized slopes back to the original predictor scale.print(pd.Series(beta_hat_py / s_py, index=features_py).round(3))
Lasso coefficient paths on the original predictor scale. The dashed orange line marks the minimum-error penalty, and the dotted navy line marks the one-standard-error penalty.
<matplotlib.legend.Legend object at 0x7fa2e3c28510>
Five-fold cross-validation MSE along the lasso path. Error bars are one standard error across folds. The horizontal dotted line shows the one-standard-error limit.
Read the path and the cross-validation results
The algorithm computes the path from large penalties to small penalties so that it can use warm starts. The plotted horizontal axis increases from left to right, so small penalties appear on the left and large penalties appear on the right. At a sufficiently large , every slope is zero. As the penalty decreases, coefficients begin to move away from zero. Their paths need not move at the same rate because each coordinate update depends on the current residuals from all of the other predictors.
The path should not be read as a ranking of variable importance. In particular, a member of a correlated pair may enter because it carries information similar to the other member. A different response sample or a different set of folds can change which member enters first.
For each cross-validation fold, the code:
computes the predictor centers and scales from the other four folds;
fits every candidate penalty using those observations;
predicts the withheld fold; and
records the withheld-fold MSE.
The mean of the five fold MSEs estimates prediction performance for each penalty. The error bars use the standard deviation across folds divided by . We call this a fold-based standard-error estimate, not a formal confidence interval, because the fold fits use overlapping training observations. The estimated curve and its minimum can change when the data or fold assignment changes.
The complete path begins at . The cross-validation figure focuses on because the larger penalties already show clear underfitting and would compress the differences near the minimum.
Two common choices summarize the curve:
Minimum-error rule: choose the penalty with the smallest mean cross-validation MSE.
One-standard-error rule: add the fold-based standard-error estimate at the minimum, then choose the largest penalty whose mean MSE is below that horizontal limit.
In this example, the minimum-error rule chooses and retains , , , , , and . Predictor enters together with the signal-bearing predictor , illustrating how correlated predictors can share a fitted contribution. The nonzero coefficients of and also remind us that selection in one sample does not prove that a variable belongs to the generating mean.
The one-standard-error rule chooses and retains , , , and . It removes the two additional noise predictors but still keeps both members of the highly correlated pair . Its validation error is slightly larger, but remains below the one-standard-error limit. The two selected fits have test MSEs and . These are observed values from one test sample, so another test sample could change the values or their ordering. Different variable lists can still give similar predictions when the predictors contain overlapping information.
WarningThe test set is used after tuning
The test MSEs are reported only after the two cross-validation rules have been applied. If we inspected all test MSEs and chose the smallest one, the test rows would become part of the tuning process. The resulting test error would then be too favorable as an evaluation of the selected procedure.
Lasso, ridge, and elastic net
The three penalties express different preferences:
Method
Penalty term
Typical fitted pattern
Ridge
Slopes shrink smoothly and are usually all nonzero. Correlated predictors often share the fitted contribution.
Lasso
Some slopes are exactly zero. One member of a correlated group may represent information shared by the group.
Elastic net
The part can create zeros, while the part can make correlated coefficients move more stably together.
Here . Under this convention, gives lasso and gives ridge. Values between zero and one give elastic net. Both and must be chosen. If several values of are compared, using the same cross-validation folds makes their estimated errors directly comparable.
For and , the quadratic part makes the elastic-net coefficient solution unique. This is one reason elastic net can be more stable than lasso when predictors contain nearly the same information.
No penalty is uniformly best. Ridge is often useful when many predictors each contribute a little or when correlated predictors should be kept together. Lasso is useful when a shorter fitted rule is desired. Elastic net is a useful compromise when both sparsity and stability among correlated predictors matter.
Using standard software
The teaching code above makes the coordinate update visible. For an applied analysis, we normally use software that computes the path efficiently and checks convergence. The following examples preserve the training folds and place standardization inside the fitted procedure.
Write the objective before translating argument names:
Tool
Gaussian lasso objective
Course mapping
This lecture
R glmnet with alpha = 1
The same normalized form after its observation weights, intercept, and standardization conventions are matched
lambda = lambda
Python sklearn.linear_model.Lasso
alpha = lambda
The alpha argument has different meanings in the two libraries. In glmnet, it mixes the lasso and ridge penalties. In scikit-learn’s Lasso, it is the penalty strength. Argument names are software choices, not mathematical notation.
# Match the package penalty scale to the course objective before tuning.library(glmnet)train <-subset(lasso_data_r, split =="train")X_raw <-as.matrix(train[, features_r])y <- train$y_regfit <-cv.glmnet(x = X_raw,y = y,family ="gaussian",alpha =1,lambda = lambda_grid_r,foldid = train$fold,type.measure ="mse",standardize =TRUE)coef(fit, s ="lambda.min")coef(fit, s ="lambda.1se")
Show the reproducible code
# This Pipeline fits standardization separately within every cross-validation fold.from sklearn.linear_model import Lassofrom sklearn.model_selection import GridSearchCVfrom sklearn.pipeline import Pipelinefrom sklearn.preprocessing import StandardScalerfold_splits = [ (np.flatnonzero(fold_py != m), np.flatnonzero(fold_py == m))for m inrange(1, 6)]pipeline = Pipeline([ ("scale", StandardScaler()), ("lasso", Lasso(max_iter=20000, tol=1e-10)),])search = GridSearchCV( pipeline, param_grid={"lasso__alpha": lambda_grid_py}, scoring="neg_mean_squared_error", cv=fold_splits, refit=True,)search.fit(X_train_raw_py, y_train_py)# GridSearchCV chooses the smallest mean validation error.search.best_params_
For Gaussian lasso, scikit-learn’s alpha plays the role of in the objective used in this lecture. In glmnet, alpha = 1 requests lasso, while the argument lambda controls the penalty strength. The cv.glmnet() object reports both lambda.min and lambda.1se. GridSearchCV selects the minimum-error setting by default; applying a one-standard-error rule in Python requires reading the fold-level results and choosing the largest eligible penalty.
The name of an argument is not enough to establish that two fits are the same. Before comparing numerical penalty values, check the squared-error normalization, predictor standardization, response scaling, observation weights, and intercept treatment.
Interpreting a sparse fitted model
A zero coefficient is conditional on the other predictors and on . It means that this fitted rule did not use that predictor after accounting for the others at the chosen penalty.
A nonzero coefficient does not by itself establish scientific importance or a causal effect. Lasso is fitting a predictive relationship in the available data.
A stable prediction does not require a stable variable list. Correlated predictors can substitute for one another with little change in prediction error.
Large penalties can remove useful signal. Lasso reduces variation by adding shrinkage bias, just as ridge does.
Cross-validation does not reveal one fixed, universally best penalty. The selected value and the nonzero coefficients can change with the observed sample and fold assignment.
Review
Check your understanding
In the one-variable problem, why is the solution exactly zero when ?
Why does ridge usually shrink a nonzero least-squares slope without making it exactly zero?
In coordinate descent, why must the partial residual be recomputed after other coefficients change?
In the decreasing-signal simulation, why can a truly nonzero coefficient have a selection frequency well below one?
Why can a correlated predictor be nonzero even when it does not appear in the generating equation for the controlled example?
Key ideas
Lasso uses an penalty and can produce an exactly sparse fitted coefficient vector.
Soft thresholding explains the exact zero: scores with absolute value no larger than are mapped to zero.
Selection is sample-dependent. Stronger signals are selected more often, while a larger penalty lowers selection frequencies and fitted magnitudes.
Coordinate descent repeatedly solves one-variable problems, and warm starts make a full penalty path efficient.
Correlated predictors can give similar predictions while producing different lists of nonzero coefficients.
Cross-validation chooses a predictive rule, while the final test set evaluates it. Elastic net offers a compromise between lasso sparsity and ridge stability.
Looking ahead. Lasso selects among the original predictor coordinates. In Week 5, principal component analysis takes a different approach: it constructs new directions that summarize the predictor variation before a response model is fitted.
James, Witten, Hastie, Tibshirani, and Taylor, An Introduction to Statistical Learning, Chapter 6, give an accessible discussion of ridge, lasso, and tuning.