Speed

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 (x1⊤x2≠0x_1^\top x_2 \neq 0). If two correlated columns both track yy and you soft-threshold x1⊤yx_1^\top y and x2⊤yx_2^\top y separately, both features claim credit for the same signal and prediction overshoots.

When X⊤XX^\top X has off-diagonal entries, no single matrix formula solves Lasso because sign⁡(w)\operatorname{sign}(w) is unknown ahead of time. Instead, cyclic coordinate descent updates one weight at a time while holding the others fixed: form the partial residual r(−j)=y−∑k≠jxkwkr^{(-j)} = y - \sum_{k \neq j} x_k w_k, dot with xjx_j to get ρj=xj⊤r(−j)\rho_j = x_j^\top r^{(-j)}, set

wj=S(ρj,λ)xj⊤xj w_j = \frac{S(\rho_j, \lambda)}{x_j^\top x_j}

and repeat across coordinates until [w1,w2][w_1, w_2] 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 y=x1+x2y = x_1 + x_2 exactly).

Column norms are s1=4.0s_1 = 4.0 and s2=3.0s_2 = 3.0, with strong overlap x1⊤x2=3.0x_1^\top x_2 = 3.0 and raw correlations c1=7.0c_1 = 7.0, c2=6.0c_2 = 6.0. Pretending the columns are orthogonal gives [S(7.0,4.0)/4.0,S(6.0,4.0)/3.0]=[0.75,0.67][S(7.0, 4.0) / 4.0, S(6.0, 4.0) / 3.0] = [0.75, 0.67], double-counting the shared signal.

Now run coordinate descent from [0.0, 0.0]. With w2=0w_2 = 0, ρ1=7.0\rho_1 = 7.0 updates w1=S(7.0,4.0)/4.0=0.75w_1 = S(7.0, 4.0) / 4.0 = 0.75. Immediately subtract 0.75x10.75 x_1 from yy to get partial residual r=[1.25,1.25,−1.25,−0.25]r = [1.25, 1.25, -1.25, -0.25]. Dotting x2x_2 with what x1x_1 left unexplained shrinks its correlation from 6.0 down to ρ2=1.25+1.25+1.25+0=3.75\rho_2 = 1.25 + 1.25 + 1.25 + 0 = 3.75. Because ∣3.75∣≤4.0|3.75| \le 4.0, w2=S(3.75,4.0)/3.0=0.0w_2 = S(3.75, 4.0) / 3.0 = 0.0, converging to [0.75, 0.0].

When does w2w_2 enter as lam decreases? While w2=0w_2 = 0 and 0<λ<7.00 < \lambda < 7.0, w1=(7−λ)/4w_1 = (7 - \lambda) / 4 leaves partial correlation ρ2=6−3(7−λ)/4=(3+3λ)/4\rho_2 = 6 - 3(7 - \lambda)/4 = (3 + 3\lambda)/4, which exceeds λ\lambda as soon as λ<3.0\lambda < 3.0.

Below lam = 3.0, solving the active KKT system 4w1+3w2=7−λ4w_1 + 3w_2 = 7 - \lambda and 3w1+3w2=6−λ3w_1 + 3w_2 = 6 - \lambda gives [w1,w2]=[1.0,1.0−λ/3][w_1, w_2] = [1.0, 1.0 - \lambda / 3]: [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 yiy_i (blue) against fitted predictions XwX w (green). Drag lam below 3.0 (say to 1.5) to watch w2w_2 enter at [1.0, 0.5], or slide lam up to 7.0 and beyond to watch w1w_1 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.
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.
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: x2x_2 built y=x1+x2y = x_1 + x_2 with raw correlation c2=6.0c_2 = 6.0, yet landed at w2=0.0w_2 = 0.0 for every λ≥3.0\lambda \ge 3.0 because correlated x1x_1 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, λ∥w∥1\lambda \|w\|_1 depends on column units, so standardize features before fitting.
  • Row-count ceiling: when d>Nd > N, Lasso selects at most NN nonzero features before saturating.

Recap

  • Correlated Lasso has no one-shot closed form; cyclic coordinate descent repeatedly applies S(xj⊤r(−j),λ)/(xj⊤xj)S(x_j^\top r^{(-j)}, \lambda) / (x_j^\top x_j) to partial residuals until convergence.
  • Subtracting x1w1x_1 w_1 before updating w2w_2 prevents correlated predictors from double-counting shared target variance.
  • A zero Lasso weight signals conditional redundancy at penalty λ\lambda on standardized scales, not causal absence.