DAY6 Naive Bayes

Naive Bayes foundation

basic concept:

Conditional probability: refers to the event  A  in another event  B  probability condition has occurred

 

 

Bayes' theorem : P ( A B ) = P ( A | B ) * P ( B ) --->

Prior probability : prior probability (Prior Probability) refers to the probability obtained based on past experience and analysis. For example, in the above formula  P ( A ) , P ( B ) P (A), P (B), another example: the X-  represents a vote even texture coins, the probability of a positive upward, apparently based on our past experience next, we will consider  X probability  P ( X ) = 0.5 P (X) = 0.5. Where  P ( X- ) = 0.5 P (X-) = a priori probability is 0.5.

Posteriori probability : posterior probability (Posterior Probability) is a reverse conditional probability of incident request; i.e., reverse conditional probabilities based on prior probabilities by Bayes formula obtained. For example, the formula  P (B|A) is through the prior probability  P ( A ) and P ( B ) posterior probability P (B) was obtained, and the popular talk is "seeking enforcement fruit because" in "because" .

Naive Bayes :

Naive Bayes is "simple", ie independent condition, said its forecast assumed that the individual properties are independent of each other, each property independently affect the classification results for the forecast data, solving property in the forecast data appears the probability of occurrence for each category, the probability of large value category as a class prediction data

Algorithm:

"""生成示例数据
"""
import pandas as pd


def create_data():
    data = {"x": ['r', 'g', 'r', 'b', 'g', 'g', 'r', 'r', 'b', 'g', 'g', 'r', 'b', 'b', 'g'],
            "y": ['m', 's', 'l', 's', 'm', 's', 'm', 's', 'm', 'l', 'l', 's', 'm', 'm', 'l'],
            "labels": ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B']}
    data = pd.DataFrame(data, columns=["labels", "x", "y"])
    return data
data = create_data()
data
 

参数估计

根据朴素贝叶斯的原理,最终分类的决策因素是比较 P(1),P(2),,P(m) 各个概率的大小,根据贝叶斯公式得知每一个概率计算的分母 P()P(特征) 都是相同的,只需要比较分子 P()和 P()乘积的大小。

那么如何得到 P(),以及 P()呢?在概率论中,可以应用极大似然估计法以及贝叶斯估计法来估计相应的概率。

极大似然估计

设甲箱中有99个白球,1个黑球;乙箱中有1个白球.99个黑球。现随机取出一箱,再从抽取的一箱中随机取出一球,结果是黑球,这一黑球从乙箱抽取的概率比从甲箱抽取的概率大得多,这时我们自然更多地相信这个黑球是取自乙箱的。一般说来,事件A发生的概率与某一未知参数  有关,  取值不同,则事件A发生的概率  也不同,当我们在一次试验中事件A发生了,则认为此时的 值应是t的一切可能取值中使  达到最大的那一个,极大似然估计法就是要选取这样的t值作为参数t的估计值,使所选取的样本在被选的总体中出现的可能性为最大

目的就是利用已知样本结果,反推最有可能造成这个结果的参数值。

极大似然估计提供了一种给定观察数据来评估模型参数的方法,即:「模型已定,参数未知」。通过若干次试验,观察其结果,利用试验结果得到某个参数值能够使样本出现的概率为最大,则称为极大似然估计。

 

Guess you like

Origin www.cnblogs.com/APINKE/p/11234623.html