What Lasso Is and Is Not
Fit correlated two-feature Lasso via cyclic coordinate descent on partial residuals and separate what L1 sparsity proves from what it cannot claim.
The problem
Orthogonal columns let us soft-threshold each feature independently, yet real predictors overlap (). If two correlated columns both track and you soft-threshold and separately, both features claim credit for the same signal and prediction overshoots.
When has off-diagonal entries, no single matrix formula solves Lasso because is unknown ahead of time. Instead, cyclic coordinate descent updates one weight at a time while holding the others fixed: form the partial residual , dot with to get , set
and repeat across coordinates until settles.
Work through the numbers
Take the correlated four-row [x_1, x_2, y] table (1, 1, 2), (1, 1, 2), (-1, -1, -2), and (-1, 0, -1) at lam = 4.0 (here exactly).
Column norms are and , with strong overlap and raw correlations , . Pretending the columns are orthogonal gives , double-counting the shared signal.
Now run coordinate descent from [0.0, 0.0]. With , updates . Immediately subtract from to get partial residual . Dotting with what left unexplained shrinks its correlation from 6.0 down to . Because , , converging to [0.75, 0.0].
When does enter as lam decreases? While and , leaves partial correlation , which exceeds as soon as .
Below lam = 3.0, solving the active KKT system and gives : [1.0, 0.5] at lam = 1.5, and [1.0, 1.0] at lam = 0.0.
The live model
The left bars compare naive independent thresholding (gray) against converged coordinate-descent weights [w_1, w_2] (blue when active, green dot when zero); the right panel plots row targets (blue) against fitted predictions (green). Drag lam below 3.0 (say to 1.5) to watch enter at [1.0, 0.5], or slide lam up to 7.0 and beyond to watch vanish too.
![Correlated two-feature Lasso comparing naive [0.75, 0.67] against coordinate descent [0.75, 0.0] at lam = 4.0, alongside row targets vs predictions.](../assets/ml/what-lasso-is-and-is-not--demo.png)
let lam = scene.parameter("lam", 4.0, 0.0, 8.0, 0.5);
let x1 = input.select(1, 0);
let x2 = input.select(1, 1);
let ys = input.select(1, 2);
let s0 = x1.square().sum();
let s1 = x2.square().sum();
let w0 = torch.zeros(1).to(DType.F64).sum();
let w1 = torch.zeros(1).to(DType.F64).sum();
for (step in range(0, 60)) {
let rho0 = (x1 * (ys - x2 * w1)).sum();
w0 = (rho0.sign() * (rho0.abs() - lam).relu()).div(s0);
let rho1 = (x2 * (ys - x1 * w0)).sum();
w1 = (rho1.sign() * (rho1.abs() - lam).relu()).div(s1);
}
let pair = torch.list().add(w0.reshape(1)).add(w1.reshape(1));
let answer = torch.cat(pair, 0);
out.set("weights", answer);
{
"weights": [
0.75,
0
]
}Your turn
Fit correlated two-feature Lasso [w_0, w_1] at penalty lam by running 60 sweeps of cyclic coordinate descent from zero. On the default table at lam = 4.0 the starter returns [0.75, 0.6667] where the page computed [0.75, 0.0].
![Starter double-counts correlated signal, returning [0.75, 0.67] instead of [0.75, 0.0] at lam = 4.0.](../assets/ml/what-lasso-is-and-is-not--exercise.png)
let lam = scene.parameter("lam", 4.0, 0.0, 8.0, 0.5);
let x1 = input.select(1, 0);
let x2 = input.select(1, 1);
let ys = input.select(1, 2);
let s0 = x1.square().sum();
let s1 = x2.square().sum();
let c0 = (x1 * ys).sum();
let c1 = (x2 * ys).sum();
let w0 = (c0.sign() * (c0.abs() - lam).relu()).div(s0);
let w1 = (c1.sign() * (c1.abs() - lam).relu()).div(s1);
let pair = torch.list().add(w0.reshape(1)).add(w1.reshape(1));
let answer = torch.cat(pair, 0);
out.set("weights", answer);
{
"weights": [
0.75,
0.6666666666666666
]
}Fit correlated two-feature Lasso [w_0, w_1] at penalty lam by iterating cyclic coordinate descent to convergence (60 sweeps suffice). On the default table at lam = 4.0 the starter returns [0.75, 0.6667] where the page computed [0.75, 0.0].
Read the result carefully
Keep three boundaries of Lasso clear in practice:
- Dropping out does not mean irrelevant alone: built with raw correlation , yet landed at for every because correlated absorbed its share first. Among near-duplicate columns, Lasso tends to keep one representative and zero its twin (which one can flip under small data changes); Ridge shares weight across both.
- Scale sensitivity: like Ridge, depends on column units, so standardize features before fitting.
- Row-count ceiling: when , Lasso selects at most nonzero features before saturating.
Recap
- Correlated Lasso has no one-shot closed form; cyclic coordinate descent repeatedly applies to partial residuals until convergence.
- Subtracting before updating prevents correlated predictors from double-counting shared target variance.
- A zero Lasso weight signals conditional redundancy at penalty on standardized scales, not causal absence.