Foundations of Data Science 📂 Probability · 3 of 5 176 min read

Random Variables Explained: Discrete vs Continuous

A comprehensive, story-driven tutorial on random variables covering the discrete vs continuous split, Probability Mass Function (PMF) with a binomial defective phone worked example and bar chart, Probability Density Function (PDF) with uniform bus arrival and normal height examples, Cumulative Distribution Function (CDF) with staircase and S-curve diagrams, five custom inline SVGs, common distribution tables, ML applications, and 12 golden rules.

🌐
SectionSection第 01 节

Numbers That Carry Uncertainty 🎲अनिश्चितता वाली संख्याएँ 🎲带着不确定性的数字 🎲

You are about to roll a die. You cannot say which face will show, but you know it will be some number. Call that number X. X is not fixed in advance — its value depends on the outcome of a random experiment. That is a random variable.

आप एक die फेंकने वाले हैं। आप नहीं बता सकते कि कौन-सा अंक आएगा, पर इतना पता है कि कोई संख्या आएगी। उस संख्या को X कहें। X पहले से तय नहीं — इसका मान एक random प्रयोग के नतीजे पर निर्भर है। यही random variable है।

你准备掷一颗骰子。你说不准会出现哪一面,但知道一定是某个数。把这个数记作 X。X 事先并不确定 —— 它的值取决于随机试验的结果。这就是随机变量。

Random variables connect probability (sample spaces, events) to real data. Every column you analyse — customer age, transaction amount, exam score, daily rainfall — can be seen as values of a random variable. This tutorial covers what a random variable is, the discrete/continuous split, and the three functions that describe its behaviour: the PMF, PDF and CDF.

Random variables, probability (sample spaces, events) को असली data से जोड़ते हैं। आप जो भी column analyse करते हैं — ग्राहक की उम्र, लेन-देन की राशि, exam score, रोज़ की बारिश — उसे random variable के मानों की तरह देखा जा सकता है। यह tutorial बताता है कि random variable क्या है, discrete/continuous का बँटवारा, और इसके व्यवहार को बताने वाले तीन functions: PMF, PDF और CDF।

随机变量把概率(样本空间、事件)与真实数据连接起来。你分析的每一列 —— 客户年龄、交易金额、考试分数、每日降雨量 —— 都可以看作某个随机变量的取值。本教程介绍随机变量是什么、离散与连续的区别,以及描述其行为的三个函数:PMF、PDF 和 CDF。

💡
Notation ConventionNotation का नियम符号约定

Random variables use capital letters (X, Y, Z). The values they take use small letters (x, y, z). So "X = 3" means the random variable X took the value 3 in one trial, and P(X = 3) is the chance of that happening.

Random variables के लिए बड़े अक्षर (X, Y, Z) और उनके मानों के लिए छोटे अक्षर (x, y, z)। तो "X = 3" का मतलब है random variable X ने एक trial में मान 3 लिया, और P(X = 3) इसके होने का chance है।

随机变量用大写字母(X、Y、Z),它们的取值用小写字母(x、y、z)。所以“X = 3”表示随机变量 X 在一次试验中取值 3,P(X = 3) 是这件事发生的概率。


SectionSection第 02 节

What Is a Random Variable? 🔢Random Variable क्या है? 🔢什么是随机变量?🔢

The Story: The Call Centreकहानी: Call Centre故事:呼叫中心

Priya manages a call centre. Each hour she counts the complaints: some hours 0, some 12, now and then 30. She cannot predict the exact number, but she can describe the pattern. She defines X = "number of complaints in an hour". X is a random variable.

Priya एक call centre चलाती है। हर घंटे वह शिकायतें गिनती है: कभी 0, कभी 12, कभी-कभार 30। वह सही संख्या का अनुमान नहीं लगा सकती, पर pattern बता सकती है। वह X = "एक घंटे में शिकायतों की संख्या" तय करती है। X एक random variable है।

Priya 管理一个呼叫中心。她每小时统计投诉数:有时 0,有时 12,偶尔 30。她无法预测确切数字,但能描述规律。她定义 X =“每小时的投诉数”。X 就是一个随机变量。

Her colleague Arjun measures how long each call lasts: 2.3 minutes, 7.81 minutes, 14.002 minutes… Any positive number is possible. He defines Y = "call duration in minutes". Y is also a random variable, but of a different type.

उसका साथी Arjun हर call की अवधि मापता है: 2.3 मिनट, 7.81 मिनट, 14.002 मिनट… कोई भी positive संख्या संभव है। वह Y = "call की अवधि मिनट में" तय करता है। Y भी random variable है, पर अलग प्रकार का।

她的同事 Arjun 记录每通电话的时长:2.3 分钟、7.81 分钟、14.002 分钟……任何正数都可能。他定义 Y =“通话时长(分钟)”。Y 也是随机变量,但类型不同。

Random variable (formal)Random variable (औपचारिक)随机变量(正式定义)
X : Ω → ℝ
A rule (function) that gives a real number to every outcome in the sample space Ω.
एक नियम (function) जो sample space Ω के हर नतीजे को एक real संख्या देता है।
一条规则(函数),给样本空间 Ω 中每个结果分配一个实数。
Observed valueदेखा गया मान观测值
x = X(ω)
When outcome ω happens, the random variable takes the value x. This is a realisation.
जब नतीजा ω होता है, random variable मान x लेता है। इसे realisation कहते हैं।
当结果 ω 发生时,随机变量取值 x,称为一次实现。
DistributionDistribution分布
P(X ∈ A) for sets A ⊆ ℝ
The chance that X lands in each set A (in practice: intervals and their combinations). This is the full description of X.
X के हर set A में आने का chance (व्यवहार में: intervals और उनके मेल)। यह X का पूरा विवरण है।
X 落入各个集合 A 的概率(实际中指区间及其组合)。这是对 X 的完整描述。
Main typesमुख्य प्रकार主要类型
Discrete or continuousDiscrete या continuous离散或连续
Discrete: values you can list (0, 1, 2, …). Continuous: any value in an interval. The type decides which tools you use.
Discrete: जिन मानों की सूची बन सके (0, 1, 2, …)। Continuous: interval का कोई भी मान। प्रकार तय करता है कि कौन-से tools लगेंगे।
离散:可以列举的取值(0、1、2、…)。连续:区间内任意值。类型决定使用哪些工具。
🌧️
Some Variables Are Mixedकुछ Variables मिश्रित होते हैं有些变量是混合型

Daily rainfall is neither purely discrete nor purely continuous. Many days have exactly 0 mm, so P(rain = 0) > 0 — a discrete lump. On wet days the amount can be any positive number — a continuous part. Its CDF has a jump at 0 and then rises smoothly. Insurance claims (many are exactly 0) behave the same way.

रोज़ की बारिश न पूरी तरह discrete है न पूरी तरह continuous। कई दिन ठीक 0 mm होती है, इसलिए P(बारिश = 0) > 0 — एक discrete ढेर। बारिश वाले दिनों में मात्रा कोई भी positive संख्या हो सकती है — continuous हिस्सा। इसकी CDF में 0 पर छलांग होती है और फिर यह smooth चढ़ती है। बीमा claims (कई ठीक 0) भी ऐसे ही होते हैं।

每日降雨量既不是纯离散也不是纯连续。很多天恰好是 0 毫米,所以 P(降雨 = 0) > 0 —— 这是离散的一块。下雨的日子雨量可以是任意正数 —— 这是连续部分。它的 CDF 在 0 处有跳跃,之后平滑上升。保险理赔(很多恰好为 0)也是如此。


SectionSection第 03 节

Random Variables in Pictures — Understand Before the Maths 📊तस्वीरों में Random Variables — गणित से पहले समझें 📊图解随机变量 — 先理解,再算数 📊

Roll two dice. The sample space has 36 equally likely pairs. The rule "add the two numbers" turns each pair into one number from 2 to 12. Counting how many pairs give each sum gives the PMF directly.

दो dice फेंकें। Sample space में 36 बराबर संभावना वाले जोड़े हैं। नियम "दोनों संख्याएँ जोड़ें" हर जोड़े को 2 से 12 तक की एक संख्या में बदल देता है। हर योग देने वाले जोड़े गिनने से सीधे PMF मिल जाता है।

掷两颗骰子,样本空间有 36 个等可能的有序对。规则“把两个数相加”把每一对变成 2 到 12 之间的一个数。数一数每个和对应几对,就直接得到 PMF。

🎲 PICTURE 1 — A RANDOM VARIABLE IS A RULEतस्वीर 1 — RANDOM VARIABLE एक नियम है图 1 — 随机变量是一条规则
The sum of two dice as a random variable Ω: 36 equally likely outcomesΩ: 36 बराबर संभावना वाले नतीजेΩ:36 个等可能结果 1st die →पहला die →第一颗 → 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12 rows = 2nd die · cell = 1st + 2ndपंक्ति = दूसरा die · खाना = पहला + दूसरा行 = 第二颗 · 格 = 第一颗 + 第二颗 X = a + b PMF of X: count the cells ÷ 36X का PMF: खाने गिनें ÷ 36X 的 PMF:数格子 ÷ 36 1/36 2 2/36 3 3/36 4 4/36 5 5/36 6 6/36 7 5/36 8 4/36 9 3/36 10 2/36 11 1/36 12 Same experiment, now described by one numberवही प्रयोग, अब एक संख्या से बताया गया同一个试验,现在用一个数来描述
LIVELIVE互动Roll Dice — Watch a PMF AppearDice फेंकें — PMF बनता देखें掷骰子 — 看 PMF 出现

Pick a rule, then roll. Each roll is one outcome ω; the rule turns it into a value of X. The blue bars are the share of rolls; the dashed outlines are the exact PMF.

एक नियम चुनें, फिर फेंकें। हर फेंक एक नतीजा ω है; नियम उसे X के एक मान में बदलता है। नीले bars फेंकों का हिस्सा हैं; dashed outlines सटीक PMF हैं।

选一条规则,然后掷。每次投掷是一个结果 ω,规则把它变成 X 的一个值。蓝柱是实测比例,虚线轮廓是精确 PMF。


SectionSection第 04 节

Discrete vs Continuous — The Core Split ⚖️Discrete बनाम Continuous — मुख्य बँटवारा ⚖️离散 vs 连续 — 核心区分 ⚖️

The first question about any random variable: can you list its possible values, or can it take any value in an interval? The answer decides which formulas, plots and distributions make sense.

किसी भी random variable के बारे में पहला सवाल: क्या आप इसके संभव मानों की सूची बना सकते हैं, या यह interval का कोई भी मान ले सकता है? जवाब तय करता है कि कौन-से formulas, plots और distributions ठीक हैं।

关于任何随机变量的第一个问题:它的可能取值能列举出来吗,还是能取区间内的任意值?答案决定了该用哪些公式、图形和分布。

DiscreteDiscrete离散
X ∈ {x₁, x₂, …}
  • Values can be listed: 0, 1, 2, …मानों की सूची बन सकती है: 0, 1, 2, …取值可以列举:0、1、2、…
  • List may be finite or endlessसूची सीमित या अंतहीन हो सकती है可以是有限个或无穷多个
  • Gaps between possible valuesसंभव मानों के बीच खाली जगह可能取值之间有间隔
  • Described by a PMF: P(X = x)PMF से बताया जाता है: P(X = x)用 PMF 描述:P(X = x)
  • PMF values sum to 1PMF मानों का योग 1PMF 之和为 1
  • CDF is a staircaseCDF सीढ़ी हैCDF 是阶梯
  • Examples: counts, dice, clicksउदाहरण: गिनती, dice, clicks例:计数、骰子、点击
ContinuousContinuous连续
X ∈ [a, b] or ℝ
  • Any value in an intervalInterval का कोई भी मान区间内任意值
  • Values cannot be listedमानों की सूची नहीं बन सकती取值无法列举
  • No gapsकोई खाली जगह नहीं没有间隔
  • Described by a PDF: f(x)PDF से बताया जाता है: f(x)用 PDF 描述:f(x)
  • Area under the PDF = 1PDF के नीचे area = 1PDF 下方面积 = 1
  • CDF is a continuous curve (S-shaped for the normal)CDF एक continuous curve (normal के लिए S-आकार)CDF 是连续曲线(正态分布为 S 形)
  • Examples: height, time, temperatureउदाहरण: लंबाई, समय, तापमान例:身高、时间、温度
The key differenceमुख्य अंतर关键区别
P(X = x)
  • Discrete: P(X = x) can be > 0Discrete: P(X = x) > 0 हो सकता है离散:P(X = x) 可以 > 0
  • Continuous: P(X = x) = 0 alwaysContinuous: P(X = x) = 0 हमेशा连续:P(X = x) 恒为 0
  • Continuous: ask about intervalsContinuous: intervals के बारे में पूछें连续:要问区间
  • Discrete: bar HEIGHT = probabilityDiscrete: bar की ऊँचाई = probability离散:柱高 = 概率
  • Continuous: AREA = probabilityContinuous: AREA = probability连续:面积 = 概率
FeatureFeature特征DiscreteDiscrete离散ContinuousContinuous连续
Valuesमान取值A list {0, 1, 2, …}एक सूची {0, 1, 2, …}可列集合 {0, 1, 2, …}An interval [a, b] or all of ℝInterval [a, b] या पूरा ℝ区间 [a, b] 或整个 ℝ
Probability at one pointएक बिंदु पर probability单点概率P(X = x) can be > 0P(X = x) > 0 हो सकता हैP(X = x) 可 > 0P(X = x) = 0P(X = x) = 0P(X = x) = 0
FunctionFunction函数PMF p(x) = P(X = x)PDF f(x); area gives probabilityPDF f(x); area से probabilityPDF f(x);面积给出概率
Totalकुल总和Σ p(x) = 1∫ f(x) dx = 1
CDF shapeCDF का आकारCDF 形状Staircaseसीढ़ी阶梯Continuous curve (no jumps)Continuous curve (कोई छलांग नहीं)连续曲线(无跳跃)
Common distributionsआम distributions常见分布Binomial, Poisson, GeometricNormal, Exponential, Uniform, Beta
Real examplesअसली उदाहरण真实例子Defects, goals, clicksDefects, goals, clicks次品数、进球、点击Height, weight, time, temperatureलंबाई, वज़न, समय, तापमान身高、体重、时间、温度
⚖ PICTURE 2 — HEIGHT VS AREAतस्वीर 2 — ऊँचाई बनाम AREA图 2 — 高度 vs 面积
Discrete PMF versus continuous PDF Discrete: probability sits ON pointsDiscrete: probability बिंदुओं पर बैठती है离散:概率落在点上 1 2 3 4 5 6 each bar = 1/6 ≈ 0.167हर bar = 1/6 ≈ 0.167每根柱 = 1/6 ≈ 0.167 one fair die: bar HEIGHT = probabilityएक सही die: bar की ऊँचाई = probability一颗均匀骰子:柱的高度 = 概率 Continuous: probability is AREAContinuous: probability = AREA连续:概率是面积 140 150 160 170 180 190 P(160 ≤ H ≤ 170) = 0.468 heights N(165, 8²): shaded AREA = probabilityलंबाई N(165, 8²): रंगीन AREA = probability身高 N(165, 8²):阴影面积 = 概率

SectionSection第 05 节

Probability Mass Function (PMF) 📊Probability Mass Function (PMF) 📊概率质量函数(PMF)📊

The Story: The Quality Inspectorकहानी: Quality Inspector故事:质检员

Ravi checks batches of 3 smartphones. Each phone, independently, has a 20% chance of a defect. X = "number of defective phones in a batch". X can be 0, 1, 2 or 3. The list of probabilities for these four values is the probability mass function.

Ravi 3 smartphones के batches जाँचता है। हर phone में, independently, defect का 20% chance है। X = "batch में ख़राब phones की संख्या"। X 0, 1, 2 या 3 हो सकता है। इन चार मानों की probabilities की सूची probability mass function है।

Ravi 检查每批 3 部智能手机。每部手机独立地有 20% 的概率存在缺陷。X =“一批中的次品数”,可取 0、1、2、3。这四个值的概率清单就是概率质量函数。

PMFPMFPMF
p(x) = P(X = x)
How much probability sits exactly at each value x.
हर मान x पर ठीक कितनी probability बैठी है।
每个取值 x 上恰好有多少概率。
Two rulesदो नियम两条规则
p(x) ≥ 0 and Σ p(x) = 1
No negative probabilities, and they must add up to exactly 1.
कोई negative probability नहीं, और योग ठीक 1।
概率不能为负,且总和恰为 1。
Expected valueExpected value期望
E[X] = Σ x · p(x)
The probability-weighted average — the balance point of the bars.
Probability से तौला गया औसत — bars का संतुलन बिंदु।
按概率加权的平均 —— 柱状图的平衡点。
VarianceVariance方差
Var(X) = Σ (x − μ)² · p(x)
The weighted average squared distance from the mean μ = E[X].
Mean μ = E[X] से वर्ग दूरी का weighted औसत।
到均值 μ = E[X] 的平方距离的加权平均。
🧮 PMF — Defective Phones (Binomial, n = 3, p = 0.2)PMF — ख़राब Phones (Binomial, n = 3, p = 0.2)PMF — 次品手机(二项,n = 3,p = 0.2)
Formula
P(X = k) = C(n, k) · pᵏ · (1 − p)ⁿ⁻ᵏ with n = 3, p = 0.2
P(X = k) = C(n, k) · pᵏ · (1 − p)ⁿ⁻ᵏ with n = 3, p = 0.2
P(X = k) = C(n, k) · pᵏ · (1 − p)ⁿ⁻ᵏ with n = 3, p = 0.2
P(X=0)
1 × 1 × 0.8³ = 0.512
1 × 1 × 0.8³ = 0.512
1 × 1 × 0.8³ = 0.512
P(X=1)
3 × 0.2 × 0.8² = 0.384
3 × 0.2 × 0.8² = 0.384
3 × 0.2 × 0.8² = 0.384
P(X=2)
3 × 0.2² × 0.8 = 0.096
3 × 0.2² × 0.8 = 0.096
3 × 0.2² × 0.8 = 0.096
P(X=3)
1 × 0.2³ × 1 = 0.008
1 × 0.2³ × 1 = 0.008
1 × 0.2³ × 1 = 0.008
Checkजाँच验证
0.512 + 0.384 + 0.096 + 0.008 = 1.000 ✓
0.512 + 0.384 + 0.096 + 0.008 = 1.000 ✓
0.512 + 0.384 + 0.096 + 0.008 = 1.000 ✓
E[X]
0×0.512 + 1×0.384 + 2×0.096 + 3×0.008 = 0.60 (also n·p = 3 × 0.2)
0×0.512 + 1×0.384 + 2×0.096 + 3×0.008 = 0.60 (n·p = 3 × 0.2 भी)
0×0.512 + 1×0.384 + 2×0.096 + 3×0.008 = 0.60(也等于 n·p = 3 × 0.2)
Var(X)
n·p·(1 − p) = 3 × 0.2 × 0.8 = 0.48; SD = √0.48 ≈ 0.693
n·p·(1 − p) = 3 × 0.2 × 0.8 = 0.48; SD = √0.48 ≈ 0.693
n·p·(1 − p) = 3 × 0.2 × 0.8 = 0.48; SD = √0.48 ≈ 0.693
📊 PICTURE 3 — PMF AND ITS CDFतस्वीर 3 — PMF और उसकी CDF图 3 — PMF 及其 CDF
PMF and CDF of defective phones PMF p(x) = P(X = x) 0 0.2 0.4 0.6 0.5120 0.3841 0.0962 0.0083 μ = 0.6 number of defective phones in a batch of 33 के batch में ख़राब phones3 部一批中的次品数 CDF F(x) = P(X ≤ x): a staircaseCDF F(x) = P(X ≤ x): सीढ़ीCDF F(x) = P(X ≤ x):阶梯 0 0.5 1 0.5120 0.8961 0.9922 1.0003 filled dot = value at the jump (right-continuous); hollow = just beforeभरा बिंदु = छलांग पर मान (right-continuous); खोखला = ठीक पहले实心点 = 跳跃处的值(右连续);空心点 = 跳跃前

The CDF jumps by exactly the PMF bar at each value: 0.512, then +0.384, +0.096, +0.008.

CDF हर मान पर ठीक PMF bar जितनी छलांग लगाती है: 0.512, फिर +0.384, +0.096, +0.008।

CDF 在每个取值处正好跳升一个 PMF 柱高:0.512,然后 +0.384、+0.096、+0.008。

More PMF ExamplesPMF के और उदाहरण更多 PMF 例子

Experimentप्रयोग试验Random variable XRandom variable X随机变量 XValuesमान取值PMFPMFPMF
Fair coinसही सिक्का均匀硬币1 if heads, 0 if tailsheads पर 1, tails पर 0正面为 1,反面为 0{0, 1}P(X=0) = P(X=1) = 0.5
Fair dieसही die均匀骰子Face shownदिखा अंक朝上的点数{1, …, 6}P(X=k) = 1/6
Goals in a football matchफ़ुटबॉल मैच में गोल足球比赛进球数Total goalsकुल गोल总进球{0, 1, 2, …}Often modelled as Poisson: e^(−λ) λᵏ / k!अक्सर Poisson से: e^(−λ) λᵏ / k!常用泊松模型:e^(−λ) λᵏ / k!
Emails per hourहर घंटे emails每小时邮件数Number receivedआए emails की संख्या收到的数量{0, 1, 2, …}Poisson with λ = average ratePoisson, λ = औसत दर泊松,λ = 平均速率
Raffle ticketRaffle ticket抽奖券1 if you win, else 0जीतें तो 1, वरना 0中奖为 1,否则为 0{0, 1}P(X=1) = 1/1000
LIVELIVE互动PMF and CDF, Side by SidePMF और CDF, साथ-साथPMF 与 CDF 并排

Set n and p for a binomial variable, then move k. Every bar up to k is shaded; their total is F(k), the height of the staircase below. Turn on Poisson to see when it approximates the binomial.

Binomial variable के लिए n और p चुनें, फिर k खिसकाएँ। k तक का हर bar रंगीन है; इनका योग F(k) है, यानी नीचे की सीढ़ी की ऊँचाई। Poisson चालू करें और देखें कि यह कब binomial के पास होता है।

为二项变量设置 n 和 p,再移动 k。k 及以下的柱子都会着色,它们的总和就是 F(k),即下方阶梯的高度。打开泊松,看看它何时近似二项分布。


SectionSection第 06 节

Probability Density Function (PDF) 🌊Probability Density Function (PDF) 🌊概率密度函数(PDF)🌊

The Story: Hospital Waiting Timeकहानी: अस्पताल में इंतज़ार故事:医院候诊时间

An emergency room records waiting times: 8.7 minutes, 23.14 minutes, 5.003 minutes… The wait Y can be any non-negative number. The chance that Y is exactly 8.7000… minutes is zero. But the chance that Y is between 10 and 20 minutes is a real, useful number: the area under the density curve between 10 and 20.

एक emergency room इंतज़ार के समय दर्ज करता है: 8.7 मिनट, 23.14 मिनट, 5.003 मिनट… इंतज़ार Y कोई भी non-negative संख्या हो सकता है। Y के ठीक 8.7000… मिनट होने का chance शून्य है। पर Y के 10 और 20 मिनट के बीच होने का chance एक असली, काम की संख्या है: 10 और 20 के बीच density curve के नीचे का area।

急诊室记录候诊时间:8.7 分钟、23.14 分钟、5.003 分钟……等待时间 Y 可以是任意非负数。Y 恰好等于 8.7000… 分钟的概率为零。但 Y 落在 10 到 20 分钟之间的概率是一个真实而有用的数:密度曲线在 10 到 20 之间的面积。

⚠️
The Most Common PDF MistakePDF की सबसे आम ग़लती关于 PDF 最常见的误解

f(x) is NOT a probability. It is a density — like population density (people per km²). It can be bigger than 1: Uniform(0, 0.5) has f(x) = 2 on its whole range, yet its total area is 2 × 0.5 = 1. Only areas give probabilities: P(a ≤ X ≤ b) = ∫ₐᵇ f(x) dx.

f(x) probability नहीं है। यह density है — जैसे जनसंख्या घनत्व (लोग प्रति km²)। यह 1 से बड़ी हो सकती है: Uniform(0, 0.5) में पूरी range पर f(x) = 2 है, फिर भी कुल area 2 × 0.5 = 1 है। सिर्फ़ areas probability देते हैं: P(a ≤ X ≤ b) = ∫ₐᵇ f(x) dx।

f(x) 不是概率,而是密度 —— 就像人口密度(每平方千米的人数)。它可以大于 1:Uniform(0, 0.5) 在整个范围上 f(x) = 2,但总面积仍是 2 × 0.5 = 1。只有面积才给出概率:P(a ≤ X ≤ b) = ∫ₐᵇ f(x) dx。

PDF and probabilityPDF और probabilityPDF 与概率
P(a ≤ X ≤ b) = ∫ₐᵇ f(x) dx
The chance of landing in [a, b] is the area under f between a and b.
[a, b] में आने का chance = a और b के बीच f के नीचे का area।
落在 [a, b] 的概率等于 f 在 a 与 b 之间的面积。
Two rulesदो नियम两条规则
f(x) ≥ 0 and ∫ f(x) dx = 1
The density is never negative, and the total area is exactly 1.
Density कभी negative नहीं, और कुल area ठीक 1।
密度永不为负,总面积恰为 1。
Expected valueExpected value期望
E[X] = ∫ x · f(x) dx
Same idea as the PMF mean: the sum becomes an integral.
PMF mean जैसा ही विचार: योग integral बन जाता है।
与 PMF 均值同理:求和变成积分。
VarianceVariance方差
Var(X) = ∫ (x − μ)² f(x) dx
The density-weighted average squared distance from μ.
μ से वर्ग दूरी का density-weighted औसत।
以密度加权的、到 μ 的平方距离的平均。
🧮 PDF — Uniform: Waiting for a BusPDF — Uniform: बस का इंतज़ारPDF — 均匀分布:等公交
Storyकहानी故事
The bus comes at a random time between 0 and 10 minutes from now: Y ~ Uniform(0, 10). The density is flat.
बस अभी से 0 और 10 मिनट के बीच किसी random समय आती है: Y ~ Uniform(0, 10)। Density सपाट है।
公交在接下来 0 到 10 分钟内随机到达:Y ~ Uniform(0, 10)。密度是平的。
PDF
f(y) = 1/(10 − 0) = 0.10 for 0 ≤ y ≤ 10, else 0
f(y) = 1/(10 − 0) = 0.10 for 0 ≤ y ≤ 10, else 0
f(y) = 1/(10 − 0) = 0.10 for 0 ≤ y ≤ 10, else 0
Checkजाँच验证
0.10 × 10 = 1.0 ✓
0.10 × 10 = 1.0 ✓
0.10 × 10 = 1.0 ✓
P(2≤Y≤5)
0.10 × (5 − 2) = 0.30
0.10 × (5 − 2) = 0.30
0.10 × (5 − 2) = 0.30
P(Y=3)
0.10 × 0 = 0 — an interval of width 0 has no area.
0.10 × 0 = 0 — चौड़ाई 0 वाले interval का कोई area नहीं।
0.10 × 0 = 0 —— 宽度为 0 的区间没有面积。
E[Y]
(0 + 10)/2 = 5 minutes
(0 + 10)/2 = 5 मिनट
(0 + 10)/2 = 5 分钟
🧮 PDF — Normal: Heights (Illustrative)PDF — Normal: लंबाई (उदाहरण)PDF — 正态:身高(示例)
Storyकहानी故事
Suppose the heights of adult men in a city follow a normal distribution with μ = 165 cm and σ = 8 cm. (Mixing men and women would give a wider, flatter shape, so we keep one group.)
मान लें किसी शहर के वयस्क पुरुषों की लंबाई normal distribution मानती है, μ = 165 cm और σ = 8 cm। (पुरुषों और महिलाओं को मिलाने से आकार चौड़ा और चपटा होगा, इसलिए हम एक group रखते हैं।)
假设某城市成年男性身高服从正态分布,μ = 165 厘米,σ = 8 厘米。(把男女混在一起会让形状更宽更平,所以只取一组。)
PDF
f(h) = 1/(8√(2π)) · exp[−(h − 165)² / 128]
f(h) = 1/(8√(2π)) · exp[−(h − 165)² / 128]
f(h) = 1/(8√(2π)) · exp[−(h − 165)² / 128]
P(H>170)
z = (170 − 165)/8 = 0.625 → P(Z > 0.625) ≈ 0.266
z = (170 − 165)/8 = 0.625 → P(Z > 0.625) ≈ 0.266
z = (170 − 165)/8 = 0.625 → P(Z > 0.625) ≈ 0.266
68-95-99.768-95-99.768-95-99.7
157–173 cm: 68.3% · 149–181 cm: 95.4% · 141–189 cm: 99.7%
157–173 cm: 68.3% · 149–181 cm: 95.4% · 141–189 cm: 99.7%
157–173 厘米:68.3% · 149–181 厘米:95.4% · 141–189 厘米:99.7%
DensityDensity密度
The peak height is f(165) ≈ 0.050 per cm — a rate, not a probability.
शिखर की ऊँचाई f(165) ≈ 0.050 प्रति cm — एक दर, probability नहीं।
峰值 f(165) ≈ 0.050 每厘米 —— 是一个速率,不是概率。
📐 PICTURE 4 — THE 68-95-99.7 RULEतस्वीर 4 — 68-95-99.7 नियम图 4 — 68-95-99.7 法则
The 68-95-99.7 rule for heights 141 149 157 165 173 181 189 68.3% 13.6% 13.6% 2.1% 2.1% μ ± 1σ: 68.3% · μ ± 2σ: 95.4% · μ ± 3σ: 99.7% (height in cm)μ ± 1σ: 68.3% · μ ± 2σ: 95.4% · μ ± 3σ: 99.7% (लंबाई cm में)μ ± 1σ:68.3% · μ ± 2σ:95.4% · μ ± 3σ:99.7%(身高,厘米)
LIVELIVE互动Probability Is Area — Shrink to a PointProbability = Area — बिंदु तक सिकोड़ें概率就是面积 — 缩成一个点

Choose a distribution, move the interval, and change its width. The shaded area is the probability. Press "Shrink" and watch the area vanish while the height stays. Try U(0, 0.5) to see a density above 1.

एक distribution चुनें, interval खिसकाएँ, और उसकी चौड़ाई बदलें। रंगीन area ही probability है। "सिकोड़ें" दबाएँ और देखें कि ऊँचाई रहती है पर area ग़ायब हो जाता है। 1 से ज़्यादा density देखने के लिए U(0, 0.5) आज़माएँ।

选择一个分布,移动区间并改变宽度。阴影面积就是概率。点击“缩成一个点”,看面积消失而高度不变。试试 U(0, 0.5),看看大于 1 的密度。


SectionSection第 07 节

Cumulative Distribution Function (CDF) 📈Cumulative Distribution Function (CDF) 📈累积分布函数(CDF)📈

The Story: The Weather Forecasterकहानी: मौसम विशेषज्ञ故事:天气预报员

A forecaster studying daily rainfall rarely asks "what is the chance of exactly 15 mm?". She asks "what is the chance of at most 15 mm?". "At most" questions are exactly what the cumulative distribution function answers.

रोज़ की बारिश पढ़ने वाली मौसम विशेषज्ञ शायद ही पूछती है "ठीक 15 mm का chance क्या है?"। वह पूछती है "ज़्यादा से ज़्यादा 15 mm का chance क्या है?"। "ज़्यादा से ज़्यादा" वाले सवालों का जवाब ठीक cumulative distribution function देता है।

研究每日降雨的预报员很少问“恰好 15 毫米的概率是多少?”,她会问“至多 15 毫米的概率是多少?”。“至多”类问题正是累积分布函数回答的。

The CDF works for every random variable — discrete, continuous or mixed. It starts at 0, ends at 1 and never goes down. For discrete variables it is a staircase; for continuous ones it is an unbroken curve whose shape depends on the distribution.

CDF हर random variable के लिए काम करती है — discrete, continuous या mixed। यह 0 से शुरू होती है, 1 पर ख़त्म होती है और कभी नीचे नहीं जाती। Discrete variables के लिए यह सीढ़ी है; continuous के लिए एक अटूट curve जिसका आकार distribution पर निर्भर है।

CDF 适用于所有随机变量 —— 离散、连续或混合。它从 0 开始,到 1 结束,从不下降。离散变量的 CDF 是阶梯;连续变量的是一条不间断的曲线,形状取决于分布。

Definition (all types)परिभाषा (सभी प्रकार)定义(所有类型)
F(x) = P(X ≤ x)
The chance that X is at most x. Defined for every real x.
X के ज़्यादा से ज़्यादा x होने का chance। हर real x के लिए परिभाषित।
X 至多为 x 的概率,对所有实数 x 都有定义。
From a PMFPMF से由 PMF 得到
F(x) = Σ p(k) for k ≤ x
Add up the bars from the left. Each jump equals one PMF bar.
बाईं ओर से bars जोड़ें। हर छलांग एक PMF bar के बराबर।
从左往右累加柱子,每次跳跃等于一个 PMF 柱高。
From a PDFPDF से由 PDF 得到
F(x) = ∫₋∞ˣ f(t) dt
The area to the left of x. Where f exists, F′(x) = f(x).
x के बाईं ओर का area। जहाँ f है, वहाँ F′(x) = f(x)।
x 左侧的面积。在 f 存在处,F′(x) = f(x)。
IntervalsIntervals区间
P(a < X ≤ b) = F(b) − F(a)
Works for every distribution. For continuous variables, < and ≤ give the same answer.
हर distribution के लिए। Continuous variables में < और ≤ एक ही जवाब देते हैं।
适用于所有分布。连续变量中 < 与 ≤ 结果相同。
📐 Three Properties of Every CDFहर CDF के तीन गुण每个 CDF 的三条性质
1
Between 0 and 1: F(x) → 0 as x → −∞ and F(x) → 1 as x → +∞.
0 और 1 के बीच: x → −∞ पर F(x) → 0 और x → +∞ पर F(x) → 1।
介于 0 与 1 之间:x → −∞ 时 F(x) → 0,x → +∞ 时 F(x) → 1。
2
Never decreasing: if a ≤ b then F(a) ≤ F(b). Probability only builds up as x grows.
कभी नहीं घटती: अगर a ≤ b तो F(a) ≤ F(b)। x बढ़ने पर probability सिर्फ़ जमा होती है।
单调不减:若 a ≤ b,则 F(a) ≤ F(b)。随着 x 增大,概率只会累积。
3
Right-continuous: at a jump x₀, F(x₀) already includes the jump: F(x₀) = lim F(x) as x → x₀ from the right. That is why the filled dot sits at the top of each step.
Right-continuous: छलांग x₀ पर F(x₀) में छलांग पहले से शामिल है: F(x₀) = दाईं ओर से x → x₀ पर F(x) की सीमा। इसीलिए भरा बिंदु हर सीढ़ी के ऊपर होता है।
右连续:在跳跃点 x₀,F(x₀) 已包含跳跃:F(x₀) 等于 x 从右侧趋于 x₀ 时 F(x) 的极限。所以实心点在每级台阶的上方。
🧮 CDF — Defective PhonesCDF — ख़राब PhonesCDF — 次品手机
F(0)
P(X ≤ 0) = 0.512
P(X ≤ 0) = 0.512
P(X ≤ 0) = 0.512
F(1)
0.512 + 0.384 = 0.896
0.512 + 0.384 = 0.896
0.512 + 0.384 = 0.896
F(2)
0.896 + 0.096 = 0.992
0.896 + 0.096 = 0.992
0.896 + 0.096 = 0.992
F(3)
0.992 + 0.008 = 1.000 ✓
0.992 + 0.008 = 1.000 ✓
0.992 + 0.008 = 1.000 ✓
Use itइस्तेमाल应用
P(X > 1) = 1 − F(1) = 0.104 (2 or more defects). P(1 < X ≤ 3) = F(3) − F(1) = 0.104 — the same event.
P(X > 1) = 1 − F(1) = 0.104 (2 या ज़्यादा defects)। P(1 < X ≤ 3) = F(3) − F(1) = 0.104 — वही event।
P(X > 1) = 1 − F(1) = 0.104(2 个及以上次品)。P(1 < X ≤ 3) = F(3) − F(1) = 0.104 —— 是同一个事件。
📈 PICTURE 5 — NOT EVERY CDF IS AN S-CURVEतस्वीर 5 — हर CDF S-CURVE नहीं होती图 5 — 并非每个 CDF 都是 S 形
Four shapes of CDF Binomial(3, 0.2) staircaseसीढ़ी阶梯 NormalNormal正态 S-curveS-curveS 形 Uniform(0, 1) straight rampसीधी ढलान直线斜坡 Exponential(1) fast rise, then flatतेज़ चढ़ाई, फिर सपाट先快升后平
LIVELIVE互动Sweep x — Build the CDFx खिसकाएँ — CDF बनाएँ扫动 x — 构建 CDF

A line sweeps from left to right. The shaded amount in the top panel is always equal to the height of the CDF in the bottom panel. Try all four distributions.

एक रेखा बाएँ से दाएँ चलती है। ऊपर के panel में रंगीन मात्रा हमेशा नीचे के panel में CDF की ऊँचाई के बराबर होती है। चारों distributions आज़माएँ।

一条竖线从左向右扫过。上图的阴影量始终等于下图 CDF 的高度。四种分布都试试。


SectionSection第 08 节

From Histogram to Density 🧱Histogram से Density तक 🧱从直方图到密度 🧱

Where does a PDF come from in practice? Record many call durations, draw a histogram, and scale each bar so its area (not height) is the share of calls in that bin. With more data and narrower bins, the bars settle onto a smooth curve — the density.

व्यवहार में PDF कहाँ से आती है? बहुत सारी calls की अवधि दर्ज करें, histogram बनाएँ, और हर bar को ऐसे scale करें कि उसका area (ऊँचाई नहीं) उस bin में calls का हिस्सा हो। ज़्यादा data और पतले bins के साथ bars एक smooth curve पर टिक जाते हैं — यही density है।

实际中 PDF 从哪里来?记录大量通话时长,画直方图,并缩放每根柱子,使其面积(而非高度)等于该组的通话比例。数据越多、组越窄,柱子就越贴合一条平滑曲线 —— 这就是密度。

LIVELIVE互动Record Calls — Histogram Meets DensityCalls दर्ज करें — Histogram और Density记录通话 — 直方图遇见密度

Call durations here follow an exponential distribution with a mean of 5 minutes. Add calls and narrow the bins.

यहाँ call की अवधि 5 मिनट mean वाले exponential distribution को मानती है। Calls जोड़ें और bins पतले करें।

这里的通话时长服从均值为 5 分钟的指数分布。添加通话并缩小组宽。


SectionSection第 09 节

PMF vs PDF vs CDF — The Full ComparisonPMF बनाम PDF बनाम CDF — पूरी तुलनाPMF vs PDF vs CDF — 全面比较

FeatureFeature特征PMF p(x)PDF f(x)CDF F(x)
Variable typeVariable प्रकार变量类型DiscreteDiscrete离散ContinuousContinuous连续All typesसभी प्रकार所有类型
Value at a pointएक बिंदु पर मान某点的值A probability, P(X = x)एक probability, P(X = x)概率 P(X = x)A density (not a probability)Density (probability नहीं)密度(不是概率)A probability, P(X ≤ x)एक probability, P(X ≤ x)概率 P(X ≤ x)
RangeRange取值范围0 ≤ p(x) ≤ 1f(x) ≥ 0 (can exceed 1)f(x) ≥ 0 (1 से ज़्यादा हो सकती है)f(x) ≥ 0(可超过 1)0 ≤ F(x) ≤ 1
Totalsकुल总和Σ p(x) = 1∫ f(x) dx = 1F(+∞) = 1
Pictureतस्वीर图形Bars at the valuesमानों पर bars取值处的柱子Curve (or flat line)Curve (या सपाट रेखा)曲线(或水平线)Staircase or unbroken curveसीढ़ी या अटूट curve阶梯或连续曲线
Interval probabilityInterval की probability区间概率Add the bars in [a, b][a, b] के bars जोड़ें把 [a, b] 内的柱相加Area ∫ₐᵇ f(x) dxArea ∫ₐᵇ f(x) dx面积 ∫ₐᵇ f(x) dxF(b) − F(a)
Linksसंबंध关系CDF = running sum of PMFCDF = PMF का चलता योगCDF = PMF 的累加CDF = integral of PDFCDF = PDF का integralCDF = PDF 的积分PDF = derivative of CDFPDF = CDF का derivativePDF = CDF 的导数

SectionSection第 10 节

Common Discrete Distributions 🎰आम Discrete Distributions 🎰常见离散分布 🎰

DistributionDistribution分布PMF p(k)ParametersParameters参数MeanMean均值Use caseउपयोग用途
Bernoulli(p)p if k = 1; 1 − p if k = 0k = 1 पर p; k = 0 पर 1 − pk = 1 时为 p;k = 0 时为 1 − pp ∈ [0, 1]pOne trial: click or no clickएक trial: click या नहीं单次试验:点击与否
Binomial(n, p)C(n, k) pᵏ (1 − p)ⁿ⁻ᵏn trials, success chance pn trials, सफलता chance pn 次试验,成功概率 pnpSuccesses in n trialsn trials में सफलताएँn 次试验中的成功次数
Poisson(λ)e^(−λ) λᵏ / k!λ = average countλ = औसत गिनतीλ = 平均次数λEvents per unit of time or spaceसमय/जगह की इकाई में घटनाएँ单位时间或空间内的事件数
Geometric(p)(1 − p)ᵏ⁻¹ p, for k = 1, 2, …(1 − p)ᵏ⁻¹ p, k = 1, 2, … के लिए(1 − p)ᵏ⁻¹ p,k = 1, 2, …p = success chancep = सफलता chancep = 成功概率1/pTrials until the first success (some books count failures instead)पहली सफलता तक trials (कुछ किताबें असफलताएँ गिनती हैं)直到首次成功的试验次数(有些书改为计失败次数)
Discrete uniform{a, …, b}Discrete uniform{a, …, b}离散均匀{a, …, b}1/(b − a + 1)a = min, b = max(a + b)/2Fair die, lottery numberसही die, लॉटरी नंबर均匀骰子、彩票号码

SectionSection第 11 节

Common Continuous Distributions 🌊आम Continuous Distributions 🌊常见连续分布 🌊

DistributionDistribution分布PDF f(x)RangeRange范围MeanMean均值Use caseउपयोग用途
Uniform(a, b)1/(b − a)[a, b](a + b)/2Equally likely over an intervalInterval पर बराबर संभावना区间内等可能
Normal N(μ, σ²)(1/(σ√(2π))) e^(−(x−μ)²/(2σ²))(−∞, +∞)μMeasurement errors, heights, test scoresमाप की ग़लतियाँ, लंबाई, test scores测量误差、身高、考试分数
Exponential(λ)λ e^(−λx)[0, +∞)1/λTime between random eventsRandom घटनाओं के बीच समय随机事件之间的时间
Beta(α, β)x^(α−1) (1−x)^(β−1) / B(α, β)[0, 1]α/(α + β)Unknown proportions and ratesअज्ञात अनुपात और दरें未知的比例与比率
Gamma(k, θ)x^(k−1) e^(−x/θ) / (θᵏ Γ(k))[0, +∞)kθWaiting times, claim sizes (θ is the scale; some books use a rate 1/θ)इंतज़ार समय, claim आकार (θ scale है; कुछ किताबें rate 1/θ लेती हैं)等待时间、理赔金额(θ 为尺度参数;有的书用速率 1/θ)
Log-normal(1/(xσ√(2π))) e^(−(ln x−μ)²/(2σ²))(0, +∞)e^(μ + σ²/2)Incomes, file sizes, pricesआय, file आकार, कीमतें收入、文件大小、价格

SectionSection第 12 节

Using the CDF — Four Practical Questions 🔧CDF का इस्तेमाल — चार व्यावहारिक सवाल 🔧使用 CDF — 四个实际问题 🔧

🧮 Test Scores ~ N(70, 10²)Test Scores ~ N(70, 10²)考试分数 ~ N(70, 10²)
P(X ≤ 80)
z = 1.0 → F(80) = 0.841: 84.1% score 80 or less.
z = 1.0 → F(80) = 0.841: 84.1% के 80 या कम।
z = 1.0 → F(80) = 0.841:84.1% 的人得分 ≤ 80。
P(X > 80)
1 − 0.841 = 0.159
1 − 0.841 = 0.159
1 − 0.841 = 0.159
P(60 ≤ X ≤ 80)
F(80) − F(60) = 0.841 − 0.159 = 0.683
F(80) − F(60) = 0.841 − 0.159 = 0.683
F(80) − F(60) = 0.841 − 0.159 = 0.683
90th percentile90वाँ percentile第 90 百分位
Solve F(x) = 0.90: z = 1.282 → x = 70 + 1.282 × 10 = 82.8. This "inverse CDF" is called the quantile function.
F(x) = 0.90 हल करें: z = 1.282 → x = 70 + 1.282 × 10 = 82.8। इस "inverse CDF" को quantile function कहते हैं।
解 F(x) = 0.90:z = 1.282 → x = 70 + 1.282 × 10 = 82.8。这个“反 CDF”叫分位数函数。

SectionSection第 13 节

Python ImplementationPython ImplementationPython 实现

PMF, CDF, mean and variance with scipy.statsscipy.stats से PMF, CDF, mean और variance用 scipy.stats 计算 PMF、CDF、均值和方差

# 1) PMF, CDF, mean and variance of the defective-phone example
from scipy import stats
X = stats.binom(n=3, p=0.2)
for k in range(4):
    print(f"P(X={k}) = {X.pmf(k):.3f}    F({k}) = P(X<={k}) = {X.cdf(k):.3f}")
print(f"sum of PMF = {sum(X.pmf(k) for k in range(4)):.3f}")
print(f"E[X] = {X.mean():.2f}, Var(X) = {X.var():.2f}, SD = {X.std():.3f}")
print(f"P(X > 1) = 1 - F(1) = {X.sf(1):.3f}")
OUTPUT
P(X=0) = 0.512 F(0) = P(X<=0) = 0.512 P(X=1) = 0.384 F(1) = P(X<=1) = 0.896 P(X=2) = 0.096 F(2) = P(X<=2) = 0.992 P(X=3) = 0.008 F(3) = P(X<=3) = 1.000 sum of PMF = 1.000 E[X] = 0.60, Var(X) = 0.48, SD = 0.693 P(X > 1) = 1 - F(1) = 0.104

Zero probability at a point; density above 1एक बिंदु पर शून्य probability; 1 से ऊपर density单点概率为零;密度可大于 1

# 2) Continuous: a point has zero probability, and density can exceed 1
from scipy import stats
bus = stats.uniform(loc=0, scale=10)            # Uniform(0, 10)
print(f"f(3) = {bus.pdf(3):.2f}   (a density, not a probability)")
print(f"P(2 <= Y <= 5) = {bus.cdf(5) - bus.cdf(2):.2f}")
for w in [1, 0.1, 0.001, 0]:
    print(f"P(3 <= Y <= 3+{w}) = {bus.cdf(3 + w) - bus.cdf(3):.4f}")
narrow = stats.uniform(loc=0, scale=0.5)         # Uniform(0, 0.5)
print(f"Uniform(0, 0.5): f(x) = {narrow.pdf(0.2):.1f}, total area = {narrow.cdf(0.5):.1f}")
OUTPUT
f(3) = 0.10 (a density, not a probability) P(2 <= Y <= 5) = 0.30 P(3 <= Y <= 3+1) = 0.1000 P(3 <= Y <= 3+0.1) = 0.0100 P(3 <= Y <= 3+0.001) = 0.0001 P(3 <= Y <= 3+0) = 0.0000 Uniform(0, 0.5): f(x) = 2.0, total area = 1.0

Normal areas and the 68-95-99.7 ruleNormal areas और 68-95-99.7 नियम正态面积与 68-95-99.7 法则

# 3) Normal heights: areas from the CDF
from scipy import stats
H = stats.norm(loc=165, scale=8)
print(f"P(H > 170)        = {H.sf(170):.3f}")
for k in (1, 2, 3):
    lo, hi = 165 - k * 8, 165 + k * 8
    print(f"P({lo} <= H <= {hi}) = {H.cdf(hi) - H.cdf(lo):.4f}")
print(f"peak density f(165) = {H.pdf(165):.4f} per cm")
OUTPUT
P(H > 170) = 0.266 P(157 <= H <= 173) = 0.6827 P(149 <= H <= 181) = 0.9545 P(141 <= H <= 189) = 0.9973 peak density f(165) = 0.0499 per cm

Four CDF questions, including the inverse CDFचार CDF सवाल, inverse CDF सहित四个 CDF 问题(含反 CDF)

# 4) Four CDF questions about test scores ~ N(70, 10^2)
from scipy import stats
S = stats.norm(loc=70, scale=10)
print(f"P(X <= 80)       = {S.cdf(80):.4f}")
print(f"P(X > 80)        = {S.sf(80):.4f}")
print(f"P(60 <= X <= 80) = {S.cdf(80) - S.cdf(60):.4f}")
print(f"90th percentile  = {S.ppf(0.90):.2f}")
OUTPUT
P(X <= 80) = 0.8413 P(X > 80) = 0.1587 P(60 <= X <= 80) = 0.6827 90th percentile = 82.82

Simulation vs exact PMF, and Poisson ≈ BinomialSimulation बनाम सटीक PMF, और Poisson ≈ Binomial模拟 vs 精确 PMF,以及泊松 ≈ 二项

# 5) Simulation meets theory: sum of two dice, and Poisson ≈ Binomial
import numpy as np
from collections import Counter
from scipy import stats
rng = np.random.default_rng(1)
sums = rng.integers(1, 7, 100_000) + rng.integers(1, 7, 100_000)
count = Counter(sums)
for s in range(2, 13):
    exact = (6 - abs(s - 7)) / 36
    print(f"sum {s:2d}: simulated {count[s] / 100_000:.4f}   exact {exact:.4f}")
print()
n, p = 1000, 0.003
for k in range(6):
    print(f"k={k}: Binomial {stats.binom.pmf(k, n, p):.4f}   Poisson {stats.poisson.pmf(k, n * p):.4f}")
OUTPUT
sum 2: simulated 0.0279 exact 0.0278 sum 3: simulated 0.0558 exact 0.0556 sum 4: simulated 0.0835 exact 0.0833 sum 5: simulated 0.1117 exact 0.1111 sum 6: simulated 0.1400 exact 0.1389 sum 7: simulated 0.1645 exact 0.1667 sum 8: simulated 0.1399 exact 0.1389 sum 9: simulated 0.1115 exact 0.1111 sum 10: simulated 0.0819 exact 0.0833 sum 11: simulated 0.0553 exact 0.0556 sum 12: simulated 0.0281 exact 0.0278 k=0: Binomial 0.0496 Poisson 0.0498 k=1: Binomial 0.1491 Poisson 0.1494 k=2: Binomial 0.2242 Poisson 0.2240 k=3: Binomial 0.2244 Poisson 0.2240 k=4: Binomial 0.1683 Poisson 0.1680 k=5: Binomial 0.1009 Poisson 0.1008

SectionSection第 14 节

Random Variables in Data Science & ML 🤖Data Science और ML में Random Variables 🤖数据科学与机器学习中的随机变量 🤖

Applicationउपयोग应用Random variableRandom variable随机变量Typeप्रकार类型Typical modelआम model常用模型
🖱️ Ad click predictionAd click prediction广告点击预测1 = click, 0 = no click1 = click, 0 = नहीं1 = 点击,0 = 未点击DiscreteDiscrete离散Bernoulli / Binomial
📦 InventoryInventory库存Daily demand (units)रोज़ की माँग (units)每日需求(件)DiscreteDiscrete离散Poisson (or negative binomial if more spread)Poisson (या ज़्यादा फैलाव हो तो negative binomial)泊松(离散度更大时用负二项)
📉 Stock returnsStock returns股票收益Daily log-returnरोज़ का log-return日对数收益ContinuousContinuous连续Normal as a first guess; real returns have fatter tailsपहले अनुमान के रूप में Normal; असली returns की tails मोटी初步可用正态;真实收益尾部更厚
⏱️ Server response timeServer response time服务器响应时间Time to respond (ms)जवाब का समय (ms)响应时间(毫秒)ContinuousContinuous连续Exponential / Gamma / Log-normal
🎯 Bayesian A/B testingBayesian A/B testing贝叶斯 A/B 测试True conversion rateअसली conversion दर真实转化率ContinuousContinuous连续Beta
🔤 Word countsWord counts词频Count of a word in a documentDocument में शब्द की गिनती文档中某词的次数DiscreteDiscrete离散Multinomial / Poisson
🧬 GenomicsGenomics基因组学Mutations per genomeहर genome में mutations每个基因组的突变数DiscreteDiscrete离散Poisson
🏠 House pricesHouse prices房价log(price)log(price)log(价格)ContinuousContinuous连续Normal after the logLog के बाद Normal取对数后近似正态
🧮
The Link to Machine Learning Loss FunctionsML Loss Functions से संबंध与机器学习损失函数的联系

Many common loss functions come from an assumed distribution. Minimising mean squared error is the same as maximum likelihood if the target is normal around the prediction with constant spread. Cross-entropy comes from a Bernoulli or categorical model. Poisson loss suits counts. (Some losses, like the hinge loss, are not built this way.) Knowing PMFs and PDFs helps you pick a loss that matches your data.

कई आम loss functions किसी माने गए distribution से आते हैं। Mean squared error घटाना maximum likelihood के बराबर है, अगर target prediction के चारों ओर normal हो और फैलाव स्थिर हो। Cross-entropy Bernoulli या categorical model से आती है। Poisson loss गिनती के लिए ठीक है। (कुछ losses, जैसे hinge loss, ऐसे नहीं बनते।) PMF और PDF की समझ से ऐसा loss चुनना आसान होता है जो आपके data से मेल खाए।

许多常见损失函数都来自某种假设的分布。若目标值围绕预测值呈方差恒定的正态分布,最小化均方误差就等价于最大似然。交叉熵来自伯努利或类别分布模型。泊松损失适合计数数据。(也有一些损失,如合页损失,并不是这样推导的。)理解 PMF 和 PDF,能帮你选出与数据相符的损失函数。


SectionSection第 15 节

The Golden Rulesसुनहरे नियम黄金法则

🎯 12 Rules Every Data Scientist Should Know12 नियम जो हर Data Scientist को पता हों每位数据科学家应知的 12 条法则
1
Decide discrete vs continuous first. It decides PMF or PDF, sums or integrals, bars or curves. (Watch for mixed variables like rainfall.)
पहले discrete या continuous तय करें। इससे PMF या PDF, योग या integral, bars या curves तय होते हैं। (Rainfall जैसे mixed variables पर ध्यान दें।)
先判断离散还是连续。这决定了用 PMF 还是 PDF、求和还是积分、柱状图还是曲线。(注意降雨这类混合变量。)
2
For a continuous variable, P(X = x) = 0 exactly. Always ask about intervals.
Continuous variable के लिए P(X = x) = 0 बिल्कुल। हमेशा intervals के बारे में पूछें।
连续变量的 P(X = x) 精确等于 0。始终问区间。
3
A PDF value is a density, not a probability. It can exceed 1. Only areas are probabilities.
PDF का मान density है, probability नहीं। यह 1 से ज़्यादा हो सकता है। सिर्फ़ areas probability हैं।
PDF 的值是密度,不是概率。它可以大于 1,只有面积才是概率。
4
The CDF works for every distribution. P(a < X ≤ b) = F(b) − F(a) is often the fastest route.
CDF हर distribution के लिए काम करती है। P(a < X ≤ b) = F(b) − F(a) अक्सर सबसे तेज़ रास्ता है।
CDF 适用于所有分布。P(a < X ≤ b) = F(b) − F(a) 往往是最快的方法。
5
Check the two rules. Non-negative, and total 1 (sum or area). If either fails, it is not a valid PMF or PDF.
दोनों नियम जाँचें। Non-negative, और कुल 1 (योग या area)। एक भी टूटे तो वह सही PMF या PDF नहीं।
检查两条规则。非负,且总和(或总面积)为 1。任一不满足,就不是合法的 PMF 或 PDF。
6
E[X] is the balance point. For a symmetric, single-peaked distribution, mean = median = mode. With a long tail, the mean is usually pulled towards the tail.
E[X] संतुलन बिंदु है। सममित, एक शिखर वाले distribution में mean = median = mode। लंबी tail हो तो mean आम तौर पर tail की ओर खिंचता है।
E[X] 是平衡点。对称单峰分布中,均值 = 中位数 = 众数。有长尾时,均值通常被拉向尾部。
7
F′(x) = f(x). The PDF is the slope of the CDF; the CDF is the area under the PDF. Same information, two forms.
F′(x) = f(x)। PDF, CDF का ढलान है; CDF, PDF के नीचे का area। वही जानकारी, दो रूप।
F′(x) = f(x)。PDF 是 CDF 的斜率,CDF 是 PDF 下的面积。同一信息,两种形式。
8
A CDF never decreases. It goes from 0 to 1. Its shape (staircase, S-curve, ramp…) depends on the distribution.
CDF कभी नहीं घटती। यह 0 से 1 तक जाती है। इसका आकार (सीढ़ी, S-curve, ढलान…) distribution पर निर्भर है।
CDF 从不下降。它从 0 走到 1,形状(阶梯、S 形、斜坡……)取决于分布。
9
Choose a distribution from how the data are made. Counts → Poisson or binomial. Proportions in (0, 1) → Beta. Time to an event → exponential or gamma. Then check the fit.
Data कैसे बनता है, उससे distribution चुनें। गिनती → Poisson या binomial। (0, 1) में अनुपात → Beta। किसी घटना तक समय → exponential या gamma। फिर fit जाँचें।
根据数据的产生机制选分布。计数 → 泊松或二项;(0, 1) 内的比例 → Beta;到某事件的时间 → 指数或伽马。然后检验拟合。
10
Standardise for normal calculations. Z = (X − μ)/σ turns any normal into N(0, 1).
Normal गणना के लिए standardise करें। Z = (X − μ)/σ किसी भी normal को N(0, 1) बना देता है।
正态计算先标准化。Z = (X − μ)/σ 把任意正态变成 N(0, 1)。
11
Poisson approximates the binomial for rare events. Large n, small p: Binomial(n, p) ≈ Poisson(np).
दुर्लभ घटनाओं के लिए Poisson, binomial का अनुमान है। बड़ा n, छोटा p: Binomial(n, p) ≈ Poisson(np)।
稀有事件下泊松近似二项。n 大、p 小时:Binomial(n, p) ≈ Poisson(np)。
12
Many ML losses hide an assumed distribution. Reading a model as a probability model helps you choose a loss that fits your data.
कई ML losses के पीछे एक माना गया distribution छिपा है। Model को probability model की तरह पढ़ने से data के अनुकूल loss चुनना आसान होता है।
许多 ML 损失背后都有一个假设分布。把模型当作概率模型来理解,有助于选择适合数据的损失函数。
🧮
You Now Have the Probabilistic Toolkitअब आपके पास Probability Toolkit है你已掌握概率工具箱

A random variable turns outcomes into numbers. The discrete/continuous split picks your language. The PMF puts probability on points; the PDF spreads it as density, with area as probability; the CDF adds it up from the left and answers every "at most" question. Together they describe any uncertain quantity — the base of every statistical model.

Random variable नतीजों को संख्याओं में बदलता है। Discrete/continuous का बँटवारा आपकी भाषा तय करता है। PMF बिंदुओं पर probability रखता है; PDF उसे density की तरह फैलाता है, जहाँ area = probability; CDF बाईं ओर से जोड़ती है और हर "ज़्यादा से ज़्यादा" सवाल का जवाब देती है। मिलकर ये किसी भी अनिश्चित मात्रा का वर्णन करते हैं — हर statistical model की नींव।

随机变量把结果变成数字。离散/连续的区分决定了你用的语言。PMF 把概率放在点上;PDF 把它铺成密度,面积即概率;CDF 从左往右累加,回答所有“至多”类问题。它们共同描述任何不确定的量 —— 这是一切统计模型的基础。