5.6.2 · D3 · HinglishMachine Learning (Aerospace Applications)

Worked examplesLogistic regression — sigmoid, cross-entropy loss

2,437 words11 min read↑ Read in English

5.6.2 · D3 · Coding › Machine Learning (Aerospace Applications) › Logistic regression — sigmoid, cross-entropy loss

Yeh Logistic Regression ka ek worked-example deep dive hai. Parent note ne machinery banayi thi — sigmoid, cross-entropy, gradient . Yahan hum ise har us case ke against stress-test karenge jo yeh topic throw kar sakta hai: ki har sign, degenerate boundary, saturated tails jahan gradients vanish ho jaate hain, ek real aerospace word problem, aur ek exam-style twist.

Kuch naya assume nahi kiya gaya hai. Agar koi symbol aata hai, toh woh parent mein earn kiya ja chuka hai. Pehle cases ko naam lete hain.


The scenario matrix

Har logistic-regression computation inn cells mein se kisi ek mein rehti hai. Hum sab ko cover karenge.

Cell Kya ise alag banata hai Covered by
A. , correct model confident aur sahi Ex 1
B. , wrong model confident aur galat — bada loss Ex 2
C. boundary exactly — decision knife-edge Ex 3
D. Saturated tail bahut bada — sigmoid flat, gradient Ex 4
E. Multi-feature vector pura mixed signs ke saath Ex 5
F. Full descent step forward → loss → gradient → weight update Ex 6
G. Real-world word problem English → features → prediction translate karna Ex 7
H. Exam twist odds/log-odds reasoning, koi calculator sigmoid nahi Ex 8
Figure — Logistic regression — sigmoid, cross-entropy loss

Upar S-curve dekho. Chaar coloured dots is poore page ke characters hain: green (confident-right, cell A), red (confident-wrong, cell B), yellow (the boundary, cell C), aur faded dots jo tails par bahut door hain (saturation, cell D). Yeh picture apne dimaag mein rakho.


Example 1 — Cell A: , prediction correct

Forecast: compute karne se pehle guess karo — positive lagta hai, , toh hum expect karte hain aur chhota loss. Apna guess likh lo.

  1. Logit compute karo. . Yeh step kyun? Aage ka sab kuch chahiye; yeh ek akela number hai jo saari feature information sigmoid mein le jaata hai.
  2. Squash karo. . Yeh step kyun? Sigmoid raw score ko probability mein badalta hai. , bilkul forecast ke anusaar.
  3. Loss. Kyunki , sirf pehla term bachta hai: . Yeh step kyun? ke saath cross-entropy hai; 1 ke paas probability se loss 0 ke paas aata hai.

Verify karo: ✓ (class 1 predict karta hai, truth se match). Loss chhota hai ✓. Sanity: , aur 1 se thoda kam number ka ek chhota negative hai, toh chhota positive hai. Forecast confirm hua.


Example 2 — Cell B: , prediction WRONG

Forecast: truth cloudy hai () lekin agar negative nikle toh model "not cloudy" vote karta hai — ek confident galat jawab, toh expect karo bada loss.

  1. Logit. . Yeh step kyun? Mixed-sign weights: bright pixels upar push karte hain, variance term neeche. Net negative hai.
  2. Squash. . Yeh step kyun? : model kehta hai "probably not cloudy."
  3. Loss. , toh . Yeh step kyun? Cross-entropy confident wrongness ko punish karta hai — par hona jab jawab 1 hai, Example 1 ke loss ka lagbhag 5× cost karta hai.

Verify karo: lekin → misclassified ✓. Losses compare karo: (galat) vs (sahi) — galat case bahut zyada hurt karta hai, exactly wahi jo ek achha loss karna chahiye ✓.


Example 3 — Cell C: the boundary (degenerate)

Forecast: exactly hoga, toh — model maximally uncertain hai. Gradient kaisa dikhta hai jab model commit karne se mana kar de?

  1. Logit. . Yeh step kyun? Yeh decision boundary hai: woh jagah hai jahan "class 0" aur "class 1" tie karte hain.
  2. Squash. . Yeh step kyun? , toh sigmoid exactly aadha deta hai — upar figure mein yellow dot.
  3. Loss. , toh . Yeh step kyun? Boundary par loss hai chahe true label kuch bhi ho — total uncertainty dono taraf ek jaisi cost karti hai.
  4. Gradient. . Yeh step kyun? Positive gradient → descent ko decrease karega, ko 0 se neeche push karega taaki correct class 0 ki taraf drop ho.

Verify karo: exactly ✓. Loss ✓. Gradient boundary par non-zero hai — isliye logistic regression ambiguous points se bhi seekhta rehta hai, ek hard threshold ke unlike.


Example 4 — Cell D: saturation, jahan gradients vanish ho jaate hain

Forecast: bahut bada hai, toh par chipka hua hai. Jab model sahi ho, expect karo tiny gradient. Jab yeh par galat ho (ek confident blunder), gradient utna hi bada ho sakta hai jitna feature allow karta hai — dekho.

Figure — Logistic regression — sigmoid, cross-entropy loss
  1. Logit aur squash. , . Yeh step kyun? Sigmoid yahan essentially flat hai (figure mein right side par near-horizontal curve dekho).
  2. Gradient, correct label . . Yeh step kyun? Almost zero. Model sahi aur confident hai, toh seekhne ke liye kuch nahi — descent barely move karta hai. Yeh vanishing-gradient tail hai.
  3. Gradient, wrong label . . Yeh step kyun? Ek confident galat prediction maximum possible gradient magnitude deti hai (feature ka near 1×) — model ko zor se wapas khaincha jaata hai.

Verify karo: ✓. Correct-label gradient (tiny) ✓; wrong-label gradient (large) ✓. Gradient magnitude 1 se bounded hai — saturation learning speed ko limit karta hai jab sahi ho, lekin kabhi nahi jab catastrophically galat ho.


Example 5 — Cell E: multi-feature vector, mixed signs

Forecast: teen features alag-alag directions mein khichti hain; bias add karo. Numbers crunch karne se pehle ka sign guess karo.

  1. Dot product term by term. . Yeh step kyun? Dot product ek weighted vote hai: har feature apne weight se multiply hoti hai, phir sum hota hai. Negative weights ek feature ko class 0 ke liye vote karne dete hain.
  2. Bias add karo. . Yeh step kyun? Bias poori decision boundary shift karta hai; yahan yeh negative vote ko thoda soft karta hai.
  3. Squash. .
  4. Loss. , toh . Yeh step kyun? matlab hum chahte hain chhota ho; reasonably chhota hai, toh loss modest hai.

Verify karo: ✓, aur truth class 0 hai, toh model sahi hai → chhota loss ✓.


Example 6 — Cell F: ek complete gradient-descent step

Forecast: positive hai lekin confident nahi; , toh expect karo ki step ke baad increase hoga.

  1. Forward. ; . Yeh step kyun? Current prediction establish karta hai taaki hum measure kar sakein kitna galat hai.
  2. Loss. . Yeh step kyun? "Before" cost record karta hai taaki baad mein confirm kar sakein ki update ne help ki.
  3. Gradient. . Yeh step kyun? Negative → prediction ke liye bahut kam; descent ko mein add karna hai.
  4. Update. . Yeh step kyun? Gradient descent gradient ke against move karta hai; double negative ko raise karta hai.

Verify karo: New , new se upar, target ke paas ✓. New loss ✓. Step ne loss reduce kiya, toh yeh sahi direction mein gaya.


Example 7 — Cell G: aerospace word problem

Forecast: dono features high hain positive weights ke saath → high risk expected. Guess: flagged.

  1. English ko mein translate karo. . Yeh step kyun? Har standardized feature apne weight se multiply hokar risk mein contribute karta hai; bias baseline threshold set karta hai.
  2. Probability. . Yeh step kyun? Risk score ko ek interpretable failure probability mein convert karta hai — .
  3. Decision. inspection ke liye flag karo. Yeh step kyun? Operational threshold apply karta hai; yahan safety jeetti hai.

Verify karo: ✓, decision "high hours + high vibration = risky" ke saath consistent ✓. Failure probability plug karo: , ✓.


Example 8 — Cell H: exam twist (odds & log-odds, koi sigmoid table nahi)

Forecast: parent note ne dikhaya tha . Toh odds , aur mein add karna odds ko multiply karta hai. Guess: doubling-ish.

  1. Log-odds se odds. . Yeh step kyun? By definition , toh exponentiate karne se log undo ho jaata hai. Odds cloudy ke favour mein.
  2. Odds se probability. . Yeh step kyun? rearrange karne par milta hai — yeh ke equal hai, lekin humein koi sigmoid table nahi chahiye tha.
  3. ka odds par effect. New odds . Yeh step kyun? Yahi log-odds ke additive hone ka poora point hai: mein ek fixed bump odds ko ek constant factor se multiply karta hai, chahe aap kahin se bhi shuru karo.

Verify karo: ✓ — step 2 se exactly match. Odds-multiplier ✓. Yeh odds interpretation hai jo coefficients ko readable banati hai: weight matlab "har unit odds ko se multiply karta hai."


Recall Sab cells mein quick self-test

Kaun se cell mein exactly hota hai? ::: Cell C, boundary . Gradient vanishingly small kab hota hai? ::: Cell D — saturated tail AUR already correct. mein add karne se odds ka kya hota hai? ::: Unhe se multiply karta hai (Cell H). Ek confident galat prediction phir bhi fast kyun seekhti hai? ::: Uski gradient magnitude 1 ke paas hai, maximum. One-line gradient formula? ::: examples par average kiya hua.