5.6.2 · D4 · HinglishMachine Learning (Aerospace Applications)

ExercisesLogistic regression — sigmoid, cross-entropy loss

2,525 words11 min read↑ Read in English

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

Yeh page parent topic ke liye ek self-test ladder hai. Har problem pichli wali pe build karti hai. Har ek ko solve karne ki koshish karo solution kholne se pehle. Neeche jo bhi numbers dikhe hain, woh sab machine-checked hain.

Shuru karne se pehle, ek common picture. Is page ki har cheez sigmoid curve pe rehti hai: ek smooth "S" jo kisi bhi real number (logit, raw score ) ko horizontal axis pe leti hai aur ek probability between 0 aur 1 vertical axis pe return karti hai.

Figure — Logistic regression — sigmoid, cross-entropy loss

Is figure ko dimag mein rakho: centre ke left → probability 0.5 se neeche → "class 0"; centre ke right → 0.5 se upar → "class 1"; bilkul centre () → exactly 0.5.


Level 1 — Recognition

Recall

Solution 1.1 Kya karte hain: ko mein plug karo. Kaise dikhta hai: S-curve ka bilkul middle — woh point jo figure mein hai jahan curve dotted 0.5 line cross karti hai. Decision: , toh hum class 1 predict karte hain (boundary hamare convention ke hisaab se inclusive hai).

Recall

Solution 1.2

  • = training examples ki woh number jis par hum average karte hain. Average karna (sirf sum nahi) matlab yeh hai ki loss ka size sirf isliye nahi badhega kyunki humne zyada data collect kiya.
  • = example ka true label, jo ya toh hai ya (beech mein kabhi nahi).
  • = model ki predicted probability ki example class 1 hai, ek number mein.
  • Minus sign "log-likelihood jo hum maximise karna chahte hain" ko "loss jo hum minimise karna chahte hain" mein flip karta hai. Optimisers convention ke hisaab se neeche jaate hain, toh hum unhe kuch aisa dete hain jo fit improve hone par chhota hota jaata hai.
Recall

Fill-in check as ::: as ::: Woh value of jahan exactly ke barabar hai :::


Level 2 — Application

Recall

Solution 2.1 Step 1 — logit (dot product plus bias). Dot product kyun? Kyunki woh single number hai jo kehta hai "features, importance se weight karke, class 1 ki taraf kitna push kar rahe hain." Step 2 — squash karo. Kaise dikhta hai: sigmoid figure mein centre ke left mein hai, toh hum 0.5 se neeche lagte hain. Decision: class 0.

Recall

Solution 2.2 Kya karte hain: use karo. ke saath doosra term khatam ho jaata hai (), sirf bachta hai. Itna bada kyun? Truth class 1 tha lekin model ne sirf probability di — ek confident galat lean. Cross-entropy isko punish karta hai. (Yahan logarithms natural logs hain, base , jo sigmoid ke andar wale se match karta hai.)

Recall

Solution 2.3 Step 1 — error term. . Negative kyunki prediction bahut kam thi. Step 2 — per-weight gradients. Step 3 — descend (): Kaise dikhta hai: dono weights is tarah move kiye ki agली prediction raise ho — exactly waही jo hum chahte hain kyunki truth class 1 hai. Yeh Gradient Descent ka ek step hai.


Level 3 — Analysis

Recall

Solution 3.1 Compute karo: har feature ke liye. Kyun important hai: update weight ko unchanged chhod deta hai. Ek perfectly-classified point aage ki learning mein kuch contribute nahi karta — algorithm pehle se "use kar chuka hai" jo woh point sikha sakta tha. Yeh minimum ka geometric meaning hai: koi slope nahi, koi motion nahi. Subtle baat: ke liye chahiye, jo finite weights se reachable nahi hai. Toh practice mein gradient zero ki taraf shrink hota hai lekin truly kabhi hit nahi karta — model weights ko badhata rehta hai. Woh endless drift exactly woh problem hai jiske liye Regularization (L1, L2) exist karta hai.

Recall

Solution 3.2 Losses: Error terms: Padhna: confidently-wrong case (b) mein bahut bada loss aur bada-magnitude error term dono hain, toh yeh zyada strong corrective push produce karta hai. Cross-entropy ka squared error ke upar yahi poora point hai: confident hona aur galat hona bahut zyada hurt karta hai, jo model ko us bure state se jaldi bahar kheenchta hai. Ek learner jo sirf unsure hai use gentle nudge milta hai.


Level 4 — Synthesis

Recall

Solution 4.1 Forward pass, point 1 (): Forward pass, point 2 (): Error terms: ; . Averaged gradients (): Update: Kaise dikhta hai / sanity: point 1 (ek non-failure jise model ne over-predict kiya) ko neeche push karta hai; point 2 (ek failure jise usne thoda under-predict kiya) ko upar push karta hai. Woh par nearly cancel ho jaate hain, lekin dono ko lower karne par agree karte hain — poori S-curve ko rightward shift karte hue taaki ke scores "fail hone ki kam likelihood" padhein. Ek coherent, honest step.

Recall

Solution 4.2 Key link: . Toh boundary wahan hai jahan logit exactly zero hai — yahi reason hai ki logistic regression ki boundary hamesha ek straight line (ya hyperplane) hoti hai, seedha Linear Regression se inherited. set karo: Description: slope aur intercept wali ek straight line. Ek taraf (class 1 predict karo), doosri taraf (class 0 predict karo). Sigmoid sirf decide karta hai ki us line ko cross karte waqt probability kitni tez turn karti hai, nahi ki line kahan hai.


Level 5 — Mastery

Recall

Solution 5.1 Definition se shuru karo aur substitute karo: Top aur bottom ko se multiply karo: Interpretation: score par "not class 1" ki probability, flipped score par "class 1" ki probability ke barabar hai. Curve mein ke baare mein point symmetry hai. Exactly yahi reason hai ki ek two-class problem ko sirf ek sigmoid chahiye: model karna automatically pin kar deta hai. Jab do se zyada classes hoon toh yeh freebie khatam ho jaati hai aur tumhe Softmax Regression ki taraf move karna padta hai.

Recall

Solution 5.2 First derivative — do known facts chain karo aur ( ke saath): Second derivative differentiate karo; constant khatam ho jaata hai aur : Sign: , toh dono factors strictly positive hain, toh second derivative har jagah strictly positive hai. Conclusion: ek function jiska har jagah positive second derivative ho woh convex hai — yeh ek bowl ki tarah upar curve karta hai, ek single global minimum guarantee karta hai bina kisi false valleys ke jo Gradient Descent ko trap kar sakein. Yeh rigorous reason hai ki humne squared error kyun chhhoda, aur yeh parent note mein Maximum Likelihood Estimation derivation ka promised payoff hai.

Figure — Logistic regression — sigmoid, cross-entropy loss
Recall

Solution 5.3 . First derivative: (negative: par loss abhi bhi decrease hoti hai jab hum ko correct class 1 ki taraf push karte hain — good). Second derivative: (positive: bowl upar curve karta hai, is point par convexity confirm karta hai).

Recall

Poori page ke liye Mnemonic Woh ek identity jo yahan har exercise unlock karti hai ::: gradient tak collapse ho jaata hai — "prediction minus truth, feature se scale karke."


Aage kahan jaayein