Skip to content

    Naive Bayes

    Machine Learning · Intermediate

    Definition

    Naive Bayes applies Bayes' theorem assuming features are independent given the class.

    Fast and strong for text classification like spam detection.

    Diagram

    P(C|x) ∝ P(x|C)·P(C)

    Flowchart

    Compute class priors P(C)Compute likelihoods P(x|C)Multiply for each classPick highest posterior

    Example: Bayes numerical

    p_spam, p_word_spam, p_word = 0.3, 0.8, 0.4
    print(round(p_spam * p_word_spam / p_word, 2))

    Output: 0.6

    Complexity

    Training O(n·d)

    Key points

    • Use Laplace smoothing for unseen words
    • Works well with little data

    Interview questions

    Why 'naive'?

    It assumes all features are independent, which is rarely true.

    More Machine Learning topics