Docsity

Bayesian Learning in Artificial Intelligence: A Comprehensive Guide, Study notes of Computer Science

Toggle sidebar
bg1
Artificial Intelligence
Programming
Bayesian Learning
Chris Brooks
Department of Computer Science
University of San Francisco
Learning and Classification
An important sort of learning problem is the
classification problem.
This involves placing examples into one of two or more
classes.
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 to
determine what class an example should be in.
Departmentof Computer Science — University of San Francisco – p.1/??
Probabilistic Learning
Decision trees are one way to do this.
They tell us the most likely classification for given
data.
Work best with tabular data, where each attribute has
a known number of possible values.
What if we want to know how likely a hypothesis is?
We can apply our knowledge of probability to learn a
hypothesis.
Departmentof Computer Science — University of San Francisco
Bayes’ Theorem
Recall the definition of Bayes’ Theorem
P(b|a) = P(a|b)P(b)
P(a)
Let’s rewrite this a bit.
Let Dbe the data we’ve seen so far.
Let hbe a possible hypothesis
P(h|D) = P(D|h)P(h)
P(D)
Departmentof Computer Science — University of San Francisco – p.3/??
MAP Hypothesis
Often, we’re not so interested in the particular
probabilities for each hypothesis.
Instead, we want to know: Which hypothesis is most
likely, given the data?
Which classification is the most probable?
Is Pl ayT ennis or ¬Pl ayT ennis more likely?
We call this the maximum a posteriori hypothesis (MAP
hypothesis).
In this case, we can ignore the denominator (P(D)) in
Bayes’ Theorem, since it will be the same for all h.
hMAP =argmaxh∈HP(D|h)P(h)
Departmentof Computer Science — University of San Francisco – p.4/??
MAP Hypothesis
Advantages:
Simpler calculation
No need to have a prior for P(D)
Departmentof Computer Science — University of San Francisco
pf3
pf4
pf5

Partial preview of the text

Download Bayesian Learning in Artificial Intelligence: A Comprehensive Guide and more Study notes Computer Science in PDF only on Docsity!

Artificial Intelligence

Programming Bayesian Learning

Chris Brooks Department of Computer ScienceUniversity of San Francisco

Learning and Classification An important sort of learning problem is the classification

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/

??

Probabilistic Learning Decision trees are one way to do this.^ They tell us the most likely classification for givendata.^ Work best with tabular data, where each attribute hasa known number of possible values. What if we want to know how likely a hypothesis is? We can apply our knowledge of probability to learn ahypothesis.

Department of Computer Science — University of San Fra

Bayes’ Theorem Recall the definition of Bayes’ Theorem P^ (b

|a) =

P^ (a |b)P

(b) P^ (a

)

Let’s rewrite this a bit. Let

D^

be the data we’ve seen so far. Let

h^ be a possible hypothesis P^ (h

|D) =

P^ (D

|h)P

(h) P^ (D

)

Department of Computer Science — University of San Francisco – p.3/

??

MAP Hypothesis Often, we’re not so interested in the particularprobabilities for each hypothesis. Instead, we want to know: Which hypothesis is mostlikely, given the data?^ Which classification is the most probable?^ Is

P layT ennis

or^

¬P layT ennis

more likely?

We call this the

maximum a posteriori hypothesis

(MAP

hypothesis). In this case, we can ignore the denominator

(P^

(D))

in

Bayes’ Theorem, since it will be the same for all

h.

hM AP

=^

argmax

h∈H

P^ (D

|h)P

(h)

Department of Computer Science — University of San Francisco – p.4/

??

MAP Hypothesis Advantages:^ Simpler calculation^ No need to have a prior for

P^ (

D)

Department of Computer Science — University of San Fra

ML Hypothesis In some cases, we can simplify things even further. What are the priors

P^ (

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

P^ (

D|h

We call the hypothesis that maximizes this conditionalprobability the

maximum likelihood

hypothesis.

hM L

=^

argmax

h∈H

P^ (D

|h)

Department of Computer Science — University of San Francisco – p.6/

??

Example Imagine that we have a large bag of candy. We want toknow the ratio of cherry to lime in the bag. We start with 5 hypotheses:1.^ h

: 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/

??

Example Let’s assume our priors for the different hypotheses are: (0.^1 ,

0.^2

,^0.^4

,^0.^2

,^0 .1)

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.

P^ (

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

Example How do the hypotheses change as data is observed? Initially, we start with the priors:

1 ,^0

.^2 ,^0

.^4 ,^0

.^2 ,^0

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

α^0

.^05.

P^ (h

|lime 3

αP

(lime

|h)^3

P^ (h

(^1) α 2

∗^0

α^0

.^2

P^ (h

|lime 4

αP

(lime

|h)^4

P^ (h

(^3) α 4

∗^0

α^0

.^15.

P^ (h

|lime 5

αP

(lime

|h)^5

P^ (h

α^1

∗^0

α^0

.^1.

α^ = 2

Department of Computer Science — University of San Francisco – p.9/

??

Example Then we draw a second lime.^ P

(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

α^0

.^0125

P^ (h

|lime, lime 3

αP

(lime, lime

|h)^3

P^ (h

(^11) α 2 2

∗^0

α^0

.^1

P^ (h

|lime, lime 4

αP

(lime, lime

|h)^4

P^ (h

(^33) α 4 4

∗^0

α^0

.^1125

P^ (h

|lime 5

αP

(lime

|h)^5

P^ (h

α^1

∗^0

α^0

.^1.

α^ = 3

.^07.

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/

??

Bayesian Learning Eventually, the true hypothesis will dominate all others.^ Caveat: assuming the data is noise-free, or noise isuniformly distributed. Notice that we can use Bayesian learning (in this case)either as a batch algorithm or as an incrementalalgorithm. We can always easily update our hypotheses toincorporate new evidence.^ This depends on the assumption that ourobservations are independent.

Department of Computer Science — University of San Fran

Naive Bayes classifier The Naive Bayes classifer makes a strong assumptionthat makes the algorithm practical:^ Each attribute of an example is independent of theothers.^ P

(a^ ∧

b) =

P^ (

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/

??

The Bayesian Learning Problem Given: a set of labeled, multivalued examples. Find a function

F^ (

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

P^ (

v|ai

, a 1

, ..., a 2

)n

We rewrite this with Bayes’ Theorem as: vmap

=^

argmax

v∈Vi

P^ (

a, a^1

, ..., a 2

|vni

)P^ (

v)i

Estimating

P^ (

v)^ i

is straightforward with a large training

set; count the fraction of the set that are of class

v.i

However, estimating

P^ (

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/

??

Naive Bayes assumption Naive Bayes assumes that all attributes are conditionallyindependent of each other. In this case,

P^ (

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

Example Recall your tennis-playing problem from the decisiontree homework. We want to use the training data and a Naive Bayesclassifier to classify the following instance: Outlook = Sunny, Temperature = Cool, Humidity = high,Wind = Strong.

Department of Computer Science — University of San Francisco – p.21/

??

Example

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/

??

Example Our priors are:^ P

(P layT ennis

=^ yes

.^64

P^ (P layT ennis

=^ no

.^36

We can estimate:

P^ (wind

=^ strong

|P layT ennis

=^ yes

.^33

P^ (wind

=^ strong

|P layT ennis

=^ no

.^6

P^ (humidity

=^

high

|P layT ennis

=^ yes

.^33

P^ (humidity

=^

high

|P layT ennis

=^ no

.^8

P^ (outlook

=^

sunny

|P layT ennis

=^ yes

.^22

P^ (outlook

=^

sunny

|P layT ennis

=^ no

.^6

P^ (temp

=^ cool

|P layT ennis

=^

yes

.^33

P^ (temp

=^ cool

|P layT ennis

=^

no) = 1

.^2

Department of Computer Science — University of San Fran

Example vyes

P^ (yes

)P^ (

sunny

|yes

)P^ (

cool

|yes

)P^ (

high

|yes

)P^ (

strong

|yes

0.^005 vno^

P^ (no

)P^ (

sunny

|no

)P^ (

cool

|no

)P^ (

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

.^80

probability of not playing

tennis.

Department of Computer Science — University of San Francisco – p.24/

??

Estimating Probabilities As we can see from this example, estimatingprobabilities through frequency is risky when our dataset is small. We only have 5 negative examples, so we may not havean accurate estimate. A better approach is to use the following formula, calledan^ m

-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/

??

Estimating Probabilities m^ determines how heavily to weight

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

Using Naive Bayes to classify spam One are where Naive Bayes has been very successful isin text classification.^ Despite the violation of independence assumptions. Classifying spam is just a special case of textclassification. Problem - given some emails labled ham or spam,determine the category of new and unseen documents. Our features will be the tokens that appear in adocument. Based on this, we’ll predict a category.

Department of Computer Science — University of San Francisco – p.27/

??

Classifying spam Naive Bayes is only one possible way to classify spam.^ Rule-based systems (SpamAssassin)^ Examining headers (broken From or Content-Type)^ Blacklist^ Challenge/response

Department of Computer Science — University of San Francisco – p.28/

??

Classifying spam with Naive Bayes Naive Bayes has several properties that make it nice asa spam classifier:^ We don’t need to encode specific rules^ We can adapt as the types of spam change^ Somewhat robust to spammers adding in extra text

Department of Computer Science — University of San Fran