





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!






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/
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/
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(
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 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
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/
We observe the following frequencies in the training set:
HIGH = TEMP( count ⋂
MED = TEMP( count ⋂
LOW = TEMP( count ⋂
= 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
Most of the time with naive Bayes practitioners use the non-parametric model.
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/
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?
, 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/
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?