2.2.15 · HinglishLinear & Logistic Regression

Elastic Net regularization

1,697 words8 min readRead in English

2.2.15 · AI-ML › Linear & Logistic Regression


WHAT is it?


WHY combine them? (first-principles reasoning)

L1 sparsity kyun deta hai: L1 ball ke corners axes par hote hain. Jab loss contour pehli baar is ball ko touch karti hai, woh aksar corner par touch karti hai → kuch coordinates exactly ho jaate hain.

L1 akela correlated features par kyun fail hota hai: agar ho, toh loss direction mein almost flat hoti hai. L1 ki penalty bhi us direction mein constant hoti hai (jab tak signs match karein), isliye solution unique nahi hota — woh arbitrarily hil-dol jaata hai.

L2 add karne se yeh kyun theek hota hai: L2 penalty strictly convex hai aur (fixed sum ke liye) minimize hoti hai jab ho. Toh L2 term tie todta hai aur weight ko correlated features ke beech evenly spread karta hai. Yahi grouping effect hai.


HOW to derive the update (soft-thresholding)

Hum ek weight ke liye coordinate-descent update derive karte hain. Assume karo ki features standardized hain, yaani .

Step 1 — ko isolate karo. Baaki sab weights fix rakho. Partial residual define karo (target minus baaqi sab ka contribution): Yeh step kyun? Coordinate descent ek waqt mein ek variable optimize karta hai; jo bhi se involve nahi hai woh constant hai.

Step 2 — 1-D objective likho. Yeh step kyun? Yeh exactly hai jismein sirf free hai.

Step 3 — subgradient lo aur 0 par set karo. (feature ka partial residual ke saath correlation). use karte hue: Yeh step kyun? Quadratic parts cleanly differentiate hote hain; ka subgradient ke liye hai aur par hai.

Step 4 — solve karo, soft-threshold milta hai. Minimizer hai: Yeh step kyun? soft-thresholding operator hai: L1 term ko zero ki taraf se shrink karta hai (aur maar deta hai agar ho), jabki L2 term se divide karta hai, jo ek extra proportional shrink hai.

Figure — Elastic Net regularization

Worked examples



Active recall

Recall Forecast-then-Verify: pehle predict karo, phir reveal karo

Q: Agar ho, toh kaun sa method milta hai, aur kya woh zeros produce karta hai? A: Pure Ridge; yeh shrink karta hai lekin weights ko kabhi exactly zero nahi karta.

Q: Do perfectly correlated features — Elastic Net unke saath weight ka kya karta hai? A: L2 term ki wajah se weight ko unke beech (roughly) equally split karta hai (grouping effect).

Recall Feynman: ek 12-saal ke bachhe ko explain karo

Socho tum ek trip ke liye backpack pack kar rahe ho aur tumhe decide karna hai ki kaun si gadgets laani hain. Lasso ek strict dost hai: "EK flashlight lo, baaki do phenko" — chahe teeno equally achhi hon, aur agli baar woh alag wali randomly pick kar sakta hai. Ridge ek soft dost hai: "sab ki chhoti-chhoti versions laao, koi ghar nahi chhutega." Elastic Net samajhdaar dost hai: "jo cheez sacchi bekaar hai usse phenko (jaise Lasso), lekin teeno equally-achhi flashlights ke liye, teeno chhoti laao taaki fair aur stable rahe (jaise Ridge)." Equally-achhi chezon ke liye yeh fairness hi wajah hai ki yeh similar chezon se ghabrata nahi.


The 80/20 core

  1. .
  2. Update = soft-threshold (numerator, L1) over (denominator, L2).
  3. L1 → sparsity; L2 → grouping/stability; Elastic Net → dono.
  4. (strength) aur (flavor) ko CV se tune karo; pehle standardize karo.

Connections

  • Ridge Regression special case (sirf L2).
  • Lasso Regression special case (sirf L1).
  • Soft-Thresholding Operator — woh proximal operator jo update ko power deta hai.
  • Coordinate Descent — woh algorithm jo ise solve karta hai.
  • Bias-Variance Tradeoff — regularization variance ko bias ke liye trade karta hai.
  • Feature Correlation & Multicollinearity — woh problem jo Elastic Net specifically sambhalta hai.
  • Cross-Validation kaise choose kiye jaate hain.

Elastic Net loss mein kaun si penalty add hoti hai?
Ek convex combination — L1 aur L2 dono.
Elastic Net mein kya control karta hai?
L1 aur L2 ke beech mixing ratio; Lasso hai, Ridge hai.
kya control karta hai?
Regularization ki overall strength (L1/L2 flavor se independent).
Lasso correlated features par kyun struggle karta hai?
Iska objective correlated direction mein flat hota hai, isliye selection non-unique/unstable hoti hai.
L2 term correlated features ko kyun fix karta hai?
L2 strictly convex hai aur equal weights par minimize hoti hai, isliye weight evenly split hoti hai (grouping effect).
ke liye coordinate-descent update likho.
jahan soft-thresholding hai.
Soft-thresholding operator kya hai?
— zero ki taraf shrink karta hai, zero set karta hai agar ho.
Update ka kaun sa part sparsity deta hai vs stability?
Numerator (L1 soft-threshold) → sparsity; denominator (L2) → stability/grouping.
Kya Elastic Net se pehle features standardize karne chahiye?
Haan — penalties scale-invariant nahi hain, isliye unstandardized scales bias karti hain ki kaun si features penalize hongi.
Agar , , ho, toh kya hai?
, kyunki toh soft-threshold zero hai.

Concept Map

gives

fails on

shrinks but

strictly convex fixes

produces

convex combination of

convex combination of

controlled by

alpha=1

alpha=0

scaled by

solved via

yields

achieves

achieves

L1 Lasso penalty

Sparsity / zero weights

Correlated features

L2 Ridge penalty

Never zeroes weights

Grouping effect

Elastic Net

alpha mixing ratio 0 to 1

lambda overall strength

Coordinate descent

Soft-thresholding update