5.6.3 · D3 · HinglishMachine Learning (Aerospace Applications)

Worked examplesRegularization — L1 (lasso), L2 (ridge), dropout

3,185 words14 min read↑ Read in English

5.6.3 · D3 · Coding › Machine Learning (Aerospace Applications) › Regularization — L1 (lasso), L2 (ridge), dropout

Yeh page parent topic ki practice arena hai. Humne teen tools — L2 (ridge), L1 (lasso), dropout — pehle se first principles se build kar liye hain. Ab hum inhe haath se har us situation mein chalate hain jo aa sakti hai: har sign, tricky exactly-at-zero case, dono limits aur , ek real aerospace word problem, aur ek exam-style twist.

Kuch bhi naya assume nahi kiya gaya. Agar koi symbol aata hai, toh woh parent note mein define tha; lekin hum usse wahan phir se state karte hain jab bhi use karte hain, toh tum line one se padh sakte ho.

Do symbols jinhe hum baar baar use karte hain:

  • (eta) = learning rate, ek gradient step ka size. Socho "kitna bada kadam."
  • (lambda) = regularization strength, hum bade weights ko kitna penalize karte hain. Socho "teacher kitna strict hai."

The scenario matrix

Neeche har cell ek tarah ki situation hai jo topic throw kar sakta hai. Har worked example un cell(s) ke saath tagged hai jo woh cover karta hai, toh end tak har cell filled hogi.

# Cell (case class) Tool Covered by
A Positive weight, gentle shrink L2 Ex 1
B Negative weight, sign handled L2 Ex 1
C Limit (no reg) L2/L1 Ex 2
D Limit (over-shrink / overshoot) L2 Ex 2
E Small weight → crosses zero (soft threshold) L1 Ex 3
F Large weight → shrinks but survives, both signs L1 Ex 3
G Degenerate input exactly (subgradient) L1 Ex 4
H Geometry: why L1 corner = sparsity L1 vs L2 Ex 5
I Dropout expectation / scaling both conventions Dropout Ex 6
J Real-world word problem (choose the tool) all Ex 7
K Exam twist (L1+L2 = elastic net, hidden trap) mixed Ex 8

Example 1 — L2 ek positive aur ek negative weight par (cells A, B)

Forecast: compute karne se pehle guess karo — positive weight chhota hona chahiye (0 ki taraf), negative weight kam negative hona chahiye (woh bhi 0 ki taraf). Regularization hamesha zero ki taraf pull karti hai. Yeh prediction hold karo.

Recipe (parent ki L2 formula se):

Step 1 — shrink factor compute karo. Yeh step kyun? Yeh akela number L2 ki poori rooh hai: data dekhne se pehle, har weight apne aap ka ho jaata hai. Yahi "weight decay" hai.

Step 2 — isse par apply karo. Toh . Yeh step kyun? Shrink () proportional hai — bada weight bada chunk kho deta hai. Phir data gradient use thoda aur neeche nudge karta hai.

Step 3 — isse par apply karo. Toh . Yeh step kyun? Dekho sign automatically handle ho gaya — shrink factor jo bhi sign weight ka ho use multiply karta hai, toh ban jaata hai (zero ke karib, door nahi). L2 mein negatives ke liye koi special case ki zarurat nahi.

Verify: Dono zero ki taraf move hue: aur . Forecast se match. Bade weight ne decay kiya, chhote ne — proportional, jaisa promise tha. Units: weights dimensionless model coefficients hain, toh sab terms dimensionless hain. ✓


Example 2 — dono L2 limits (cells C, D)

Forecast: ke saath kuch nahi hilna chahiye. Jaise badhta hai weight zero ki taraf kheecha jaata hai. Lekin kya koi itna bada hai jo overshoot kare? Guess: haan — aur socho kaun sa sign dikhayega.

Kyunki data gradient hai, update purely hai.

Step 1 — (cell C). Yeh step kyun? Koi regularizer nahi toh model untouched rehta hai — yahi woh baseline hai jiske baare mein parent ne bataya tha ki overfit karta hai.

Step 2 — . Yeh step kyun? Healthy shrink: har step mein weight ka bachta hai, toh kaafi steps mein woh smoothly ki taraf decay karta hai.

Step 3 — (cell D, danger zone). Yeh step kyun? Shrink factor negative ho gaya. Weight shrink nahi hua — usne sign flip kiya aur size pe raha! Aur bade ke saath factor ho jaata hai aur weight explode karta hai. Yahi "" ka practical matlab hai: update unstable ho jaata hai jab tak na ho.

Verify: Stability rule hai , yaani . Check: (edge, koi motion nahi), ✓ andar, bilkul unstable edge par, jisse humne woh sign flip dekha. Parent ka claim " weights shrink hokar zero ho jaate hain" ideal fixed point hai — lekin sirf tab reachable hai jab itna chhota ho ki rahe. ✓


Example 3 — L1 soft-thresholding, small vs large, dono signs (cells E, F)

Forecast: L1 ek fixed amount zero ki taraf subtract karta hai. Guess karo kaun se weights bachenge: se chhota weight bach nahi sakta; kaafi bada ek sirf shave off karayega.

Parent ki soft-threshold formula:

Step 1 — (cell E, bilkul threshold par). Yeh step kyun? Uski magnitude step ke barabar hai, toh woh bilkul zero par land karta hai aur select out ho jaata hai. Yahi L1 ka automatic feature selection hai action mein.

Step 2 — (cell E, negative, below threshold). Yeh step kyun? guard ke bina weight flip ho jaata positive — ek bogus overshoot. use bilkul zero par clamp karta hai. ne negative input ko sahi handle kiya.

Step 3 — (cell F, large, survives). Yeh step kyun? Ek bada informative weight sirf fixed kho deta hai — woh bachta hai aur apna kaam karta rehta hai. L2 se contrast karo, jo proportionally () le leta.

Verify: Teen mein se do weights bilkul zero ho gaye (sparsity!), bade ne exactly shrink kiya. Sanity: absolute weights ka sum se gira, drop ka, aur (total available step se zyada drop nahi ho sakta). ✓


Example 4 — degenerate case exactly (cell G)

Forecast: Parent ne note kiya tha ki par undefined hai (diamond ka wahan sharp corner hai). Toh hum kya plug in karein? Guess: penalty "resist" karni chahiye data gradient ko, koi definite direction push karne ki jagah.

Step 1 — zero par subgradient yaad karo. par ka slope ek akela number nahi hai; woh interval mein koi bhi value ho sakti hai. Yeh set subgradient kehlati hai. Yeh step kyun? Kyunki corner ki kaafi tangent lines hain, ek nahi — hume puri interval se reason karna hoga, ek point se nahi.

Step 2 — check karo ki data gradient penalty se escape kar sakta hai ya nahi. Weight zero chhod sakta hai sirf tab jab data gradient maximum penalty pull se zyada strong ho. Yahan . Yeh step kyun? Interval ke andar penalty data gradient ko exactly cancel kar sakti hai subgradient … choose karke — aur seedha bolein, kyunki , koi subgradient value total gradient ko zero kar deta hai.

Step 3 — conclude karo ki weight same rehta hai. Yeh step kyun? L1 se pehle se zeroed weight zeroed hi rehta hai jab tak uska data signal se zyada na ho. Yahi exactly reason hai ki L1 stable sparsity deta hai — weak signals par features wapas on nahi flickerti.

Verify: Threshold check: activate hone ke liye chahiye; false, toh weight rehta hai. Agar data gradient instead hota, toh ek step deta , yaani weight finally zero chhod deta. ✓


Example 5 — geometry: kyun L1 diamond zeros banata hai (cell H)

Forecast: Ellipse ko baahri taraf grow karte socho jab tak woh pehli baar budget region ko touch na kare. Woh circle vs diamond ko kahan touch karta hai? Guess: diamond ko pointy corner par touch milta hai.

Figure — Regularization — L1 (lasso), L2 (ridge), dropout

Step 1 — L2 (circle) side padhho, left panel. Budget round region hai. Expanding ellipse (data loss) ise ek smooth arc par touch karti hai, aisa point jahan dono aur nonzero hain. Yeh step kyun? Smooth boundary ki koi preferred direction nahi hoti, toh tangency wahan land hoti hai jahan ellipse lean karti hai — generically off-axis. Result: sab weights chhote, koi exactly zero nahi.

Step 2 — L1 (diamond) side padhho, right panel. Budget diamond hai. Uske corners axes par hain (jahan ek coordinate zero hai). Ellipse, expand hote hue, bahut often pehle ek corner se bump karti hai. Yeh step kyun? Corners ellipse ki taraf stick out karte hain aur ellipse orientations ki puri range cover karte hain, toh corner par tangency likely hai. Us corner par ek coordinate exactly zero hai → sparsity.

Step 3 — update rule se connect karo. Yeh geometry Example 3 ki soft-threshold ki same kahani hai: constant push hi hai jo ek coordinate ko poori tarah axis par drive karta hai.

Verify: Diamond ka corner -axis par hai — ek coordinate exactly . Circle ke liye sirf axis points isolated hain; generic tangent line off-axis touch karta hai. ✓ (algebraic check VERIFY mein)


Example 6 — dropout expectation, dono scaling conventions (cell I)

Forecast: "Keep probability" hai. Guess karo expected surviving signal hoga classic dropout ke liye, aur inverted dropout engineer kiya gaya hai ki poora wapas de.

Step 1 — classic dropout, training expectation. Yeh step kyun? Average par forward passes neuron ko rakhte hain; mean signal tak scale down ho jaata hai.

Step 2 — classic dropout, test time correction. Test par hum neuron ko hamesha rakhte hain, toh training ke expected se match karne ke liye se scale karo: Yeh step kyun? Test ko wahi average magnitude dekhni chahiye jo next layer ko train kiya gaya tha, warna har activation zyada bada hoga.

Step 3 — inverted dropout, training scaling. Jab rakha jaaye, se divide karo: Yeh step kyun? Training ke dauran pre-inflate karke, expectation pehle se poora hai, toh test time mein koi scaling nahi chahiye — yahi reason hai ki modern frameworks ise use karte hain.

Verify: Classic: train mean , test output — matched ✓. Inverted: train mean , test output — matched ✓. Dono conventions identical test behaviour dete hain ( effective vs full ek re-parameterization hai; downstream weights ke saath ratio consistent hai). ✓


Example 7 — real-world: sahi tool choose karo (cell J)

Forecast: Sparsity + interpretability ek tool chikhti hai; deep net mein overfitting doosra. Guess: sensor-selection linear layer par L1, CNN ke andar dropout.

Step 1 — sensor selection → L1. Kyun? Ex 3 se, L1 weak weights ko exactly zero karta hai, toh 45 useless sensors ka coefficient ho jaata hai aur model se drop ho jaate hain. Yeh engineers ka "kaun se 5 sensors" wala interpretable jawab deta hai. Feature Engineering se tied.

Step 2 — survivors par smooth stable coefficients → optionally L2. Kyun? Bachne wale 5 sensors mein hum nahi chahte ki koi single coefficient blow up kare (Ex 1 ka proportional decay), toh light L2 unhe well-conditioned rakhti hai.

Step 3 — deep CNN overfitting → dropout. Kyun? Ex 6 se, dropout co-adaptation tod deta hai toh CNN training-flight noise memorize nahi kar sakta. Yeh kaafi sub-networks ko average karne jaisa behave karta hai — Ensemble Methods se related.

Step 4 — / honestly choose karo. Kyun? Koi bhi strength a priori nahi pata; inhe Cross-Validation se sweep karo aur train aur test loss ke beech gap dekho (Overfitting Detection).

Verify: Counts par sanity: L1 moderate ke saath jo 50 mein se 5 features rakhe matlab zeros — parent ke Example 2 vector ke 45 zeros ke saath consistent. Dropout FC layers par parent ke fault-detection CNN se match karta hai. ✓


Example 8 — exam twist: elastic net trap (cell K)

Forecast: Ek saath do forces — proportional L2 shrink aur constant L1 push. Guess: pehle L2 factor apply karo, phir result par L1 soft-threshold.

Combined update (data gradient ):

Step 1 — L2 shrink factor apply karo. Yeh step kyun? L2 proportional hai, toh woh pehle multiplicatively act karta hai, deta hai .

Step 2 — us result par L1 soft-threshold apply karo. Yeh step kyun? Ab constant L1 step subtract karo. Dono pulls zero ki taraf, lekin akele kisi ne bhi zero reach nahi kiya, toh weight par bachta hai.

Step 3 — trap spot karo. Agar tum (galat se) L1 pehle apply karo: , phir . Alag jawab! Convention hai L2 shrink phir L1 threshold, deta hai . Yeh step kyun? Kyunki L1 nonlinear hai, order matter karta hai — classic exam gotcha.

Verify: Correct order deta hai ; galat order deta hai ; woh differ karte hain, order-sensitivity confirm karte hue. Dono weight ko se neeche pull karte hain (elastic net = "L1 sparsity flavor + L2 stability"). ✓


Recall Self-test (jawab dene ke baad reveal karo)

par L2 step, data grad , , kya deta hai? ::: L1 step ko zero karta hai jab kis value ke barabar ho? ::: L2 stability ke liye, kya se neeche rehna chahiye? ::: Inverted dropout with : value ka ek kept neuron kya ban jaata hai? ::: Elastic-net order (kaun si penalty pehle)? ::: L2 shrink, phir L1 threshold

Related deep-dive links: Gradient Descent Variants (kaise in updates ke saath interact karta hai), Neural Network Architectures (kahan dropout layers baithti hain), Bayesian Inference (L2 = Gaussian prior, L1 = Laplace prior — probabilistic story).