0% found this document useful (0 votes)
338 views2 pages

06 NaiveBayes Example

This document provides an example of how a Naive Bayes classifier works. It describes the classifier formula that selects the most likely classification given attribute values. It then provides a car theft example with attributes of color, type, and origin, and whether the car was stolen or not. It shows the training data and how to compute the probabilities of attributes given a classification in order to classify a new example of a red domestic SUV as either stolen or not stolen.

Uploaded by

kakalott77
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
338 views2 pages

06 NaiveBayes Example

This document provides an example of how a Naive Bayes classifier works. It describes the classifier formula that selects the most likely classification given attribute values. It then provides a car theft example with attributes of color, type, and origin, and whether the car was stolen or not. It shows the training data and how to compute the probabilities of attributes given a classification in order to classify a new example of a red domestic SUV as either stolen or not stolen.

Uploaded by

kakalott77
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Naive Bayes Classifier example

Eric Meisner
November 22, 2003

1 The Classifier
The Bayes Naive classifier selects the most likely classification Vnb given the attribute values a1 , a2 , . . . an .
This results in: Y
Vnb = argmaxvj ∈V P (vj ) P (ai |vj ) (1)
We generally estimate P (ai |vj ) using m-estimates:
nc + mp
P (ai |vj ) = (2)
n+m
where:
n= the number of training examples for which v = vj
nc = number of examples for which v = vj and a = ai
p= a priori estimate for P (ai |vj )
m= the equivalent sample size

2 Car theft Example


Attributes are Color , Type , Origin, and the subject, stolen can be either yes or no.

2.1 data set


Example No. Color Type Origin Stolen?
1 Red Sports Domestic Yes
2 Red Sports Domestic No
3 Red Sports Domestic Yes
4 Yellow Sports Domestic No
5 Yellow Sports Imported Yes
6 Yellow SUV Imported No
7 Yellow SUV Imported Yes
8 Yellow SUV Domestic No
9 Red SUV Imported No
10 Red Sports Imported Yes

2.2 Training example


We want to classify a Red Domestic SUV. Note there is no example of a Red Domestic SUV in our data
set. Looking back at equation (2) we can see how to compute this. We need to calculate the probabilities
P(Red|Yes), P(SUV|Yes), P(Domestic|Yes) ,

P(Red|No) , P(SUV|No), and P(Domestic|No)

1
and multiply them by P(Yes) and P(No) respectively . We can estimate these values using equation (3).

Yes: No:
Red: Red:
n = 5 n = 5
n_c= 3 n_c = 2
p = .5 p = .5
m = 3 m = 3
SUV: SUV:
n = 5 n = 5
n_c = 1 n_c = 3
p = .5 p = .5
m = 3 m = 3
Domestic: Domestic:
n = 5 n = 5
n_c = 2 n_c = 3
p = .5 p = .5
m = 3 m =3
Looking at P (Red|Y es), we have 5 cases where vj = Yes , and in 3 of those cases ai = Red. So for
P (Red|Y es), n = 5 and nc = 3. Note that all attribute are binary (two possible values). We are assuming
no other information so, p = 1 / (number-of-attribute-values) = 0.5 for all of our attributes. Our m value
is arbitrary, (We will use m = 3) but consistent for all attributes. Now we simply apply eqauation (3)
using the precomputed values of n , nc , p, and m.

3 + 3 ∗ .5 2 + 3 ∗ .5
P (Red|Y es) = = .56 P (Red|N o) = = .43
5+3 5+3
1 + 3 ∗ .5 3 + 3 ∗ .5
P (SU V |Y es) = = .31 P (SU V |N o) = = .56
5+3 5+3
2 + 3 ∗ .5 3 + 3 ∗ .5
P (Domestic|Y es) = = .43 P (Domestic|N o) = = .56
5+3 5+3
We have P (Y es) = .5 and P (N o) = .5, so we can apply equation (2). For v = Y es, we have
P(Yes) * P(Red | Yes) * P(SUV | Yes) * P(Domestic|Yes)

= .5 * .56 * .31 * .43 = .037


and for v = N o, we have
P(No) * P(Red | No) * P(SUV | No) * P (Domestic | No)

= .5 * .43 * .56 * .56 = .069


Since 0.069 > 0.037, our example gets classified as ’NO’

You might also like