5.3.13 · AI-ML › MLOps & Deployment
Intuition Ek-sentence ka idea
Ek model duniya ke ek snapshot pe train hota hai. Duniya chalti rehti hai. Drift detection woh alarm system hai jo batata hai kab duniya itni badal gayi hai ki tumhare model ki predictions pe ab bharosa nahi kiya ja sakta — pehle hi, jab business metrics quietly kharaab ho rahi hoti hain.
Intuition Yeh kyun matter karta hai
ML models assume karte hain ki future past jaisa dikhega. Formally, training assume karti hai ki joint distribution P ( X , Y ) stationary hai. Reality mein, user behaviour, prices, sensors, fraud tactics, aur language sab evolve karte hain. Jab P ( X , Y ) deployment ke baad change ho jaata hai, tumhara frozen model aaj ke questions ka jawab kal ke exam se de raha hota hai.
Hum joint distribution ko chain rule se split kar sakte hain:
P ( X , Y ) = P ( Y ∣ X ) P ( X )
Yeh factorization poori conceptual key hai — neeche jo bhi hai woh isi sawaal se nikalti hai ki kaun sa factor badla .
Definition Drift ke do prakar
Data drift (covariate shift) : P ( X ) badalta hai lekin P ( Y ∣ X ) same rehta hai. Inputs alag dikhte hain; input→output rule intact hai.
Concept drift : P ( Y ∣ X ) badalta hai. Rule khud badal gaya — same input ab ek alag label imply karta hai.
Worked example Difference feel karo (loan default model)
Data drift: Ek marketing campaign younger applicants laati hai. Age distribution P ( X ) shift ho jaata hai. Lekin income I wala 25-year-old pehle jaisi hi rate pe default karta hai → P ( Y ∣ X ) unchanged.
Concept drift: Recession aa jaati hai. Ab wahi 25-year-old income I ke saath bahut zyada default karta hai. P ( Y ∣ X ) badal gaya → features se default tak ka mapping toot gaya.
Yeh step kyun? Kyunki fix alag hoti hai: data drift ko reweighting/monitoring ki zaroorat ho sakti hai; concept drift ko usually naye labels ke saath retraining chahiye.
Tum P directly kabhi observe nahi karte — sirf samples . Toh detection = ek reference window (training/recent-good) ko ek current window (live) se compare karna aur poochna "kya yeh dono samples ek hi distribution se hain?"
Hum reference feature distribution P r e f ( X ) ko current P c u r ( X ) se compare karte hain.
P ( Y ∣ X ) ka change dekhne ke liye tumhe labels Y chahiye. Concept drift time ke saath rising prediction error ke roop mein dikhta hai, even jab inputs normal dikhte hain.
Worked example Ek single numeric feature, 3 bins
Reference proportions r = [ 0.5 , 0.3 , 0.2 ] , current c = [ 0.3 , 0.3 , 0.4 ] .
PSI = ( 0.3 − 0.5 ) ln 0.5 0.3 + ( 0.3 − 0.3 ) ln 0.3 0.3 + ( 0.4 − 0.2 ) ln 0.2 0.4
Term 1: ( − 0.2 ) ln ( 0.6 ) = ( − 0.2 ) ( − 0.5108 ) = 0.1022 . Positive kyun? dono factors negative hain.
Term 2: 0 × ln 1 = 0 . Kyun? unchanged bin kuch contribute nahi karta.
Term 3: ( 0.2 ) ln ( 2 ) = ( 0.2 ) ( 0.6931 ) = 0.1386 .
Total PSI ≈ 0.241 → moderate-to-significant drift, investigate karo.
Worked example KS statistic haath se (tiny example)
Reference sorted = [ 1 , 2 , 3 , 4 ] , current = [ 3 , 4 , 5 , 6 ] .
x = 3 pe: F r e f = 3/4 = 0.75 , F c u r = 1/4 = 0.25 → gap 0.5 . Yahi max hai, toh D = 0.5 — bada gap, distributions clearly right shift ho gayi hain. x = 3 kyun? Yahi woh jagah hai jahan dono step-functions sabse zyada separated hain.
Common mistake "Data drift ka matlab hamesha retrain karo."
Kyun sahi lagta hai: koi bhi alarm "kuch bada karo" jaisa feel karta hai. Pech: pure covariate shift (P ( X ) move kiya, P ( Y ∣ X ) fixed) accuracy ko bilkul hurt nahi kar sakta agar model already naye input region pe generalize karta ho. Fix: costly retrain trigger karne se pehle model performance / concept drift bhi check karo.
Common mistake "Labels nahi hain? Toh concept drift detect nahi kar sakta, ignore karta hoon."
Kyun sahi lagta hai: DDM ko Y chahiye. Pech: tum proxy signals use kar sakte ho — prediction-confidence distribution shifts, output-class ratio changes, ya delayed/partial labels. Fix: prediction distributions monitor karo aur delayed-label evaluation set up karo.
Common mistake "Badi window = zyada reliable detection."
Kyun sahi lagta hai: zyada data = kam noise. Pech: bahut badi current window us moment ko average over kar leti hai jab drift shuru hua, alarm ko delay aur dilute kar ke. Fix: sliding/adaptive windows use karo (e.g. ADWIN) jo change detect hone pe shrink ho jaayein.
Common mistake "Statistical significance = practical importance."
Kyun sahi lagta hai: chhota p-value decisive lagta hai. Pech: millions of rows ke saath KS/chi-square bahut chhoti shifts flag kar deta hai. Fix: p-values ke saath effect sizes (PSI magnitude) aur business thresholds bhi pairo karo.
Recall Scroll karne se pehle khud test karo
P ( X , Y ) ka kaun sa factor data drift vs concept drift mein badalta hai?
PSI hamesha non-negative kyun hota hai?
KS statistic ka "sup" geometrically kya represent karta hai?
DDM 3σ rule kyun use karta hai?
Bina (kuch) labels ke concept drift detect kyun nahi kar sakte?
Recall Feynman: ek 12-year-old ko explain karo
Imagine karo tumne ball pakadna seekha apne dost ko throw karte dekhke. Data drift tab hota hai jab ek alag dost throw karne lagta hai — balls naye angles se aate hain (inputs badal gaye), lekin ball abhi bhi usi tarah udhti hai, toh tum phir bhi pakad sakte ho. Concept drift zyada spooky hai: physics ke rules khud change ho jaate hain — wahi throw ab alag curve karti hai, toh tumhari purani pakadne ki habit fail ho jaati hai. Drift detectors ek coach ki tarah hain jo constantly poochta hai "kya yeh throws abhi bhi waise hi hain jaise tumne practice kiye?" (data drift) aur "kya tum abhi bhi unhe pakad rahe ho?" (concept drift). Agar kisi bhi sawaal ka jawab "nahi" hai, toh phir se practice karne ka time hai.
#flashcards/ai-ml
Chain rule factorization jo drift define karne ke liye use hoti hai P ( X , Y ) = P ( Y ∣ X ) P ( X ) ; data drift P ( X ) badalta hai, concept drift P ( Y ∣ X ) badalta hai.
Data drift (covariate shift) ki definition P ( X ) badalta hai jabki P ( Y ∣ X ) fixed rehta hai — inputs shift hote hain lekin input→output rule intact rehta hai.
Concept drift ki definition P ( Y ∣ X ) badalta hai — same input ab different labels pe map karta hai; underlying rule badal gaya.
PSI formula PSI = ∑ i ( c i − r i ) ln r i c i binned proportions pe; symmetrized KL.
PSI hamesha ≥ 0 kyun hota hai sign ( c i − r i ) = sign ( ln r i c i ) , toh har term non-negative hai (equivalently yeh ek symmetrized KL divergence hai).
PSI thresholds <0.1 koi drift nahi, 0.1–0.25 moderate, >0.25 significant.
KL divergence formula D K L ( P ∥ Q ) = ∑ i P i ln Q i P i , Jensen se hamesha ≥0, =0 tabhi jab P=Q.
KS statistic D = sup x ∣ F r e f ( x ) − F c u r ( x ) ∣ , empirical CDFs ke beech maximum vertical gap.
Categorical feature drift ke liye test Chi-square: χ 2 = ∑ i ( O i − E i ) 2 / E i observed vs reference-expected counts compare karta hai.
DDM warning/drift rule warning
p i + s i ≥ p min + 2 s min pe, drift
≥ p min + 3 s min pe, jahaan
s i = p i ( 1 − p i ) / n i .
Concept drift ko labels kyun chahiye Yeh P ( Y ∣ X ) mein change hai; rule toot-ta tabhi dikh sakta hai jab predictions ko true Y se compare karo (ya proxies jaise confidence/output ratios se).
"Badi current window" detection kyun hurt karti hai Badi window change point ke upar average kar leti hai, drift signal ko delay aur dilute karti hai; adaptive/sliding windows (ADWIN) use karo.
deploy ke baad toot jaata hai
P of Y given X badalta hai
compare karke detect karo
Stationary assumption P of X,Y
P of X,Y = P of Y given X times P of X
Data drift / covariate shift
Fix: naye labels se retrain
Reference vs current window
Population Stability Index