



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Chris Brooks Department of Computer ScienceUniversity of San Francisco
problem.
This involves placing examples into one of two or moreclasses.
Should/shouldn’t play tennis Spam/not spam. Wait/don’t wait at a restaurant Classification is a
supervised
learning task.
Requires access to a set of labeled training examples From this we induce a hypothesis that describes how todetermine what class an example should be in.
Department of Computer Science — University of San Francisco – p.1/
??
Department of Computer Science — University of San Fra
|a) =
P^ (a |b)P
(b) P^ (a
)
Let’s rewrite this a bit. Let
be the data we’ve seen so far. Let
h^ be a possible hypothesis P^ (h
P^ (D
|h)P
(h) P^ (D
)
Department of Computer Science — University of San Francisco – p.3/
??
P layT ennis
or^
¬P layT ennis
more likely?
We call this the
maximum a posteriori hypothesis
hypothesis). In this case, we can ignore the denominator
in
Bayes’ Theorem, since it will be the same for all
h.
hM AP
argmax
h∈H
|h)P
(h)
Department of Computer Science — University of San Francisco – p.4/
??
Department of Computer Science — University of San Fra
h)^ for each hypothesis?
Without any other information, we’ll often assume thatthey’re equally possible.^ Each has probability
(^1) H
In this case, we can just consider the conditionalprobability
D|h
We call the hypothesis that maximizes this conditionalprobability the
maximum likelihood
hypothesis.
hM L
argmax
h∈H
|h)
Department of Computer Science — University of San Francisco – p.6/
??
: 100% cherry 1
2.^
h75% cherry, 25% lime.^2
3.^
h50% cherry, 50% lime^3
4.^
h25% cherry, 75% lime^4
5.^
h100% lime^5 Our agent repeatedly draws pieces of candy. We want it to correctly pick the type of the next piece ofcandy.
Department of Computer Science — University of San Francisco – p.7/
??
Also, we assume that the observations are i.i.d.
This means that each choice is independent of theothers. (order doesn’t matter) In that case, we can multiply probabilities. P^ (D
|h) = Πi
P^ (j d|hj^
)i
Suppose we draw 10 limes in a row.
D|h
)^ is 3
since the probability of drawing a lime under
h^3
(^1) is 2
Department of Computer Science — University of San Fra
Then we draw a lime.^ P
(h^1
|lime
αP
(lime
|h)^1
P^ (h
P^ (h
|lime 2
αP
(lime
|h)^2
P^ (h
(^1) α 4
α^0
P^ (h
|lime 3
αP
(lime
|h)^3
P^ (h
(^1) α 2
α^0
P^ (h
|lime 4
αP
(lime
|h)^4
P^ (h
(^3) α 4
α^0
P^ (h
|lime 5
αP
(lime
|h)^5
P^ (h
α^1
α^0
α^ = 2
Department of Computer Science — University of San Francisco – p.9/
??
(h^1
|lime, lime
αP
(lime, lime
|h)^1
P^ (h
P^ (h
|lime, lime 2
αP
(lime, lime
|h)^2
P^ (h
(^11) α 4 4
α^0
P^ (h
|lime, lime 3
αP
(lime, lime
|h)^3
P^ (h
(^11) α 2 2
α^0
P^ (h
|lime, lime 4
αP
(lime, lime
|h)^4
P^ (h
(^33) α 4 4
α^0
P^ (h
|lime 5
αP
(lime
|h)^5
P^ (h
α^1
α^0
α^ = 3
Strictly speaking, we don’t really care what
α^ is.
We can just select the MAP hypothesis, since we justwant to know the most likely hypothesis.
Department of Computer Science — University of San Francisco – p.10/
??
Department of Computer Science — University of San Fran
(a^ ∧
b) =
a)P
(b)^
for all a and b.
This makes it straightforward to compute posteriors.
Department of Computer Science — University of San Francisco – p.18/
??
x)^ that correctly classifies an unseen
example with attributes
(a^1
, a^2
, ..., a
)^ .n
Call the most probable category
vmap
vmap
argmax
vi∈V
v|ai
, a 1
, ..., a 2
)n
We rewrite this with Bayes’ Theorem as: vmap
argmax
v∈Vi
a, a^1
, ..., a 2
|vni
v)i
Estimating
v)^ i
is straightforward with a large training
set; count the fraction of the set that are of class
v.i
However, estimating
a, a^1
, ..., a 2
|vni )^ is difficult unless
our training set is
very
large. We need to see every
possible attribute combination many times.
Department of Computer Science — University of San Francisco – p.19/
??
a, a^1
, ..., a 2
|vni
P^ (i a|vi
).i
This can be estimated from the training data. The classifier then picks the class with the highestprobability according to this equation. Interestingly, Naive Bayes performs well even in caseswhere the conditional independence assumption fails.
Department of Computer Science — University of San Fran
Department of Computer Science — University of San Francisco – p.21/
??
Day^
Outlook
Temperature
Humidity
Wind
PlayTennis
D^
Sunny
Hot^
High
Weak
No
D^
Sunny
Hot^
High
Strong
No
D^
Overcast
Hot^
High
Weak
Yes
D^
Rain
Mild^
High
Weak
Yes
D^
Rain
Cool
Normal
Weak
Yes
D^
Rain
Cool
Normal
Strong
No
D^
Overcast
Cool
Normal
Strong
Yes
D^
Sunny
Mild^
High
Weak
No
D^
Sunny
Cool
Normal
Weak
Yes
D^
Rain
Mild^
Normal
Weak
Yes
D^
Sunny
Mild^
Normal
Strong
Yes
D^
Overcast
Mild^
High
Strong
Yes
D^
Overcast
Hot^
Normal
Weak
Yes
D^
Rain
Mild^
High
Strong
No Department of Computer Science — University of San Francisco – p.22/
??
(P layT ennis
=^ yes
P^ (P layT ennis
=^ no
We can estimate:
P^ (wind
=^ strong
|P layT ennis
=^ yes
P^ (wind
=^ strong
|P layT ennis
=^ no
P^ (humidity
high
|P layT ennis
=^ yes
P^ (humidity
high
|P layT ennis
=^ no
P^ (outlook
sunny
|P layT ennis
=^ yes
P^ (outlook
sunny
|P layT ennis
=^ no
P^ (temp
=^ cool
|P layT ennis
yes
P^ (temp
=^ cool
|P layT ennis
no) = 1
Department of Computer Science — University of San Fran
P^ (yes
sunny
|yes
cool
|yes
high
|yes
strong
|yes
0.^005 vno^
P^ (no
sunny
|no
cool
|no
high
|no)
P^ (strong
|no) =
0.^0206 So we see that not playing tennis is the maximumlikelihood hypothesis. Further, by normalizing, we see that the classifierpredicts a
0.^02060 .005+
.^0206
probability of not playing
tennis.
Department of Computer Science — University of San Francisco – p.24/
??
-estimate: nc+
mp n+m Where
nc^
is the number of individuals with the
characteristic of interest (say Wind = strong),
n^ is the
total number of positive/negative examples,
p^ is our prior
estimate, and
m^
is a constant called the
equivalent
sample size
Department of Computer Science — University of San Francisco – p.25/
??
p.
p^ is assumed to be uniform. So, in the Tennis example, P^ (wind
strong
|playT ennis
=^ no
3+
.^2 m 5+m
We’ll determine an
m^
based on sample size.
If^ m
is zero, we just use observed data. If^ m >> n
, we use the prior.
Otherwise
m^
lets us weight these parameters’
relative influence.
Department of Computer Science — University of San Fran
Department of Computer Science — University of San Francisco – p.27/
??
Department of Computer Science — University of San Francisco – p.28/
??
Department of Computer Science — University of San Fran