25 / 90

第 25 天:機率基礎:事件、條件機率與貝氏

在明確的樣本空間中計數,透過條件化縮小樣本空間,用貝氏公式反向求解,並區分經驗頻率與有保證的機率。預測、證據與恢復均計入 480 分鐘台帳。

數學與演算法基礎 480 分鐘(8 小時專注學習)
01 120 分鐘

樣本空間、事件與計數

僅在記錄預測與觀察證據後才允許輔助。

前置要求

完成第 24 天(線性代數收尾);如遇阻塞,請先複習第 21 天,再繼續。

學習目標

定義樣本空間,列舉等可能結果,並在明確陳述的公平性與獨立性假設下以計數求事件機率。

操作指引

學習來源:在本活動現有的閱讀與練習時段內,參考 Stat 110: Strategic Practice and Homework Problems 的 Strategic Practice and Homework 1; linked problem and solution document,用自己的話解釋一處與本地任務的聯繫。保留現有練習與驗收檢查;若外部資料無法存取,使用課程自寫的解釋。機率模型假設由等可能結果組成的樣本空間 $\Omega$,並賦予事件 $A$ 機率 $P(A) = |A|/|\Omega|$。兩顆公平且相互獨立的六面骰共有 36 個有序對 $(a,b)$,每個機率為 $1/36$。僅有公平的邊際分布還不夠:若兩骰總是相同點數,和為 7 的機率是 0,至少一個為 6 的機率是 $1/6$。必做:先預測個數,再列舉和為 7 的對與至少含一個 6 的對(用容斥原理避免重複計算 $(6,6)$)。選做:必做證據齊全後,再以三枚硬幣重複此計數練習。

自主實作與記錄

對兩顆公平且相互獨立的六面骰(每個有序對的機率為 $1/36$),先預測再計算:(a) $P(\text{和}=7)$;(b) $P(\text{至少一顆為 }6)$。每個答案寫成 36 個有序對的分數與小數,並說明所依據的公平性與獨立性假設。

獨立掌握標準

樣本空間寫為 36 個有序對;兩個機率都在明確陳述每顆骰子公平且兩骰獨立(等價於每個有序對機率為 $1/36$)的假設下由計數推出,而非背誦。

權威來源資源與權利證明

linking Harvard University copyright; no open reuse license verified linking only; no reproduction

Stat 110: Strategic Practice and Homework Problems

作者 / 機構: Joe Blitzstein (Harvard University) | 原始出處連結 ↗

對應章節 / 時間戳: Strategic Practice and Homework 1; linked problem and solution document

驗證版本與日期: Public edition checked 2026-11-01; moving pages may change

入選理由:

Concept-organized questions plus solutions supply probability teaching practice missing from reference notes. Use early sets, not an entire semester or an unverified free textbook.

來源前置條件:

Counting, fractions and the Day 25 probability definitions; use only the identified early problems.

安全回退方案(離線彈性):

Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.

對比候選資源與選型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Retained for accessible definitions and a full statistics sequence; Stat 110 adds targeted probability practice.

OpenIntro Statistics ↗ compared_alternative [CC BY-SA 3.0]

Comparable introductory statistics text; remains a supplementary reference for estimation rather than replacing concept-targeted probability practice.

linking CC BY-NC-SA 4.0 noncommercial share-alike

Introductory Statistics 2e

作者 / 機構: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 3: Probability Topics (sample spaces, events, equally likely outcomes)

驗證版本與日期: 2e web edition (Verified: 2026-10-30)

入選理由:

Peer-reviewed open textbook with beginner-grade rigor for sample spaces and counting-based probability.

來源前置條件:

High-school algebra

安全回退方案(離線彈性):

All required definitions, counts, and worked answers are reproduced locally in this lesson.

對比候選資源與選型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 機構: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出處連結 ↗

對應章節 / 時間戳: Section 2: Probability spaces, events, and axioms

驗證版本與日期: 2020 public course notes (Verified: 2026-10-30)

入選理由:

Compact machine-learning-oriented probability review connecting axioms to model assumptions.

來源前置條件:

Multivariate calculus notation exposure

安全回退方案(離線彈性):

Self-contained definitions and derivations in activity instructions and offline guide.

對比候選資源與選型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.

02 120 分鐘

條件機率與獨立性

獨立掌握檢查(無 AI 輔助)。

前置要求

完成上一項活動;如遇阻塞,請先按活動 01 的指引複習第 21 天,再繼續。

學習目標

透過縮小樣本空間計算 $P(A\mid B)=P(A\cap B)/P(B)$,並以乘積恆等式 $P(A\cap B)=P(A)P(B)$ 驗證獨立性。

操作指引

學習來源:在本活動現有的閱讀與練習時段內,參考 Stat 110: Strategic Practice and Homework Problems 的 Strategic Practice and Homework 2: Conditional Probability; problems and solutions,用自己的話解釋一處與本地任務的聯繫。保留現有練習與驗收檢查;若外部資料無法存取,使用課程自寫的解釋。以 $B$ 為條件會把樣本空間縮小到 $B$ 並重新正規化:在縮小後的空間內計數,而不是死記公式。必做:獨立完成 (a)-(c),並寫出每題所用的受限樣本空間。獨立性是要驗證的數值恆等式,不是要斷言的直覺。

自主實作與記錄

兩顆公平且相互獨立的骰子(每個有序對的機率為 $1/36$)。(a) 已知第一顆為偶數,求 $P(\text{和}=8)$。(b) 已知和為 7,求 $P(\text{第一顆}=4)$。(c)「第一顆為偶數」與「和為 7」是否獨立?比較 $P(\text{偶數})\cdot P(\text{和}=7)$ 與 $P(\text{偶數}\cap\text{和}=7)$。

獨立掌握標準

三個結果都由受限計數獨立推出;每部分指明所用條件集合;僅在做完乘積檢驗 $1/12 = 3/36$ 後才斷言獨立。

權威來源資源與權利證明

linking Harvard University copyright; no open reuse license verified linking only; no reproduction

Stat 110: Strategic Practice and Homework Problems

作者 / 機構: Joe Blitzstein (Harvard University) | 原始出處連結 ↗

對應章節 / 時間戳: Strategic Practice and Homework 2: Conditional Probability; problems and solutions

驗證版本與日期: Public edition checked 2026-11-01; moving pages may change

入選理由:

Concept-organized questions plus solutions supply probability teaching practice missing from reference notes. Use early sets, not an entire semester or an unverified free textbook.

來源前置條件:

Counting, fractions and the Day 25 probability definitions; use only the identified early problems.

安全回退方案(離線彈性):

Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.

對比候選資源與選型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Retained for accessible definitions and a full statistics sequence; Stat 110 adds targeted probability practice.

OpenIntro Statistics ↗ compared_alternative [CC BY-SA 3.0]

Comparable introductory statistics text; remains a supplementary reference for estimation rather than replacing concept-targeted probability practice.

linking CC BY-NC-SA 4.0 noncommercial share-alike

Introductory Statistics 2e

作者 / 機構: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 3: Probability Topics (conditional probability, independence)

驗證版本與日期: 2e web edition (Verified: 2026-10-30)

入選理由:

Clear treatment of conditional probability via restricted sample spaces matching this activity's method.

來源前置條件:

High-school algebra

安全回退方案(離線彈性):

All required definitions, counts, and worked answers are reproduced locally in this lesson.

對比候選資源與選型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 機構: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出處連結 ↗

對應章節 / 時間戳: Section 3: Conditional probability and independence

驗證版本與日期: 2020 public course notes (Verified: 2026-10-30)

入選理由:

ML-oriented reference for the independence product rule used later in model assumptions.

來源前置條件:

Multivariate calculus notation exposure

安全回退方案(離線彈性):

Self-contained definitions and derivations in activity instructions and offline guide.

對比候選資源與選型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.

03 120 分鐘

貝氏公式與經驗頻率對機率

僅在記錄預測與觀察證據後才允許輔助。

前置要求

完成上一項活動;如遇阻塞,請先按活動 01 的指引複習第 21 天,再繼續。

學習目標

以全機率分母應用貝氏公式 $P(D\mid +)=P(+\mid D)P(D)/P(+)$,並執行固定種子的模擬以區分經驗頻率與有保證的機率。

操作指引

篩檢範例:患病率 $P(D)=0.01$,靈敏度 $P(+\mid D)=0.99$,偽陽性率 $P(+\mid \bar D)=0.05$。先用全機率公式求 $P(+)$,再求 $P(D\mid +)$。然後執行:python3 -c "import random; random.seed(25); pairs=[(random.randint(1,6), random.randint(1,6)) for _ in range(36)]; print(sum(1 for a,b in pairs if a+b==7))",把觀察到的和 7 頻率與 $1/6$ 比較。

自主實作與記錄

(a) 計算該篩檢情境的 $P(D\mid +)$。(b) 報告 36 對模擬中和為 7 的觀察頻率,並解釋它為何不必等於 $1/6$。(c) 若某事件在 $n$ 次試驗中從未出現,其機率是否恰為 0?

獨立掌握標準

貝氏計算展示全機率分母;模擬頻率如實報告;零計數告誡與頻率/機率區分用自己的話陳述。

權威來源資源與權利證明

linking CC BY-NC-SA 4.0 noncommercial share-alike

Introductory Statistics 2e

作者 / 機構: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 3: Probability Topics (Bayes' rule, law of total probability); Chapter 1 (relative frequency)

驗證版本與日期: 2e web edition (Verified: 2026-10-30)

入選理由:

Open treatment of Bayes' rule and the relative-frequency interpretation of probability.

來源前置條件:

High-school algebra

安全回退方案(離線彈性):

All required definitions, counts, and worked answers are reproduced locally in this lesson.

對比候選資源與選型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking PSF License Version 2

Python 3 random: Generate pseudo-random numbers

作者 / 機構: Python Software Foundation | 原始出處連結 ↗

對應章節 / 時間戳: random.seed, random.randint, random.choices (reproducible simulations)

驗證版本與日期: Python 3.12 documentation (Verified: 2026-10-30)

入選理由:

Normative reference for seeded pseudo-random sampling used in the empirical-frequency experiment.

來源前置條件:

Basic Python syntax

安全回退方案(離線彈性):

Use the installed interpreter's help(random) and the included deterministic commands.

對比候選資源與選型分析 (2)
NumPy random Generator documentation ↗ compared_deferred [BSD 3-Clause]

Faster vectorized sampling but adds a third-party dependency before the tensor track; deferred to the models-and-training days.

Python secrets module documentation ↗ compared_rejected_for_days_25_27 [PSF License Version 2]

Cryptographically secure randomness is unnecessary for reproducible statistical pedagogy and obscures the seed-based determinism the exercises require.

04 120 分鐘

獨立掌握檢查:機率基礎

獨立掌握檢查(無 AI 輔助)。

前置要求

完成上一項活動;如遇阻塞,請先按活動 01 的指引複習第 21 天,再繼續。

學習目標

獨立求解未見過的機率題,並明確陳述所用的每條假設(先驗、概似、獨立性)。

操作指引

本檢查期間不使用 AI、參考資料或超出四則運算的計算工具。解出全部三題,驗證前先記錄預測,再複盤錯誤並對遺漏概念走恢復連結。 保留首次無協助嘗試且不做改動;此後的錯題複盤和任何協助式補救是單獨階段,遺漏的概念須通過一次答案事先不展示的新同等無協助檢查,才算已補救。 第二次檢查(僅在補救之後;無協助、無提示):(a) $P(\text{spam})=0.3$,$P(w\mid\text{spam})=0.8$,$P(w\mid\text{ham})=0.2$,求 $P(\text{spam}\mid w)$。(b) 從 52 張牌中無放回抽兩張,求 $P(\text{兩張都是紅心})$。(c) 對使用兩個詞 $w_1,w_2$ 的樸素貝氏評分,寫出它假設的分解式,並給出一個它在真實文本中不成立的原因。本卡片不給出第二次檢查的答案:按與掌握標準相同的標準評分(由所述模型得出的精確值,寫明每個假設),並只在做完後用另一種方法(1000 封郵件的頻數表,或有序對計數)核對。(a) 出錯用 day-25-act-03(貝氏定理、全機率分母)補救,(b) 用 day-25-act-02(相依事件)和 day-25-act-01(計數),(c) 用 day-25-act-02(獨立性)。

自主實作與記錄

(a) 垃圾郵件篩選器:$P(\text{spam})=0.2$,可疑詞 $w$ 滿足 $P(w\mid\text{spam})=0.9$、$P(w\mid\text{ham})=0.1$,求 $P(\text{spam}\mid w)$。(b) 從 52 張牌中無放回抽兩張,求 $P(\text{兩張都是 A})$。(c) 對於一個用多個可疑詞特徵為郵件評分的多特徵樸素貝氏分類器,說明它額外引入的條件獨立假設,並評價其是否現實。((a) 只用單個特徵,其後驗僅由貝氏定理得出。)

獨立掌握標準

獨立答案與 $9/13$、$1/221$ 一致;明確陳述所設模型(先驗、概似、條件獨立、無放回抽樣);錯題接入恢復連結,且每個遺漏概念須經一次新的同等無協助檢查才算補救。

權威來源資源與權利證明

linking CC BY-NC-SA 4.0 noncommercial share-alike

Introductory Statistics 2e

作者 / 機構: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 3: Probability Topics (review problems)

驗證版本與日期: 2e web edition (Verified: 2026-10-30)

入選理由:

Open end-of-chapter review coverage aligned with this day's assessment scope.

來源前置條件:

High-school algebra

安全回退方案(離線彈性):

The assessment is self-contained with original items and worked reference answers.

對比候選資源與選型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 機構: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出處連結 ↗

對應章節 / 時間戳: Sections 2-3: axioms, conditional probability, Bayes' rule

驗證版本與日期: 2020 public course notes (Verified: 2026-10-30)

入選理由:

Reference for the probability toolkit this assessment checks without assistance.

來源前置條件:

Multivariate calculus notation exposure

安全回退方案(離線彈性):

The assessment is self-contained with original items and worked reference answers.

對比候選資源與選型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.