Naive Bayes Classification method

    • Let Naive Bayes 朴素贝叶斯 - 图1 be a training set of tuples and their associated class labels, and each tuple is represented by an n-Dimensional attribute vector Naive Bayes 朴素贝叶斯 - 图2
    • Suppose there are Naive Bayes 朴素贝叶斯 - 图3 classes Naive Bayes 朴素贝叶斯 - 图4
    • Classification aims to derive the maximum posteriori, i.e., the maximal Naive Bayes 朴素贝叶斯 - 图5 using Bayes’ theorem Naive Bayes 朴素贝叶斯 - 图6
      • Since P(X) is constant for all classes, we only need to maximise
        Naive Bayes 朴素贝叶斯 - 图7

    For Naive Bayes, we simplify Bayes’ theorem to reduce the computation cost of each likelihood in the training phase. Instead of a computing and recording a likelihood for each tuple for each class in our training set, we summarise by computing a likelihood for each attribute value for each class, that is, the class distribution for each attribute value. Statistically, we are making an assumption that, within each class, each attribute is independent of all the others.

    Class conditional independence: We assume the object’s attribute values are conditionally independent of each other given a class label, so we can write
    image.png

    • In other words, we factorise each attribute in the likelihood function, by _assuming that there are no dependence relationships amongst the attribu_tes. 换句话说,我们通过假设属性之间没有依赖关系,来分解似然函数中的每个属性。
    • This greatly reduces the computation cost as it only counts the class distribution 这大大降低了计算成本,因为它只计算类分布
    • If Naive Bayes 朴素贝叶斯 - 图9 is categorical, Naive Bayes 朴素贝叶斯 - 图10 is the number of tuples in Naive Bayes 朴素贝叶斯 - 图11 having value Naive Bayes 朴素贝叶斯 - 图12 for Naive Bayes 朴素贝叶斯 - 图13 divided by Naive Bayes 朴素贝叶斯 - 图14 (number of tuples of Naive Bayes 朴素贝叶斯 - 图15 in Naive Bayes 朴素贝叶斯 - 图16)
    • Blithely assuming class conditional independence of attributes is naive, hence the name of the method. It is not checked, and is commonly even known to be untrue, however, it seems to work, mostly.

    Example
    Let’s compute the likelihood of the previous example using the assumption of class conditional independence

    age credit buys_computer
    youth fair no
    youth fair yes
    middle_aged excellent yes
    middle_aged fair no
    youth excellent no
    middle_aged excellent no
    middle_aged fair yes

    • With the conditional independence assumption, the likelihood of tuple (youth, excellent) is
      Naive Bayes 朴素贝叶斯 - 图17
      Naive Bayes 朴素贝叶斯 - 图18
      Naive Bayes 朴素贝叶斯 - 图19
      Naive Bayes 朴素贝叶斯 - 图20
    • We can also see here that we have mitigated the limitation observed earlier caused by the lack of observations for (youth, excellent) actually buying a computer.

    Example 2

    • Here we have some more complex customer history with four different attributes. | age | income | student | credit | buys_computer | | —- | —- | —- | —- | —- | | youth | high | no | fair | no | | youth | high | no | excellent | no | | middle_aged | high | no | fair | yes | | senior | medium | no | fair | yes | | senior | low | yes | fair | yes | | senior | low | yes | excellent | no | | middle_aged | low | yes | excellent | yes | | youth | medium | no | fair | no | | youth | low | yes | fair | yes | | senior | medium | yes | fair | yes | | youth | medium | yes | excellent | yes | | middle_aged | medium | no | excellent | yes | | middle_aged | high | yes | fair | yes | | senior | medium | no | excellent | no |

    • Compute prior probability on hypothesis: Naive Bayes 朴素贝叶斯 - 图21

      • Naive Bayes 朴素贝叶斯 - 图22
      • Naive Bayes 朴素贝叶斯 - 图23
    • Compute conditional probability Naive Bayes 朴素贝叶斯 - 图24for each class
      • Attribute ‘age’
        • Naive Bayes 朴素贝叶斯 - 图25
        • Naive Bayes 朴素贝叶斯 - 图26
      • Attribute ‘ income’
        • Naive Bayes 朴素贝叶斯 - 图27
        • Naive Bayes 朴素贝叶斯 - 图28
      • Attribute ‘student’
        • Naive Bayes 朴素贝叶斯 - 图29
        • Naive Bayes 朴素贝叶斯 - 图30
      • Attribute ‘credit’
        • Naive Bayes 朴素贝叶斯 - 图31
        • Naive Bayes 朴素贝叶斯 - 图32
    • Predict probability ofNaive Bayes 朴素贝叶斯 - 图33buying computer
      • Naive Bayes 朴素贝叶斯 - 图34
      • Compute likelihoodNaive Bayes 朴素贝叶斯 - 图35
        • Naive Bayes 朴素贝叶斯 - 图36
        • Naive Bayes 朴素贝叶斯 - 图37
      • Compute Naive Bayes 朴素贝叶斯 - 图38
        • Naive Bayes 朴素贝叶斯 - 图39
        • Naive Bayes 朴素贝叶斯 - 图40
      • Therefore, Naive Bayes 朴素贝叶斯 - 图41 belongs to class Naive Bayes 朴素贝叶斯 - 图42