📚 Bayes’ Theorem and Its Applications | 贝叶斯公式及其应用
Bayes’ Theorem is one of the most powerful and counter-intuitive results in probability. It allows us to update our beliefs about a hypothesis when new evidence arrives, and it forms the mathematical backbone of fields as diverse as medical diagnosis, spam filtering, machine learning, and even legal reasoning.
贝叶斯公式是概率论中最强大且最反直觉的结果之一。它允许我们在新证据出现时更新对某个假设的信念,并且构成了医学诊断、垃圾邮件过滤、机器学习乃至法律推理等领域的关键数学基础。
1. Conditional Probability: A Quick Review | 条件概率:快速回顾
Before we dive into Bayes’ Theorem, we must recall the definition of conditional probability. The probability that event A occurs given that event B has already occurred is written P(A|B), and is defined by the formula:
在深入贝叶斯公式之前,我们必须回顾条件概率的定义。在事件 B 已经发生的前提下,事件 A 发生的概率记为 P(A|B),其定义公式为:
P(A|B) = P(A ∩ B) / P(B), provided P(B) > 0
This formula tells us that the conditional probability is the fraction of B that also belongs to A. It is not the same as P(B|A), a distinction that lies at the heart of Bayes’ Theorem.
这个公式告诉我们,条件概率是 B 中同时也属于 A 的那部分所占的比例。它并不等于 P(B|A),而正是这一区别构成了贝叶斯公式的核心。
For example, suppose a bag contains 3 red marbles and 2 blue marbles. If one marble is drawn at random, the probability it is red is 3/5. But if we are told that the drawn marble is not blue, then the probability it is red becomes 1. The information changes the probability.
例如,假设一个袋子里有 3 个红球和 2 个蓝球。如果随机抽取一个球,它是红球的概率是 3/5。但如果我们被告知抽出的球不是蓝色的,那么它是红球的概率就变成了 1。信息改变了概率。
2. The Law of Total Probability | 全概率公式
Bayes’ Theorem relies on the Law of Total Probability. If events B₁, B₂, …, Bₙ form a partition of the sample space (they are mutually exclusive and exhaustive), then for any event A:
贝叶斯公式依赖于全概率公式。如果事件 B₁, B₂, …, Bₙ 构成样本空间的一个划分(即它们互斥且完备),那么对于任意事件 A:
P(A) = P(A|B₁)P(B₁) + P(A|B₂)P(B₂) + … + P(A|Bₙ)P(Bₙ)
Intuitively, we split the sample space into disjoint pieces, calculate the probability of A within each piece, and then add these weighted contributions together.
直观上,我们将样本空间分割成互不相交的部分,计算 A 在每个部分中的概率,然后将这些加权贡献相加。
In the simplest case with two complementary events B and Bᶜ, the law becomes P(A) = P(A|B)P(B) + P(A|Bᶜ)P(Bᶜ). This form is used constantly in Bayes’ Theorem problems.
在只有两个互补事件 B 和 Bᶜ 的最简单情形下,全概率公式变为 P(A) = P(A|B)P(B) + P(A|Bᶜ)P(Bᶜ)。在贝叶斯公式问题中这种形式经常被使用。
3. Statement of Bayes’ Theorem | 贝叶斯公式的表述
Bayes’ Theorem connects P(B|A) to P(A|B). For two events A and B, the theorem states:
贝叶斯公式将 P(B|A) 与 P(A|B) 联系起来。对于两个事件 A 和 B,公式表述为:
P(B|A) = [P(A|B) × P(B)] / P(A)
Using the Law of Total Probability to expand the denominator, we get the more complete version:
使用全概率公式展开分母,我们得到更完整的版本:
P(B|A) = [P(A|B) × P(B)] / [P(A|B)P(B) + P(A|Bᶜ)P(Bᶜ)]
Here, P(B) is called the prior probability (our belief before seeing the evidence), P(B|A) is the posterior probability (our updated belief after seeing evidence A), and P(A|B) is the likelihood.
其中,P(B) 称为先验概率(我们在看到证据之前的信念),P(B|A) 是后验概率(看到证据 A 之后更新的信念),而 P(A|B) 是似然度。
4. A Simple Derivation | 简单推导
The derivation is short. Start with the definition of conditional probability applied twice:
推导过程很短。我们从条件概率的定义出发,分别对两个方向应用:
P(A ∩ B) = P(A|B) × P(B) = P(B|A) × P(A)
Equating the two expressions for P(A ∩ B) gives P(B|A) × P(A) = P(A|B) × P(B). Dividing both sides by P(A) yields Bayes’ Theorem immediately.
将 P(A ∩ B) 的两种表达式相等,得到 P(B|A) × P(A) = P(A|B) × P(B)。两边同时除以 P(A) 即可立刻得到贝叶斯公式。
This derivation shows that Bayes’ Theorem is not a mysterious black box; it is just a rearrangement of the definition of conditional probability. What makes it useful is the interpretation: we can “reverse” the direction of conditioning.
这个推导表明贝叶斯公式并不是神秘的黑箱;它只是条件概率定义的重新排列。它的有用之处在于其解释:我们可以“反转”条件的方向。
5. Worked Example: Medical Testing | 实例演练:医学检测
A classic application involves diagnostic tests. Suppose a disease affects 1% of a population (P(D) = 0.01). A test for the disease has a 95% sensitivity: P(positive | disease) = 0.95. It also has a 90% specificity: P(negative | no disease) = 0.90. If a person tests positive, what is the probability they actually have the disease?
一个经典应用涉及诊断检测。假设某种疾病影响 1% 的人口(P(D) = 0.01)。针对这种疾病的检测具有 95% 的灵敏度:P(阳性 | 患病) = 0.95。它还有 90% 的特异度:P(阴性 | 未患病) = 0.90。如果一个人检测结果为阳性,他真正患病的概率是多少?
First, compute the probability of a positive test result using the Law of Total Probability:
首先,使用全概率公式计算检测结果为阳性的概率:
P(positive) = 0.95 × 0.01 + 0.10 × 0.99 = 0.0095 + 0.099 = 0.1085
Note that P(positive | no disease) = 1 − 0.90 = 0.10. Now apply Bayes’ Theorem:
注意 P(阳性 | 未患病) = 1 − 0.90 = 0.10。现在应用贝叶斯公式:
P(D|positive) = [0.95 × 0.01] / 0.1085 ≈ 0.0876
Surprisingly, even with a positive test, the probability of actually having the disease is only about 8.8%. Because the disease is rare, most positive results are false positives.
令人惊讶的是,即使检测结果为阳性,真正患病的概率也只有大约 8.8%。由于该疾病罕见,大多数阳性结果都是假阳性。
6. Worked Example: Spam Filtering | 实例演练:垃圾邮件过滤
Email spam filters use Bayes’ Theorem to classify messages. Suppose 20% of all emails are spam (P(spam) = 0.20). The word “win” appears in 5% of spam emails and in 0.5% of non-spam emails. If an email contains the word “win”, what is the probability it is spam?
电子邮件垃圾过滤器使用贝叶斯公式对邮件进行分类。假设 20% 的邮件是垃圾邮件(P(spam) = 0.20)。单词“win”出现在 5% 的垃圾邮件中,出现在 0.5% 的非垃圾邮件中。如果一封邮件包含“win”这个词,它是垃圾邮件的概率是多少?
Define events: S = spam, W = contains “win”. We want P(S|W). First compute P(W):
定义事件:S = 垃圾邮件,W = 包含“win”。我们要求 P(S|W)。首先计算 P(W):
P(W) = P(W|S)P(S) + P(W|Sᶜ)P(Sᶜ) = 0.05 × 0.20 + 0.005 × 0.80 = 0.01 + 0.004 = 0.014
Then apply Bayes’ Theorem:
然后应用贝叶斯公式:
P(S|W) = [0.05 × 0.20] / 0.014 ≈ 0.714
So the probability is about 71.4%. If we also see the word “free”, we can update further, which is how filters combine evidence from multiple words.
所以概率约为 71.4%。如果我们还看到“free”这个词,可以进一步更新,这正是过滤器综合多个单词证据的方式。
7. Tree Diagrams and Bayes’ Theorem | 树状图与贝叶斯公式
In A-Level exams, Bayes’ Theorem problems are often best visualised using a tree diagram. Draw the first branch for the prior events (e.g., disease or no disease), then the second branch for the test result (positive or negative). Each path probability is the product of the branch probabilities.
在 A-Level 考试中,贝叶斯公式问题通常最好用树状图来直观呈现。先画出先验事件的第一层分支(例如患病或不患病),然后画出检测结果的第二层分支(阳性或阴性)。每条路径的概率是各分支概率的乘积。
To find P(B|A), locate all paths that end in A, take the path that also includes B, and divide by the sum of all paths ending in A. This is exactly what Bayes’ Theorem computes.
为了求 P(B|A),找出所有以 A 结束的路径,取其中也包含 B 的路径,并除以所有以 A 结束的路径之和。这正是贝叶斯公式所计算的。
For example, in the medical test scenario, the relevant paths are: (disease, positive) with probability 0.0095, and (no disease, positive) with probability 0.099. The first path divided by the sum gives the posterior probability 0.0095 / 0.1085 ≈ 0.0876.
例如,在医学检测场景中,相关路径是:(患病,阳性) 的概率为 0.0095,以及 (未患病,阳性) 的概率为 0.099。第一条路径除以总和得到后验概率 0.0095 / 0.1085 ≈ 0.0876。
8. Common Mistakes and Pitfalls | 常见错误与陷阱
One frequent error is confusing P(A|B) with P(B|A). In the medical example, P(positive | disease) = 0.95, but P(disease | positive) ≈ 0.088. A student who writes 0.95 as the answer has completely missed the point of Bayes’ Theorem.
一个常见错误是混淆 P(A|B) 与 P(B|A)。在医学例子中,P(阳性 | 患病) = 0.95,但 P(患病 | 阳性) ≈ 0.088。写出 0.95 作为答案的学生完全没有理解贝叶斯公式的要旨。
Another mistake is forgetting to use the Law of Total Probability to calculate P(A) when it is not given directly. Always check whether you are given P(A) explicitly or whether you must compute it from the partition.
另一个错误是当 P(A) 没有直接给出时,忘记使用全概率公式来计算它。始终检查你是否被直接告知 P(A),还是必须从划分中计算得出。
Finally, be careful with probabilities that are given in percentages or words like “twice as likely”. Convert these correctly to decimals or fractions before substituting into the formula.
最后,小心以百分比或“可能性是两倍”等文字给出的概率。在代入公式之前,务必将它们正确转换为小数或分数。
9. Bayes’ Theorem in Real-World Contexts | 贝叶斯公式在实际情境中的应用
Beyond textbook problems, Bayes’ Theorem appears in many real-world decision-making processes.
除了教科书问题之外,贝叶斯公式还出现在许多现实世界的决策过程中。
-
Medical screening: determining the probability of disease after a positive test, as demonstrated above.
医学筛查:在检测阳性后确定患病的概率,如上所示。
-
Criminal justice: interpreting forensic evidence. The probability that a piece of evidence would appear if the defendant is innocent is not the same as the probability of innocence given the evidence.
刑事司法:解释法医证据。如果被告无辜,某项证据会出现的概率并不等于在给定证据下被告无辜的概率。
-
Machine learning: Naive Bayes classifiers power many spam filters and sentiment analysis systems.
机器学习:朴素贝叶斯分类器支撑着许多垃圾邮件过滤器和情感分析系统。
-
Finance: banks use Bayesian methods to estimate the probability of loan default based on new transaction data.
金融:银行使用贝叶斯方法基于新的交易数据来估计贷款违约的概率。
10. Summary and Key Formulas | 总结与关键公式
Bayes’ Theorem is a direct consequence of conditional probability. It allows us to update a prior probability P(B) into a posterior probability P(B|A) by incorporating the likelihood P(A|B).
贝叶斯公式是条件概率的直接推论。它允许我们通过结合似然度 P(A|B),将先验概率 P(B) 更新为后验概率 P(B|A)。
P(B|A) = P(A|B) × P(B) / P(A)
When P(A) is not known directly, use the Law of Total Probability with a partition of the sample space.
当 P(A) 无法直接得知时,使用全概率公式配合样本空间的一个划分来计算。
For A-Level exams, remember to identify the prior, the likelihood, and the total probability of the evidence. Draw a tree diagram if you are unsure. Then substitute carefully into the formula, and always sanity-check your final answer: a posterior probability should make intuitive sense given the prior and the test’s accuracy.
在 A-Level 考试中,记住识别先验概率、似然度和证据的全概率。如果不确定,画出树状图。然后仔细代入公式,并始终检查最终答案的合理性:后验概率在给定先验概率和检测准确度的情况下应当符合直觉。
Published by TutorHao | Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导