Log-loss (logarithmic loss, cross-entropy loss) measure karta hai ki predicted probabilities true outcomes se kitni acchi tarah match karti hain. Calibration measure karta hai ki predicted probabilities true frequencies ko reflect karti hain ya nahi: agar aap 100 events ke liye "70% confident" kehte hain, toh roughly 70 hone chahiye.
Yeh kyun important hai: Ek model ki accuracy high ho sakti hai lekin probabilities bilkul bekar ho sakti hain. Log-loss + calibration batate hain ki aapki uncertainties trustworthy hain ya nahi—yeh medical diagnosis, finance, aur uncertainty ke saath kisi bhi decision ke liye critical hai.
Aapke paas true label y∈{0,1} hai aur class 1 ke liye predicted probability p^∈[0,1] hai.
Step 1: Likelihood define karo.
Agar y=1 hai, toh aapne jo probability assign ki woh p^ thi.
Agar y=0 hai, toh aapne jo probability assign ki woh 1−p^ thi.
Combined:
P(data∣model)=p^y⋅(1−p^)1−y
Yeh step kyun? Yeh Bernoulli likelihood hai—aapki prediction given outcome y observe karne ki basic probability.
True label: one-hot vector y=[y1,y2,…,yK] jahan exactly ek yk=1 hai.
Predicted probabilities: p^=[p^1,…,p^K] with ∑p^k=1.
Derivation:
True class observe karne ki likelihood ∏k=1Kp^kyk hai (sirf true class contribute karta hai kyunki baaki ke liye yk=0 hai).
Negative log-likelihood:
Yeh step kyun?k par sum ek single term (true class) par collapse ho jaata hai kyunki saare incorrect classes ke liye yi,k=0 hota hai.
Step 1: Predictions bin karo.[0,1] ko M bins mein divide karo (typically 10-20): B1,B2,…,BM.
Step 2: Har bin ke liye accuracy aur confidence compute karo.
Bin Bm ke liye:
Average predicted probability: conf(Bm)=∣Bm∣1∑i∈Bmp^i
Actual accuracy: acc(Bm)=∣Bm∣1∑i∈Bmyi
Step 3: Bin size se weight karo aur average karo.
Yeh step kyun? Hum bin size se weight karte hain kyunki 2 samples waale bin ko 200 samples waale bin par dominate nahi karna chahiye. Absolute difference ∣acc−conf∣ calibration gap hai.
Problem: Neural net outputs z (logits). Softmax σ(z) overconfident hai.
Solution: Temperature T add karo:
p^k=∑jezj/Tezk/T
T kaise find karein: Model weights freeze karo. NLL ya ECE minimize karne ke liye validation set par T tune karo. Typically T∈[1,5].
Yeh kyun kaam karta hai: Logits ko T>1 se divide karna distribution ko "soften" karta hai—probabilities 0 aur 1 se door uniform ki taraf move karti hain. Yeh retraining ke bina overconfidence correct karta hai.
Scores se probabilities tak ek piecewise-constant, monotonically increasing function fit karo. Flexible hai lekin chhote validation sets par overfit ho sakta hai.
Socho tum ek weather forecaster ho. Tum kehte ho "70% chance of rain." Agar tum yeh 100 baar kehte ho, toh roughly 70 baar baarish honi chahiye. Agar sirf 50 baar baarish hoti hai, toh tumhari probabilities kharaab hain—tum overconfident ho. Calibration check karta hai ki tumhare percentages honest hain ya nahi.
Ab socho, jab bhi tum galat hote ho, tumhare points kate jaate hain. Lekin sabhi mistakes equal nahi hain. Agar tum "99% no rain" kehte ho aur baarish ho jaati hai, toh tum BAHUT saare points khote ho—tum super confident the aur super galat the. Agar tumne "60% no rain" kaha hota aur baarish ho jaati, toh kam points kate kyunki tum sure nahi the. Yahi log-loss hai: yeh cocky mistakes ko humble ones se bahut zyada punish karta hai.
Kyun? Kyunki real life mein (medicine, driving, investing), galat hone par overconfident hona dangerous hai. Log-loss tumhare AI ko yeh admit karana sakta hai jab woh unsure ho, aur calibration sure karti hai ki uska "main 80% sure hoon" actually kuch maayane rakhta hai.
L=−N1∑i=1N∑k=1Kyi,klogp^i,k jahan yi one-hot hai, p^i sum hokar 1 deta hai. Equivalent hai −N1∑ilogp^i,ci (true class).
Ek model ke calibrated hone ka matlab kya hai?
Ek model calibrated hota hai agar, un sabhi predictions mein jinki confidence p hai, true positive rate p ho. Jaise, un sabhi "70% confident" predictions mein se, 70% sahi hone chahiye. Perfect calibration: observed frequency = predicted probability.
Expected Calibration Error (ECE) formula
ECE=∑m=1MN∣Bm∣∣acc(Bm)−conf(Bm)∣ jahan Bm predictions ke bins hain, acc bin mein actual accuracy hai, conf average predicted probability hai. Range: [0,1].
Ek model ki low log-loss lekin poor calibration kyun ho sakti hai?
Log-loss training distribution ke saath fit measure karta hai. Ek model training data par log-loss minimize kar sakta hai lekin test/OOD data par overconfident ho sakta hai, ya poorly extrapolate kar sakta hai. Hamesha calibration alag se ECE ya reliability diagrams se measure karo.
Softmax outputs automatically calibrated probabilities kyun nahi hote?
Softmax [0,1] mein values produce karta hai jo 1 sum hoti hain, lekin logits ka scale arbitrary hai. Neural nets classify karne ke liye train hote hain (loss minimize karna), calibrated hone ke liye nahi. Woh often overconfident scores output karte hain. Fix: temperature scaling.
Temperature scaling kya hai aur yeh calibration kaise fix karta hai?
Temperature scaling softmax(z) ko softmax(z/T) se replace karta hai jahan T>1 ko validation data par tune kiya jaata hai. Logits ko T se divide karna distribution ko "soften" karta hai, probabilities ko extremes (0 ya 1) se door le jaata hai, retraining ke bina overconfidence correct karta hai.
Log-loss vs. accuracy: kaun zyada informative hai?
Log-loss zyada informative hai kyunki yeh probability quality evaluate karta hai, sirf binary decisions nahi. Ek model jo sabhi positives ke liye 0.51 predict karta hai uski accuracy 100% hai lekin probabilities bekar hain. Log-loss high hoga, problem reveal karta hua.
Log-loss confident wrong predictions ko kaise penalize karta hai?
Log-loss −log(p^) hai jab sahi, −log(1−p^) hai jab galat. Jaise p^→0 ek true positive ke liye, −log(p^)→∞. Ek confident wrong prediction (jaise true class ke liye 0.01) massive loss (~4.6) deta hai, jabki ek timid wrong prediction (0.4) chhota loss (~0.92) deta hai. Exponential penalty.
Reliability diagram kya hota hai?
Predicted confidence (x-axis) vs. observed accuracy (y-axis) ka bins mein plot. Perfect calibration = diagonal line y=x. Diagonal se neeche curve = overconfident. Upar = underconfident.
Log-loss ko "cross-entropy" kyun kehte hain?
Cross-entropy H(p,q)=−∑p(x)logq(x) woh average bits measure karta hai jo distribution p ke data ko q ke liye optimized code use karke encode karne mein lagte hain. Classification ke liye, p one-hot true label hai, q predicted distribution hai. Binary log-loss exactly H(p,q) hai Bernoulli distributions ke liye.