zoukankan      html  css  js  c++  java
  • 机器学习实战

    核心公式 - 贝叶斯准则

    [p(c|x) = frac{p(x|c)p(c)}{p(x)} ]

    • p(c|x) 是在x发生的情况下,c发生的概率。
    • p(x|c) 是在c发生的情况下,x发生的概率。
    • p(c) 是c发生的概率。
    • p(x) 是x发生的概率。

    规则

    如果P(c₁|x) > P(c₂|x),那么属于类别c₁。
    如果P(c₁|x) < P(c₂|x),那么属于类别c₂。

    等价变化

    [p(c1|x) = frac{p(x|c1)p(c1)}{p(x)} ]

    [p(c2|x) = frac{p(x|c2)p(c2)}{p(x)} ]

    Therefore, comparing p(c1|x) and p(c2|x)
    are same as comparing
    (frac{p(x|c1)p(c1)}{p(x)}) and (frac{p(x|c2)p(c2)}{p(x)})
    same as comparing
    (p(x|c1)p(c1)) and (p(x|c2)p(c2))

    多个独立特征的变化

    p(x|c1)中,x是多个独立特征,即(x=x_0,x_1...x_n),
    则: (p(x|c1)=p(x_0,x_1...x_n|c1))
    (p(x|c1)=p(x_0|c1)p(x_1|c1)...p(x_n|c1))

    下溢出问题

    为了解决下溢出问题,这是由于太多很小的数相乘造成的,所以程序会下溢出或者得到不正确的答案。
    在代数中有ln(a*b) = ln(a)+ln(b),于是通过求对数可以避免下溢出或者浮点数舍入导致的错误。同时,采用自然对数进行处理不会有任何损失。
    Therefore, comparing p(c1|x) and p(c2|x)
    same as comparing
    (log(p(x_0|c1)) + log(p(x_1|c1)) + ... + log(p(x_n|c1) + log(p(c1))) and
    (log(p(x_0|c2)) + log(p(x_1|c2)) + ... + log(p(x_n|c2) + log(p(c2)))

    实际应用

    • 过滤侮辱性留言
    • 过滤垃圾邮件
  • 相关阅读:
    渲染你刚刚上传的图片,再进行二次上传
    详情页需要显示图片
    上传图片
    毛利率保留俩位小数
    去除input的前后的空格
    vue下载模板、导出excle
    如何从一个对象里面拿数据
    登录注册
    ajax发送请求的数据类型
    WampServer修改MySQL密码
  • 原文地址:https://www.cnblogs.com/steven-yang/p/5592582.html
Copyright © 2011-2022 走看看