Random variables (discrete and continuous)
1.3.5· AI-ML › Probability & Statistics
Ek random variable ek function hota hai jo kisi random experiment ke outcomes ko real numbers pe map karta hai. Yeh messy real world (coin flips, pixel intensities, user clicks) aur clean mathematical world ke beech ka bridge hai, jahan hum probabilities aur expectations calculate kar sakte hain.
Why Random Variables Matter in ML
Machine learning mein, almost sab kuch ek random variable hai:
- Features: pixel values, word counts, sensor readings
- Labels: class assignments, regression targets
- Model parameters: training ke dauran sample kiye gaye weights
- Predictions: uncertainty ke saath outputs
RVs ko samajhne se aap:
- Data aur predictions mein uncertainty quantify kar sakte ho
- Aise loss functions design kar sakte ho jo aapke data distribution se match karein
- Complex distributions se sample kar sakte ho (GANs, VAEs)
- Model behavior ke baare mein probabilistically reason kar sakte ho
The Core Intuition
Example: Ek die roll karo. Outcome space hai {⚀, ⚁, ⚂, ⚃, ⚄, ⚅}. Define karo = "dots ki sankhya". Tab map karta hai ⚂ → 3, ⚅ → 6, wagera. random variable hai, outcome "3" khud nahi.
Discrete Random Variables
Probability Mass Function (PMF)
Probability mass function woh probability deta hai ki exactly value leta hai.
Requirements (yeh ensure karte hain ki yeh ek valid probability distribution hai):
- Non-negativity: sabhi ke liye
- Normalization: (saari probabilities ka sum 1 hota hai)
Yeh rules kyun? Non-negativity: probabilities negative nahi ho sakti. Normalization: kuch na kuch zaroor hona chahiye, isliye total probability = 1.

First principles se:
- Socho experiment baar repeat ho raha hai, values milti hain
- Sample average hai
- Identical values group karo: agar baar aata hai, average =
- Jab , (frequency probability pe converge hoti hai)
- Isliye:
Har term se weight kyun hota hai? Zyada probable values long run mein zyada baar aati hain, isliye woh average mein zyada contribute karti hain.
PMF:
Compact form: for
Yeh form kyun? Jab : . Jab : . Yeh dono cases ek expression mein likhne ka ek clever tarika hai.
Expected value:
kyun? Agar ke saath 100 baar flip karo, toh expect karte ho lagbhag 30 heads. Average = 30/100 = 0.3 = .
ML Application: Binary classification labels (spam/not spam). Logistic regression output karta hai, jo literally hai Bernoulli RV "kya yeh example class 1 hai?" ke liye.
PMF ki Derivation:
- Kisi bhi specific sequence ki probability jisme heads hain: (heads baar prob ke saath aate hain, tails baar prob ke saath)
- Aise sequences ki sankhya ( flips mein heads ke orderings):
- Multiplication kyun? Har specific sequence ki prob hai, aur mutually exclusive sequences hain
Expected value:
Kyun? Har flip expected value contribute karta hai. independent flips ke saath: .
ML Application: Neural networks mein Dropout. Har neuron independently probability ke saath "survive" karta hai. Ek layer mein active neurons ki sankhya ~ Binomial.
Continuous Random Variables
Discrete se key difference: kisi bhi specific ke liye. Kyun? Infinitely many points, probability infinitely thin spread ho jaati hai. Hume intervals ke baare mein poochna hoga: .
Probability Density Function (PDF)
Probability density function ek probability NAHI hai—yeh ek density hai. Ise socho "probability per unit length" ki tarah.
Requirements:
- Non-negativity: sabhi ke liye
- Normalization:
Integration kyun? Tum interval par infinitesimal probabilities ko sum kar rahe ho. "" density ko probability mein convert karta hai: ke units hain "probability per unit", ke units hain "unit", product ke units hain "probability".
Geometric intuition: Probability = curve ke neeche aur ke beech ka area.
kyun? Discrete jaisi hi logic: har value ko uski "probability" se weight karo (yahan, density × ).
PDF:
Yeh form kyun? mein constant density (equally likely). 1 tak integrate hona chahiye:
Expected value:
Simplify karo: , isliye:
Midpoint kyun? Symmetry. Dono taraf equally likely, isliye average center hota hai.
ML Application: Neural networks mein weight initialization aksar uniform distributions use karta hai (jaise Xavier/Glorot initialization se sample karta hai).
PDF:
Parameters: (mean, location), (variance, spread)
Yeh functional form kyun? (Mean/variance constraints ke under maximum entropy se brief derivation—full proof complex hai, lekin intuition):
- Hum "sabse random" distribution chahte hain sirf mean aur variance ki knowledge diye gaye
- , subject to entropy maximize karna yeh exponential-quadratic form deta hai
- ensure karta hai ki
shape kyun? Yeh probability ko mean () ke paas concentrate karta hai, tails quickly khatam ho jaate hain. Exponent mein quadratic smoothness aur "bell" shape ensure karta hai.
Expected value: ke around symmetry se, .
ML Applications:
- Data mein Gaussian noise: , jahan
- Weight initialization (jaise He initialization: )
- Gaussian processes, variational autoencoders (VAE latent space)
- Linear regression assume karta hai
Cumulative Distribution Function (CDF)
Discrete aur continuous dono RVs ka CDF hota hai .
Discrete RV ke liye: (PMF values ko sum karo)
Continuous RV ke liye: (PDF integrate karo)
Useful kyun?
- CDFs hamesha exist karte hain (PMFs/PDFs mixed distributions ke liye nahi hote)
- Probabilities compute karna aasaan:
- PDF se relationship: (PDF, CDF ka derivative hai)
ML Application: Percentile-based metrics, quantile regression, inverse transform sampling (kisi bhi distribution se samples generate karo uniform random numbers par apply karke).
Common Mistakes
Kyun sahi lagta hai: Hum discrete RVs se ke aadat hain.
Fix: density hai, probability nahi. Units: "probability per unit" hai. matlab "locally, probability 2 units per unit length ki speed se accumulate ho rahi hai". Actual probability: (jo chhote ke liye chhota hai).
Check: ke liye, . Lekin ✓
Kyun sahi lagta hai: Dono weighted averages use karte hain.
Fix:
- Discrete:
E_X = sum(x * P(x) for x in values) - Continuous:
E_X = integrate(x * f(x), x, -inf, inf)yaE_X = np.mean(samples)samples ke liye
NumPy mein, agar tumhare paas continuous RV ke samples hain, toh np.mean(samples) use karo, na ki sum(x * count(x)) (jo discrete assume karta hai).
Kyun sahi lagta hai: Hum thermometers par "20°C" measure karte hain.
Fix: Real measurements finite precision hoti hai. Tumhara thermometer "20°C" padhta hai = "19.5 aur 20.5°C ke beech" (ek interval). Continuous RVs ke liye, hamesha intervals ke baare mein poochho: .
Active Recall
Recall Random Variables ko ek 12-Saal ke Bacche ko Explain Karo
Socho tumhare paas ek magic box hai jo games khelta hai. Kabhi woh dice roll karta hai, kabhi wheel spin karta hai. Har baar jab tum box use karte ho, woh tumhe ek number deta hai. Woh number random hota hai (pehle se pata nahi hota), lekin woh rules follow karta hai.
Ek random variable us number ka nickname jaisa hai. Hum ise kehte hain. Agar hum die roll karein, 1, 2, 3, 4, 5, ya 6 ho sakta hai (sirf yahi numbers, beech mein kuch nahi). Yeh discrete hai—jaise candies ginana.
Lekin agar hum ek wheel spin karein jo 0 se 100 ke beech kahin bhi land kar sakta hai, 23.7145... ya 99.001... ya beech mein koi bhi number ho sakta hai. Yeh continuous hai—jaise cup mein kitna paani hai measure karna.
Discrete ke liye, hum keh sakte hain "exactly 3 milne ki probability hai..." (jaise fair die ke liye ). Continuous ke liye, hum "exactly 23.7145" nahi keh sakte kyunki infinite possibilities hain—yeh aise hai jaise beach par ek specific ret ka daana dhundna. Isliye hum poochte hain "X ke 20 aur 30 ke beech hone ki probability kya hai?" aur us range mein probabilities add karte hain (integration).
Cool part yeh hai: AI mein almost sab kuch ek random variable hai—image mein kaunsa digit hai, agla word kya aayega, email spam hai ya nahi. RVs samajhna matlab AI uncertainty kaise handle karta hai yeh samajhna hai.
Memory Aids
- Discrete = Distinct, Discrete math (integers)
- PMF = Probability Mass (mass points par baith jaati hai)
- PDF = Probability Density (fluid ki tarah spread)
Alphabet trick:
- PMF Sum use karta hai ()
- PDF Integral use karta hai ()
- "S comes before I" → discrete ke liye sum use karo, continuous ke liye integral
Connections
- Probability Space – random variables sample spaces par measurable functions hote hain
- Expectation and Variance – random variables ke moments, higher-order statistics
- Joint and Conditional Distributions – multivariate RVs, dependence structure
- Central Limit Theorem – sums Gaussian pe converge kyun karte hain
- Maximum Likelihood Estimation – data pe distributions fit karna (, , find karna)
- Bernoulli and Categorical Distributions – classification labels discrete RVs ki tarah
- Gaussian Distribution – regression noise, VAE latents ke liye continuous RV
- Sampling Methods – RV samples generate karna (inverse transform, rejection sampling)
- Information Theory – RV distributions ki entropy
#flashcards/ai-ml
Random variable kya hota hai? :: Ek function jo random experiment ke outcomes ko real numbers pe map karta hai. Yeh real-world randomness aur mathematical probability ke beech ka bridge hai.
Discrete aur continuous random variable mein kya fark hai?
PMF kya hai aur uski do requirements kya hain?
PDF kya hai aur probability kyun nahi hai?
Continuous random variables ke liye kyun hota hai?
Discrete RV ke liye expected value formula?
Continuous RV ke liye expected value formula? :: . Density par weighted integral.