Docsity

Bayesian Learning in Machine Learning: Lecture Notes, Study notes of Software Engineering

Partial preview of the text

Download Bayesian Learning in Machine Learning: Lecture Notes and more Study notes Software Engineering in PDF only on Docsity!

Lecture 16: Bayesian learning

CSI 5v93: Introduction to machine learning

Baylor University

Computer Science Department

Dr. Greg Hamerly

http://cs.baylor.edu/˜hamerly/

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 1/

Questions?

Bayesian learning and naive Bayes

Bayes’ rule and modelling •

naive Bayes •

smoothing •

binning continuous variables •

applications to text •

shaping probabilities •

See handouts from Mitchell as primary source (also see section 6.6.3 in your book)

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 3/

Naive Bayes classifier

A naive Bayes classifier is based on Bayes’ rule.

. given the class ,j is independent of input variable i Naive assumption: input variable . conditional independence This is called

:^ jx and^ ix has features x In probability terms, if input

)c|^ jx ) Pr(c|ix ) = Pr(c|^ j , xix Pr(

-probabilitieslog Using

We can apply the log probabilities to the entire Bayes’ rule:

log = ) X| M log Pr( ) M ) Pr( M| X Pr(

) X Pr(

) X log Pr( − ) M ) + log Pr( M| X log Pr( =

=

[

d∑

=1 i ia = i X( count log ⋂

) M

]

) M( count log d −

) X log Pr( − ) M + log Pr(

) X| M log Pr( that gives the largest M Then the MAP classification is still the class

(similar for ML).

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 7/

) M Pr( Prior probabilites –

. M as the frequency of class ) M Pr( For the tasks we will use, we will model

Therefore:

= ) M Pr( ) M( count

n

)n log( − ) M( count log = ) M log Pr(

is the number ) M( is the total number of records in the training set, and count n where

occurs in the training set. M of times that class

Smoothing zero probabilities

A standard way to deal with zero probabilities is to eliminate them by smoothing.

. Forλ The simplest way to smooth probabilities is by adding a smoothing constant

example,

= ) M|x = X Pr( x = X( count ⋂

λ ) + M

kλ ) + M( count

that have been observed. X is the number of different values of k and 0 λ > Where

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 9/

Example of smoothing zero probabilities

We observe the following frequencies in the training set:

HIGH = TEMP( count ⋂

4 = ) SUNNY

MED = TEMP( count ⋂

2 = ) SUNNY

LOW = TEMP( count ⋂

0 = ) SUNNY

= 1 λ Then if

after smoothing before smoothing

6 / 4 = ) SUNNY| HIGH = TEMP Pr( 4+

6+ 9 / = 5

6 / 2 = ) SUNNY| MED = TEMPPr( 2+

6+ 9 / = 3

6 / 0 = ) SUNNY| LOW = TEMPPr( 0+

6+ 9 / = 1

Binning

Most of the time with naive Bayes practitioners use the non-parametric model.

most general assumption •

requires most data for learning •

Suppose that you have real-valued data – how do you model this with a

non-parametric model that expects discrete values?

Answer: divide up the real space into discrete regions.

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 13/

Binning methods

Equal-width binning – choose a uniform interval width, and cover all inputs with bins of

that width.

Equal-frequency binning – choose a number of bins, and cover all inputs with that

many bins, each bin having the same number of examples.

Advantages? Disadvantages?

Shaping probabilities: thresholds

, we have the probability that it belongs to each class:x When classifying an example

.)x = X| m = M Pr(

We classify to the class that gives the largest probability.

If the number of classes is 2, then we really have only one probability (since the two

probabilities must sum to 1).

The threshold for classifying to class A versus class B is usually 50%. In other words,

. 50% ≥ ) X| A Pr( classify to A if

If we want to be more sensitive to one class over the other, we can change this

threshold. This is equivalent to modifying the priors.

CSI 5v93: Introduction to machine learning, Lecture 16 – p. 15/

Shaping probabilities

Usually with naive Bayes, the probabilities that it gives are extreme – they are very

close to 0 or 1.

This causes the probabilities to be unreliable.

How can we deal with this?

ranking probabilities •

shaping probabilities •