博客
关于我
曲奇饼问题
阅读量:751 次
发布时间:2019-03-22

本文共 707 字,大约阅读时间需要 2 分钟。

使用贝叶斯公式计算条件概率

案例背景

碗1和碗2各放30个香草曲奇饼和10个巧克力曲奇饼,分别与10个香草曲奇饼和10个巧克力曲奇饼。我们需要计算从碗1取出香草曲奇饼的概率。

通过贝叶斯定理,可以得到公式:[ P(B_1|V) = \frac{P(B_1) \cdot P(V|B_1)}{P(V)} ]

其中:

  • ( B_1 ):碗1。
  • ( V ):取出的是香草曲奇饼。

概率定义

  • ( P(B_1) = 0.5 )(碗1被选中的概率)。
  • ( P(V|B_1) = \frac{30}{40} = 0.75 )(从碗1中取到香草曲奇饼的概率)。
  • ( P(V) ):取到香草曲奇饼的总概率。
  • 计算总概率

    总样本空间为两个碗,每个碗有40个曲奇饼,总共80个曲奇饼。其中:

    • 香草曲奇饼总数:30(碗1) + 10(碗2)= 40个。
    • 巧克力曲奇饼总数:10(碗1) + 10(碗2)= 20个。

    因此:[ P(V) = \frac{40}{80} = 0.5 ]

    计算条件概率

    代入贝叶斯公式:[ P(B_1|V) = \frac{0.5 \cdot 0.75}{0.5} = 0.6 ]

    即,从碗1中取到香草曲奇饼的概率为60%。

    Python验证

    from thinkbayes import Pmfpmf = Pmf()pmf.Set('Bow1', 0.5)pmf.Set("Bow2", 0.5)pmf.Mult('Bow1', 0.75)pmf.Mult('Bow2', 0.5)pmf.Normalize()print(pmf.Prob('Bow1'))

    输出结果为:

    0.6

    验证结果正确,说明计算无误。

    转载地址:http://eigwk.baihongyu.com/

    你可能感兴趣的文章
    Prometheus 安装部署实战
    查看>>
    prometheus 持久化存储方案
    查看>>
    Prometheus 监控系统企业级实战
    查看>>
    Prometheus 监控系统简介
    查看>>
    Prometheus 配置详解
    查看>>
    Prometheus 采集器使用详解
    查看>>
    Prometheus 黑盒监控实战
    查看>>
    prometheus+alertmanager+grafana监控部署教程
    查看>>
    Prometheus+Grafana构建智能化Kubernetes监控系统实战
    查看>>
    Prometheus+SpringBoot应用监控全过程详解
    查看>>
    Prometheus+SpringBoot应用监控全过程详解
    查看>>
    prometheus安装
    查看>>
    Prometheus实战教程:监控Kafka消息
    查看>>
    Prometheus实战教程:监控mysql数据库
    查看>>
    Prometheus实战教程:监控Nginx状态
    查看>>
    prometheus常用exporter下载地址大全
    查看>>
    Prometheus快速搭建与监控Linux系统实战
    查看>>
    prometheus报警与恢复告警的格式
    查看>>
    Pytorch中安装 torch_geometric 详细图文操作(全)
    查看>>
    prometheus监控docker容器实战
    查看>>