Skip to content

Instantly share code, notes, and snippets.

@goFrendiAsgard
Last active November 30, 2017 08:54
Show Gist options
  • Select an option

  • Save goFrendiAsgard/6f78baca534a230d301dfda86da12935 to your computer and use it in GitHub Desktop.

Select an option

Save goFrendiAsgard/6f78baca534a230d301dfda86da12935 to your computer and use it in GitHub Desktop.

Naive Bayes

Data

Type        |  Long | Not Long || Sweet | Not Sweet || Yellow |Not Yellow|Total
Banana      |  400  |    100   || 350   |    150    ||  450   |  50      |  500
Orange      |    0  |    300   || 150   |    150    ||  300   |   0      |  300
Other Fruit |  100  |    100   || 150   |     50    ||   50   | 150      |  200
            ____________________________________________________________________
Total       |  500  |    500   || 650   |    350    ||  800   | 200      | 1000
             ___________________________________________________________________

Probability

P(Banana) = 0.5 (500/1000) P(Orange) = 0.3 P(Other Fruit) = 0.2

p(Long) = 0.5 P(Sweet) = 0.65 P(Yellow) = 0.8

P(Long|Banana) = 0.8 (400/500) P(Long|Orange) = 0 (0/300) ....

P(Yellow|Other Fruit) = 50/200 = 0.25 P(Not Yellow|Other Fruit) = 0.75

A Fruit is long, yellow and sweet.

P(Banana|Long, Sweet and Yellow) 
      P(Long|Banana) * P(Sweet|Banana) * P(Yellow|Banana) * P(banana)
    = _______________________________________________________________
                      P(Long) * P(Sweet) * P(Yellow)

    = 0.8 * 0.7 * 0.9 * 0.5 / P(evidence)

    = 0.252 / P(evidence)


P(Orange|Long, Sweet and Yellow) = 0


P(Other Fruit|Long, Sweet and Yellow)
      P(Long|Other fruit) * P(Sweet|Other fruit) * P(Yellow|Other fruit) * P(Other Fruit)
    = ____________________________________________________________________________________
                                          P(evidence)

    = (100/200 * 150/200 * 50/200 * 200/1000) / P(evidence)

    = 0.01875 / P(evidence)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment