朴素贝叶斯算法规则

算法规则

癌症例子

先从一个例子出发,引出如何计算后验概率。假设你患有癌症的概率为

P(cancer) = 0.01

而你去医院检测到的出现结果的概率为

当你有癌症时,有90%的概率检测到你有癌症(positive)
当你没有癌症时,有90%的概率检测到你没有癌症(negative)

那么问题来了:如果你去医院检测到有癌症,你实际有癌症的概率是多少咧?即,

P(cancer|positive) = ?

概率求解

其实就是一条公式

先验概率 * 测试结果出现(positive或negative)概率 = 后验概率

概率

P(cancer) = 0.01
P(no cancer) = 1 -  P(cancer) = 0.99

先验概率

有癌症的情况下,不同检测结果出现的概率为

P(positive | cancer) = 0.9
P(negative | no cancer) = 0.9
P(negative | cancer) = 1 - P(negative | no cancer) = 0.1

联合概率

将概率和先验概率列出来后,可以开始进行计算,先求联合概率

P(cancer, positive) = P(cancer) * P(positive | cancer) = 0.01 * 0.9 = 0.009
P(no cancer, positive) = P(no cancer) * P(negative | no cancer) = 0.99 * 0.1 = 0.099

规范化

这一步英文叫normalize

P(positive) = P(cancer, positive) + P(no cancer, positive) = 0.108

后验概率

这里根据一开始的公式,很简单就可以求解了

P(cancer|positive) = P(cancer, positive) / P(positive) = 0.009 / 0.108 = 0.0833
P(no cancer|positive) = P(no cancer, positive) / P(positive) = 0.099 / 0.108 = 0.9167

全概率

这时,P(cancer|positive)P(no cancer|positive)加起来应该是1

P(cancer|positive) + P(no cancer|positive) = 1

以上就是整个朴素贝叶斯的算法规则

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值