COM6005 Statistical Modeling · Module 2b
Binomial, Geometric & Poisson Distributions
COM6005 · Module 2b · Source: Module_2b_OtherDist_Class_L02_Complete.pdf (15 slides;封面標題寫 “Lecture 2c”,內容係 Binomial / Geometric / Poisson)
Contents · 7 sections
🎯 本講重點 (Learning outcomes)
- 講出三個 discrete distribution 各自「數緊咩」、parameter 同 core conditions。
- 記熟三條 PMF 公式並識手計。
- 由文字情境判斷應該用邊個 distribution(slide 10 三個 scenario)。
- 識用
stats.binom.pmf、stats.geom.pmf、stats.poisson.pmf(同.cdf)計答案。
⭐ 考試必溫 Top-5
- Summary 表(slide 8):Binomial = successes in n trials(n, p);Geometric = trials until 1st success(p);Poisson = events in an interval()。
- Binomial PMF:;Scenario 3:15 次擲硬幣得 8 個 head = 0.1964。
- Geometric PMF:;Scenario 2:80% 命中率,第 3 次先第一次入 = 0.0320;籃球 第 4 次 = 0.0864。
- Poisson PMF:;Scenario 1:,剛好 6 個 call = 0.1281。
- scipy 寫法:
poisson.pmf(6,4.5)、geom.pmf(3,0.8)、binom.pmf(8,15,0.5)。
1. Binomial Distribution
- What it measures:The number of successes (X) out of a fixed total number of independent trials (n).
- Key parameters:n = number of trials;p = probability of success on any given trial.
- Core conditions:Each trial has only two outcomes, the probability p is constant, and all trials are independent.
- Example:Flipping a coin 10 times and counting the exact k number of heads (),X 可以係 0, 1, 2, …, 10。
每部分嘅意思(slide 9):
- (Combination):由 n 次 trials 揀邊 k 次成功嘅方法數。
- :k 次成功嘅 probability。
- :其餘 次失敗嘅 probability。
想像 10 次擲硬幣,「HHTHT…」任何一個特定序列(有 k 個 H)嘅機率都係 ;而有 k 個 H 嘅序列有 個,所以相乘。
Slides 3、5、7 係 Wikipedia 上 Binomial / Geometric / Poisson distribution 嘅公式截圖(infobox),文字擷取不到;公式本身已喺 slide 9 列出,本頁已收錄。
2. Geometric Distribution
- What it measures:The total number of trials (X) needed until the first success occurs.
- Key parameter:p = probability of success on each trial.
- Core conditions:Trials are independent, each has two outcomes, and the experiment stops immediately once the first success happens.
- Example:Rolling a six-sided die repeatedly until you finally roll a 6.
- :頭 次連續失敗。
- :第 k 次(最後一次)成功。
。 → 頭 3 次失敗,第 4 次成功:
- 指數係 (唔係 k):第 k 次成功之前只有 次失敗。
- 本課(同
scipy.stats.geom)用嘅定義係「總 trial 數」,k 由 1 開始。有啲書用「失敗次數」定義(由 0 開始),公式會變成 ,小心題目寫法。
3. Poisson Distribution
- What it measures:The number of times a discrete event occurs over a fixed period of time or space.
- Key parameter: (lambda) = the average rate of occurrence in that interval.
- Core conditions:Events occur independently, the average rate is constant, and two events cannot happen at the exact same instant.
- Example:Counting the number of emails you receive in an hour.
= 時段內平均次數;(Euler's constant); = k 嘅 factorial。
一定要配合題目嘅時段:如果「平均每分鐘 4.5 個 call」而題目問「2 分鐘內」,就要用 。Poisson 冇上限(k 可以去到無限),Binomial 最多 n。
4. Summary:三個 distribution 點分?
| Feature | Binomial | Geometric | Poisson |
|---|---|---|---|
| What is counted? | Number of successes in n trials | Number of trials until 1st success | Number of events in an interval |
| Fixed limit? | Fixed number of trials (n) | No fixed limit (stops at success) | Fixed interval of time/space |
| Main Parameters | n and p | p | (lambda) |
| Range of X(slide 9) | 1, 2, 3, … | 0, 1, 2, … | |
| PMF | |||
| scipy | stats.binom.pmf(k, n, p) | stats.geom.pmf(k, p) | stats.poisson.pmf(k, mu) |
- 題目有「n 次中有 k 次」→ Binomial。
- 題目有「直到第一次」、「第 k 次先成功」→ Geometric。
- 題目有「平均每(小時/分鐘/平方米) 次」,冇 n → Poisson。
補充(slides 冇列,但常用):Binomial 、;Geometric ;Poisson 。Module 2c 嘅 approximation 會用到 同 。
5. Worked examples(slides 10–15)
Slide 10 三個 scenario:
- Scenario 1:Call center 平均每分鐘 4.5 個 call,求下一分鐘剛好 6 個 call 嘅 probability。
- Scenario 2:籃球員罰球命中率 80%,求佢頭兩球唔入、第三球先第一次入嘅 probability。
- Scenario 3:硬幣擲 15 次,求剛好 8 次 head 嘅 probability。
Why:counting independent events (calls) in a fixed interval of time (1 minute) given an average rate 。
Result:12.81% chance the center receives exactly 6 calls in the next minute.
Why:independent trials with constant success rate until the very first success on the 3rd attempt ()。
Result:3.20% chance the first successful shot happens exactly on the third try.
Why:fixed number of independent trials (), constant , specific number of successes ()。
Result:19.64% chance of exactly 8 heads out of 15 flips.
5.1 Python code(slides 14–15)
Slide 14 係填充題(stats.XXX.pmf(??)),slide 15 係答案:
import scipy.stats as stats
# Scenario 1: Poisson,k = 6,λ = 4.5
prob1 = stats.poisson.pmf(6, 4.5)
print(f"Scenario 1 - Probability: {prob1:.4f}") # 0.1281
# Scenario 2: Geometric,k = 3,p = 0.8
prob2 = stats.geom.pmf(3, 0.8)
print(f"Scenario 2 - Probability: {prob2:.4f}") # 0.0320
# Scenario 3: Binomial,k = 8,n = 15,p = 0.5
prob3 = stats.binom.pmf(8, 15, 0.5)
print(f"Scenario 3 - Probability: {prob3:.4f}") # 0.1964
scipy 一律係 先 k,後 parameter:binom.pmf(k, n, p)、geom.pmf(k, p)、poisson.pmf(k, mu)。寫錯次序(例如 binom.pmf(15, 8, 0.5))會得到 0。
5.2 延伸練習:「至少/最多」要用 CDF
- Scenario 1 延伸:最多 2 個 call:(
stats.poisson.cdf(2, 4.5));至少 3 個 。 - Scenario 2 延伸:3 球內入到第一球:(
stats.geom.cdf(3, 0.8))。 - Scenario 3 延伸:至少 1 個 head:。
Binomial 係 Logistic regression(Module 1 提到用嚟做 classification)背後嘅 distribution:每個觀測值係一次 Bernoulli trial(Yes/No)。COM6004 Classification 評估 accuracy 時,test set 上「答啱幾多個」亦可以當 Binomial 去理解。
自我測驗 Self-test
Q1. 一間店平均每小時有 3 個客投訴。求某一小時冇人投訴嘅 probability。
Poisson,:。Python:stats.poisson.pmf(0, 3)。
Q2. 一條選擇題有 4 個選項,學生亂估 10 題。求剛好答啱 3 題嘅 probability。
Binomial,,:。
Q3. 某人每次打電話搵到客服嘅機會係 0.3。求佢第 5 次先第一次接通嘅 probability。
Geometric,,:。
Q4. 擲公平骰子直至出 6。求第 2 次就出 6 嘅 probability。
。
Q5. 某網站平均每分鐘 2 次 visit,求 3 分鐘內剛好 5 次 visit 嘅 probability。
3 分鐘 → :。
Q6. 以下邊個唔符合 Binomial 條件?(a) 由一副牌唔放返咁抽 5 張,數有幾多張紅心 (b) 擲 20 次硬幣數 head
(a) 唔符合:唔放返 → 每次 p 會變,trials 唔 independent(應該用 hypergeometric)。(b) 符合。
Q7. 寫出 Scenario 1–3 嘅 scipy code,並講出 “k” 喺每個 function 係邊個 argument。
stats.poisson.pmf(6, 4.5)、stats.geom.pmf(3, 0.8)、stats.binom.pmf(8, 15, 0.5);k 一律係第一個 argument。
Q8. :求 。
。Python:1 - stats.binom.cdf(13, 15, 0.5)。
一頁總結 Cheat sheet
- Binomial(n, p):n 次 independent trials 中成功次數;兩個結果、p 固定。,。
- Geometric(p):直到第一次成功嘅 trial 數。,
- Poisson():固定時間/空間內事件數。,; 要跟時段調整。
- Scenario 答案:Poisson(4.5) ;Geom(0.8) ;Binom(15, 0.5) ;Geom(0.4) 。
- scipy:
binom.pmf(k,n,p)、geom.pmf(k,p)、poisson.pmf(k,mu);累積用.cdf;「至少」。 - 補充:Binomial mean 、var ;Geometric mean ;Poisson 。