AI学习-day2
- 网站:elementsofai/3/2
- 贝叶斯规则
先验概率和后验概率
贝叶斯规则可以用多种形式来表达。最简单的一种是用几率来表达。这个想法是取某事发生的几率(不发生的几率),我们称之为先验几率。先验这个词指的是我们在获得一些可能相关的新信息之前对几率的评估。这个公式的目的是当有新信息可用时更新先验几率,以获得后验几率,即获得信息后的几率(后验的字典含义是“后来发生的事情”。)
Prior and posterior odds
The Bayes rule can be expressed in many forms. The simplest one is in terms of odds. The idea is to take the odds for something happening (against it not happening), which we’ll call prior odds. The word prior refers to our assessment of the odds before obtaining some new information that may be relevant. The purpose of the formula is to update the prior odds when new information becomes available, to obtain the posterior odds, or the odds after obtaining the information (the dictionary meaning of posterior is “something that comes after, later”.)
举个栗子🌰:疾病检测
假设有一种罕见疾病,人群中患病率是1%(这是先验概率)。现在有一种检测方法:
- 如果真的有病,检测结果呈阳性的概率是90%(真阳性率);
- 如果没病,检测误判为阳性的概率是5%(假阳性率)。
问题:如果一个人检测结果是阳性,他真实患病的概率是多少?
用贝叶斯定理计算后会发现,这个概率其实只有约 16%(后验概率),远低于直觉以为的90%。这是因为患病率很低(先验概率低),即使检测有一定准确性,误报的绝对数量也可能远超真实患者。
我们将前面的疾病检测例子代入贝叶斯定理公式,详细解释每个部分对应的实际含义。贝叶斯定理的公式如下:
用例子中的符号替换为:
- <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>A</mi></mrow></semantics></math>A: 患病
- <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>B</mi></mrow></semantics></math>B: 检测为阳性
则公式变形为:
逐项解析公式中的每一部分
1. <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(患病):先验概率
- 含义:在没有检测结果前,这个人患病的初始概率。
- 例子中的值:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mi mathvariant="normal">%</mi><mo>=</mo><mn>0.01</mn></mrow></semantics></math>P(患病)=1%=0.01
2. <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mtext>患病</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性∣患病):似然概率
- 含义:当一个人确实患病时,检测结果为阳性的概率。
- 例子中的值:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mtext>患病</mtext><mo stretchy="false">)</mo><mo>=</mo><mn>90</mn><mi mathvariant="normal">%</mi><mo>=</mo><mn>0.9</mn></mrow></semantics></math>P(阳性∣患病)=90%=0.9
3. <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性):证据的总概率
- 含义:无论是否患病,检测结果为阳性的总概率。需要同时考虑 真阳性 和 假阳性。
- 计算方法(全概率公式):<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mstyle mathsize="0.9em"><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo><mo>=</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mtext>患病</mtext><mo stretchy="false">)</mo><mo>⋅</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mo stretchy="false">)</mo><mo>+</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mtext>不患病</mtext><mo stretchy="false">)</mo><mo>⋅</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>不患病</mtext><mo stretchy="false">)</mo></mstyle></mrow></semantics></math>P(阳性)=P(阳性∣患病)⋅P(患病)+P(阳性∣不患病)⋅P(不患病)
- 代入数据:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mstyle mathsize="0.9em"><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo><mo>=</mo><mn>0.9</mn><mo>×</mo><mn>0.01</mn><mo>+</mo><mn>0.05</mn><mo>×</mo><mn>0.99</mn><mo>=</mo><mn>0.009</mn><mo>+</mo><mn>0.0495</mn><mo>=</mo><mn>0.0585</mn>
<mo stretchy="false">(</mo><mn>5.85</mn><mi mathvariant="normal">%</mi><mo stretchy="false">)</mo></mstyle></mrow></semantics></math>P(阳性)=0.9×0.01+0.05×0.99=0.009+0.0495=0.0585(5.85%)
4. <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mi mathvariant="normal">∣</mi><mtext>阳性</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(患病∣阳性):后验概率
- 含义:在检测结果为阳性的条件下,这个人真实患病的概率。
- 最终计算:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mstyle mathsize="0.9em"><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mi mathvariant="normal">∣</mi><mtext>阳性</mtext><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><mn>0.9</mn><mo>×</mo><mn>0.01</mn></mrow><mn>0.0585</mn></mfrac><mo>=</mo><mfrac><mn>0.009</mn><mn>0.0585</mn></mfrac><mo>≈</mo><mn>0.1538</mn>
<mo stretchy="false">(</mo><mo>≈</mo><mn>15.38</mn><mi mathvariant="normal">%</mi><mo stretchy="false">)</mo></mstyle></mrow></semantics></math>P(患病∣阳性)=0.05850.9×0.01=0.05850.009≈0.1538(≈15.38%) - 例子中的结果:约15.38%(例子中简化为16%)。
实际意义总结表
公式中的项 | 实际意义 | 例子中的值 |
---|---|---|
<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(患病) | 先验概率(初始患病率) | 1% |
<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∥</mi><mtext>患病</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性∥患病) | 真阳性率(检测准确性) | 90% |
<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性) | 总阳性概率(真+假阳性的综合结果) | 5.85% |
<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>患病</mtext><mi mathvariant="normal">∥</mi><mtext>阳性</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(患病∥阳性) | 后验概率(真实患病的可能性) | ≈15.38% |
关键结论
- 为什么后验概率低?
即使检测准确性高(90%的真阳性率),由于疾病本身罕见(先验概率仅1%),大量未患病者(99%)会出现假阳性(5%的假阳性率)。假阳性数量(0.05×99≈4.95人)远多于真阳性(0.01×0.9≈0.09人),导致阳性结果中真患者比例大幅降低。 - 贝叶斯定理的核心:通过数学将 先验信念(1%患病率)与 新证据的可靠性(真/假阳性率)结合,修正我们对事件的判断(后验概率)。它告诉我们:忽视基础概率会导致严重误判。
全概率公式计算P(阳性)的核心在于穷尽所有可能路径并加权求和,具体原因如下:
- 互斥且穷尽的划分
当计算某事件的总概率(如检测为阳性)时,需将样本空间划分为互斥且完备的场景。例如,在疾病检测中,个体要么患病(<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>D</mi></mrow></semantics></math>D),要么未患病(<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">¬</mi><mi>D</mi></mrow></semantics></math>¬D)。这两个事件覆盖所有可能性且互不重叠,形成完备事件组。 - 条件概率的加权和
阳性结果可能来源于两类情况:- 真阳性:患病并被正确检测为阳性,概率为 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi>D</mi><mo stretchy="false">)</mo><mo>⋅</mo><mi>P</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性∣D)⋅P(D);
- 假阳性:未患病但被误判为阳性,概率为 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo><mo>⋅</mo><mi>P</mi><mo stretchy="false">(</mo><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性∣¬D)⋅P(¬D)。
由于这两种情况互斥且穷尽所有阳性结果的来源,其总概率为二者的加权和:
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo><mo>=</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi>D</mi><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo><mo>+</mo><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性)=P(阳性∣D)P(D)+P(阳性∣¬D)P(¬D)其中权重 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo></mrow></semantics></math>P(D) 和 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo></mrow></semantics></math>P(¬D) 反映不同群体在总体中的比例。
- 实例验证逻辑正确性
举例:患病率 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mi mathvariant="normal">%</mi></mrow></semantics></math>P(D)=1%,真阳性率 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><mn>99</mn><mi mathvariant="normal">%</mi></mrow></semantics></math>P(阳性∣D)=99%,假阳性率 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mi mathvariant="normal">∣</mi><mi mathvariant="normal">¬</mi><mi>D</mi><mo stretchy="false">)</mo><mo>=</mo><mn>5</mn><mi mathvariant="normal">%</mi></mrow></semantics></math>P(阳性∣¬D)=5%,则:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>阳性</mtext><mo stretchy="false">)</mo><mo>=</mo><mn>0.99</mn><mo>×</mo><mn>0.01</mn><mo>+</mo><mn>0.05</mn><mo>×</mo><mn>0.99</mn><mo>=</mo><mn>0.0594</mn><mo stretchy="false">(</mo><mtext>即5.94%</mtext><mo stretchy="false">)</mo></mrow></semantics></math>P(阳性)=0.99×0.01+0.05×0.99=0.0594(即5.94%) 总阳性概率中,假阳性占比高达约83%(<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>0.0495</mn><mn>0.0594</mn></mfrac><mo>≈</mo><mn>83</mn><mi mathvariant="normal">%</mi></mrow></semantics></math>0.05940.0495≈83%),说明全概率公式能客观反映基数差异的影响。
- 数学本质与扩展性
全概率本质是计算条件概率的期望值,即:<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>A</mi><mo stretchy="false">)</mo><mo>=</mo><munder><mo>∑</mo><mi>i</mi></munder><mi>P</mi><mo stretchy="false">(</mo><mi>A</mi><mi mathvariant="normal">∣</mi><msub><mi>B</mi><mi>i</mi></msub><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><msub><mi>B</mi><mi>i</mi></msub><mo stretchy="false">)</mo></mrow></semantics></math>P(A)=i∑P(A∣Bi)P(Bi)通过将事件分解为独立的路径,能适应更复杂场景(如多状态分类),关键在于确保事件组 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">{</mo><msub><mi>B</mi><mi>i</mi></msub><mo stretchy="false">}</mo></mrow></semantics></math>{Bi} 互斥且穷尽。
结论:全概率公式通过分解事件为互斥路径并加权求和,确保了所有潜在因素均被合理纳入计算,从而准确地得出总概率。这一方法避免了直接平均或单一场景分析的偏误,是计算复合事件概率的严谨数学工具。
- 点赞
- 收藏
- 关注作者
评论(0)