Module 5
Module 5
MODULE 5
BAYESIAN LEARNING
Bayesian reasoning provides a probabilistic approach to inference. It is based on the
assumption that the quantities of interest are governed by probability distributions and that
optimal decisions can be made by reasoning about these probabilities together with observed
data
INTRODUCTION
Bayesian learning methods are relevant to study of machine learning for two different reasons.
1. First, Bayesian learning algorithms that calculate explicit probabilities for hypotheses,
such as the naive Bayes classifier, are among the most practical approaches to certain
types of learning problems
2. The second reason is that they provide a useful perspective for understanding many
learning algorithms that do not explicitly manipulate probabilities.
BAYES THEOREM
Bayes theorem provides a way to calculate the probability of a hypothesis based on its prior
probability, the probabilities of observing various data given the hypothesis, and the observed
data itself.
Notations
• P(h) prior probability of h, reflects any background knowledge about the chance that h
is correct
• P(D) prior probability of D, probability that D will be observed
• P(D|h) probability of observing D given a world in which h holds
• P(h|D) posterior probability of h, reflects confidence that h holds after D has been
observed
Bayes theorem is the cornerstone of Bayesian learning methods because it provides a way to
calculate the posterior probability P(h|D), from the prior probability P(h), together with P(D)
and P(D|h).
• P(h|D) increases with P(h) and with P(D|h) according to Bayes theorem.
• P(h|D) decreases as P(D) increases, because the more probable it is that D will be
observed independent of h, the less evidence D provides in support of h.
• In many learning scenarios, the learner considers some set of candidate hypotheses H
and is interested in finding the most probable hypothesis h ∈ H given the observed data
D. Any such maximally probable hypothesis is called a maximum a posteriori (MAP)
hypothesis.
• Bayes theorem to calculate the posterior probability of each candidate hypothesis is hMAP
is a MAP hypothesis provided
P(D|h) is often called the likelihood of the data D given h, and any hypothesis that maximizes
P(D|h) is called a maximum likelihood (ML) hypothesis
Example
• Consider a medical diagnosis problem in which there are two alternative hypotheses:
(1) that the patient has particular form of cancer, and (2) that the patient does not. The
available data is from a particular laboratory test with two possible outcomes: +
(positive) and - (negative).
• We have prior knowledge that over the entire population of people only .008 have this
disease. Furthermore, the lab test is only an imperfect indicator of the disease.
• The test returns a correct positive result in only 98% of the cases in which the disease is
actually present and a correct negative result in only 97% of the cases in which the
disease is not present. In other cases, the test returns the opposite result.
• The above situation can be summarized by the following probabilities:
Suppose a new patient is observed for whom the lab test returns a positive (+) result.
Should we diagnose the patient as having cancer or not?
The exact posterior probabilities can also be determined by normalizing the above quantities
so that they sum to 1
What is the relationship between Bayes theorem and the problem of concept learning?
Since Bayes theorem provides a principled way to calculate the posterior probability of each
hypothesis given the training data, and can use it as the basis for a straightforward learning
algorithm that calculates the probability for each possible hypothesis, then outputs the most
probable.
We can design a straightforward concept learning algorithm to output the maximum a posteriori
hypothesis, based on Bayes theorem, as follows:
In order specify a learning problem for the BRUTE-FORCE MAP LEARNING algorithm we
must specify what values are to be used for P(h) and for P(D|h) ?
Let’s choose P(h) and for P(D|h) to be consistent with the following assumptions:
• The training data D is noise free (i.e., di = c(xi))
• The target concept c is contained in the hypothesis space H
• Do not have a priori reason to believe that any hypothesis is more probable than any
other.
Given these choices for P(h) and for P(D|h) we now have a fully-defined problem for the above
BRUTE-FORCE MAP LEARNING algorithm.
Where, VSH,D is the subset of hypotheses from H that are consistent with D
To summarize, Bayes theorem implies that the posterior probability P(h|D) under our assumed
P(h) and P(D|h) is
Example:
• FIND-S outputs a consistent hypothesis, it will output a MAP hypothesis under the
probability distributions P(h) and P(D|h) defined above.
• Are there other probability distributions for P(h) and P(D|h) under which FIND-S
outputs MAP hypotheses? Yes.
• Because FIND-S outputs a maximally specific hypothesis from the version space, its
output hypothesis will be a MAP hypothesis relative to any prior probability distribution
that favours more specific hypotheses.
Note
• Bayesian framework is a way to characterize the behaviour of learning algorithms
• By identifying probability distributions P(h) and P(D|h) under which the output is a
optimal hypothesis, implicit assumptions of the algorithm can be characterized
(Inductive Bias)
• Inductive inference is modelled by an equivalent probabilistic reasoning system based
on Bayes theorem
Consider the problem of learning a continuous-valued target function such as neural network
learning, linear regression, and polynomial curve fitting
A straightforward Bayesian analysis will show that under certain assumptions any learning
algorithm that minimizes the squared error between the output hypothesis predictions and the
training data will output a maximum likelihood (ML) hypothesis
Assuming training examples are mutually independent given h, we can write P(D|h) as the
product of the various (di|h)
Given the noise ei obeys a Normal distribution with zero mean and unknown variance σ2 , each
di must also obey a Normal distribution around the true targetvalue f(xi). Because we are
writing the expression for P(D|h), we assume h is the correct description of f.
Hence, µ = f(xi) = h(xi)
Maximize the less complicated logarithm, which is justified because of the monotonicity of
function p
The first term in this expression is a constant independent of h, and can therefore be
discarded, yielding
Thus, above equation shows that the maximum likelihood hypothesis hML is the one that
minimizes the sum of the squared errors between the observed training values di and the
hypothesis predictions h(xi)
Note:
Why is it reasonable to choose the Normal distribution to characterize noise?
• Good approximation of many types of noise in physical systems
• Central Limit Theorem shows that the sum of a sufficiently large number of
independent, identically distributed random variables itself obeys a Normal distribution
Only noise in the target value is considered, not in the attributes describing the instances
themselves
What criterion should we optimize in order to find a maximum likelihood hypothesis for f' in
this setting?
• First obtain an expression for P(D|h)
• Assume the training data D is of the form D = {(x1, d1) . . . (xm, dm)}, where di is the
observed 0 or 1 value for f (xi).
• Both xi and di as random variables, and assuming that each training example is drawn
independently, we can write P(D|h) as
Equation (4) to substitute for P(di |h, xi) in Equation (5) to obtain
Equation (7) describes the quantity that must be maximized in order to obtain the maximum
likelihood hypothesis in our current problem setting
• Derive a weight-training rule for neural network learning that seeks to maximize G(h,D)
using gradient ascent
• The gradient of G(h,D) is given by the vector of partial derivatives of G(h,D) with
respect to the various network weights that define the hypothesis h represented by the
learned network
• In this case, the partial derivative of G(h, D) with respect to weight wjk from input k to
unit j is
• Suppose our neural network is constructed from a single layer of sigmoid units. Then,
where xijk is the kth input to unit j for the ith training example, and d(x) is the derivative
of the sigmoid squashing function.
• Finally, substituting this expression into Equation (1), we obtain a simple expression for
the derivatives that constitute the gradient
Because we seek to maximize rather than minimize P(D|h), we perform gradient ascent rather
than gradient descent search. On each iteration of the search the weight vector is adjusted in
the direction of the gradient, using the weight update rule
Where, η is a small positive constant that determines the step size of the i gradient ascent search
The Minimum Description Length (MDL) principle is a concept from information theory
applied to model selection in machine learning. It helps in choosing the best hypothesis (model)
by focusing on how concisely the hypothesis and the data it explains can be encoded.
The Minimum Description Length principle is motivated by interpreting the definition of hMAP
in the light of basic concepts from information theory.
Consider - MAP that aims to find the hypothesis ℎ that maximizes the product of the likelihood
P(D∣h) and the prior P(h):
• Consider there are bunch of different messages, and need to send these messages over a
communication channel. Each message 𝑖 has a certain probability 𝑝𝑖 of being sent.
• The main Goal is to create a code that Minimize the average number of bits needed to
transmit a message.
• Here the strategy is to Assign shorter codes to more frequent messages. This way, we
save space by using fewer bits for common messages and more bits for rare ones.
• The optimal number of bits to encode a message i is −log2(pi)
o If a message is more likely, it gets a shorter code.
o If a message is less likely, it gets a longer code.
• The number of bits needed to encode message 𝑖 with this optimal code is called the
description length of the message, denoted as LC(i)
The equation (1) can be interpreted as a statement that short hypotheses are preferred, assuming
a particular representation scheme for encoding hypotheses and data
• -log2P(h): the description length of h under the optimal encoding for the hypothesis
space H, LCH (h) = −log2P(h), where CH is the optimal code for hypothesis space H.
• -log2P(D | h): the description length of the training data D given hypothesis h, under the
optimal encoding from the hypothesis space H: LCH (D|h) = −log2P(D| h) , where C D|h
is the optimal code for describing data D assuming that both the sender and receiver
know the hypothesis h.
• Rewrite Equation (1) to show that hMAP is the hypothesis h that minimizes the sum given
by the description length of the hypothesis plus the description length of the data given
the hypothesis.
Where, CH and CD|h are the optimal encodings for H and for D given h
The Minimum Description Length (MDL) principle recommends choosing the hypothesis that
minimizes the sum of these two description lengths of equ.
Where, codes C1 and C2 to represent the hypothesis and the data given the hypothesis
The above analysis shows that if we choose C1 to be the optimal encoding of hypotheses CH,
and if we choose C2 to be the optimal encoding CD|h, then hMDL = hMAP
Apply the MDL principle to the problem of learning decision trees from some training data.
What should we choose for the representations C1 and C2 of hypotheses and data?
• For C1: C1 might be some obvious encoding, in which the description length grows with
the number of nodes and with the number of edges
• For C2: Suppose that the sequence of instances (x1 . . .xm) is already known to both the
transmitter and receiver, so that we need only transmit the classifications (f (x1) . . . f
(xm)).
• Now if the training classifications (f (x1) . . .f(xm)) are identical to the predictions of the
hypothesis, then there is no need to transmit any information about these examples. The
description length of the classifications given the hypothesis ZERO
• If examples are misclassified by h, then for each misclassification we need to transmit
a message that identifies which example is misclassified as well as its correct
classification
• The hypothesis hMDL under the encoding C1 and C2 is just the one that minimizes the
sum of these description lengths.
When working with machine learning, there are two important questions we often ask:
Although it might seem that we can answer the second question by just using the most probable
hypothesis, known as the Maximum A Posteriori (MAP) hypothesis, there is actually a better
way.
Any system that classifies new instances according to this method is called a Bayes optimal
classifier, or Bayes optimal learner
Gibbs Algorithm
The Bayes optimal classifier is the best possible way to classify new data based on the training
data. However, it is computationally expensive because it calculates and combines the
probabilities of all hypotheses in the hypothesis space 𝐻. The Gibbs algorithm offers a simpler
but less optimal alternative
Algorithm:
• Choose a hypothesis h from H at random, according to the posterior probability
distribution over H.
• Use h to predict the classification of the next instance x.
This means that for each new instance to be classified, the Gibbs algorithm randomly picks one
hypothesis based on the current probabilities and uses it to make the prediction.
• The naive Bayes classifier applies to learning tasks where each instance x is described
by a conjunction of attribute values and where the target function f (x) can take on any
value from some finite set V.
• A set of training examples of the target function is provided, and a new instance is
presented, described by the tuple of attribute values (al, a2.. .am).
• The learner is asked to predict the target value, or classification, for this new instance.
The Bayesian approach to classifying the new instance is to assign the most probable target
value, VMAP, given the attribute values (al, a2.. .am) that describe the instance
• The naive Bayes classifier is based on the assumption that the attribute values are
conditionally independent given the target value. Means, the assumption is that given
the target value of the instance, the probability of observing the conjunction (al, a2.. .am),
is just the product of the probabilities for the individual attributes:
Where, VNB denotes the target value output by the naive Bayes classifier
An Illustrative Example
• Let us apply the naive Bayes classifier to a concept learning problem i.e., classifying
days according to whether someone will play tennis.
• The below table provides a set of 14 training examples of the target concept PlayTennis,
where each day is described by the attributes Outlook, Temperature, Humidity, and
Wind
• Use the naive Bayes classifier and the training data from this table to classify the
following novel instance:
< Outlook = sunny, Temperature = cool, Humidity = high, Wind = strong >
• Our task is to predict the target value (yes or no) of the target concept PlayTennis for
this new instance
The probabilities of the different target values can easily be estimated based on their
frequencies over the 14 training examples
• P(P1ayTennis = yes) = 9/14 = 0.64
• P(P1ayTennis = no) = 5/14 = 0.36
Similarly, estimate the conditional probabilities. For example, those for Wind = strong
• P(Wind = strong | PlayTennis = yes) = 3/9 = 0.33
• P(Wind = strong | PlayTennis = no) = 3/5 = 0.60
Thus, the naive Bayes classifier assigns the target value PlayTennis = no to this new
instance, based on the probability estimates learned from the training data.
By normalizing the above quantities to sum to one, calculate the conditional probability that
the target value is no, given the observed attribute values
Estimating Probabilities
• We have estimated probabilities by the fraction of times the event is observed to occur
over the total number of opportunities.
• For example, in the above case we estimated P(Wind = strong | Play Tennis = no) by
the fraction nc /n where, n = 5 is the total number of training examples for which
PlayTennis = no, and nc = 3 is the number of these for which Wind = strong.
• When nc = 0, then nc /n will be zero and this probability term will dominate the quantity
calculated in Equation (2) requires multiplying all the other probability terms by this
zero value
• To avoid this difficulty we can adopt a Bayesian approach to estimating the probability,
using the m-estimate defined as follows
m -estimate of probability:
• The naive Bayes classifier makes significant use of the assumption that the values of the
attributes a1 . . .an are conditionally independent given the target value v.
• This assumption dramatically reduces the complexity of learning the target function
A Bayesian belief network describes the probability distribution governing a set of variables
by specifying a set of conditional independence assumptions along with a set of conditional
probabilities
Bayesian belief networks allow stating conditional independence assumptions that apply to
subsets of the variables
Notation
• Consider an arbitrary set of random variables Y1 . . . Yn , where each variable Yi can
take on the set of possible values V(Yi).
• The joint space of the set of variables Y to be the cross product V(Y 1) x V(Y2) x. . .
V(Yn).
• In other words, each item in the joint space corresponds to one of the possible
assignments of values to the tuple of variables (Y1 . . . Yn). The probability distribution
over this joint' space is called the joint probability distribution.
• The joint probability distribution specifies the probability for each of the possible
variable bindings for the tuple (Y1 . . . Yn).
• A Bayesian belief network describes the joint probability distribution for a set of
variables.
Conditional Independence
Where,
The naive Bayes classifier assumes that the instance attribute A1 is conditionally independent
of instance attribute A2 given the target value V. This allows the naive Bayes classifier to
calculate P(Al, A2 | V) as follows,
Representation
A Bayesian belief network represents the joint probability distribution for a set of variables.
Bayesian networks (BN) are represented by directed acyclic graphs.
The Bayesian network in above figure represents the joint probability distribution over the
boolean variables Storm, Lightning, Thunder, ForestFire, Campfire, and BusTourGroup
A Bayesian network (BN) represents the joint probability distribution by specifying a set of
conditional independence assumptions
• BN represented by a directed acyclic graph, together with sets of local conditional
probabilities
• Each variable in the joint space is represented by a node in the Bayesian network
• The network arcs represent the assertion that the variable is conditionally independent
of its non-descendants in the network given its immediate predecessors in the network.
• A conditional probability table (CPT) is given for each variable, describing the
probability distribution for that variable given the values of its immediate predecessors
The joint probability for any desired assignment of values (y1, . . . , yn) to the tuple of network
variables (Y1 . . . Ym) can be computed by the formula
Example:
Consider the node Campfire. The network nodes and arcs represent the assertion that Campfire
is conditionally independent of its non-descendants Lightning and Thunder, given its
immediate parents Storm and BusTourGroup.
This means that once we know the value of the variables Storm and BusTourGroup, the
variables Lightning and Thunder provide no additional information about Campfire
The conditional probability table associated with the variable Campfire. The assertion is
Inference
• Use a Bayesian network to infer the value of some target variable (e.g., ForestFire) given
the observed values of the other variables.
• Inference can be straightforward if values for all of the other variables in the network
are known exactly.
• A Bayesian network can be used to compute the probability distribution for any subset
of network variables given the values or distributions for any subset of the remaining
variables.
• An arbitrary Bayesian network is known to be NP-hard
Affective algorithms can be considered for learning Bayesian belief networks from training
data by considering several different settings for learning problem
➢ First, the network structure might be given in advance, or it might have to be inferred from
the training data.
➢ Second, all the network variables might be directly observable in each training example,
or some might be unobservable.
• In the case where the network structure is given in advance and the variables are fully
observable in the training examples, learning the conditional probability tables is
straightforward and estimate the conditional probability table entries
• In the case where the network structure is given but only some of the variable values
are observable in the training data, the learning problem is more difficult. The learning
problem can be compared to learning weights for an ANN.
The gradient ascent rule which maximizes P(D|h) by following the gradient of ln P(D|h) with
respect to the parameters that define the conditional probability tables of the Bayesian network.
Let wijk denote a single entry in one of the conditional probability tables. In particular wijk
denote the conditional probability that the network variable Yi will take on the value yi, given
that its immediate parents Ui take on the values given by uik.
The gradient of ln P(D|h) is given by the derivatives for each of the wijk.
As shown below, each of these derivatives can be calculated as
Derive the gradient defined by the set of derivatives for all i, j, and k. Assuming the
training examples d in the data set D are drawn independently, we write this derivative as
THE EM ALGORITHM
The EM algorithm can be used even for variables whose value is never directly observed,
provided the general form of the probability distribution governing these variables is known.
• This problem setting is illustrated in Figure for the case where k = 2 and where the
instances are the points shown along the x axis.
• Each instance is generated using a two-step process.
• First, one of the k Normal distributions is selected at random.
• Second, a single random instance xi is generated according to this selected
distribution.
• This process is repeated to generate a set of data points as shown in the figure.
• To simplify, consider the special case
• The selection of the single Normal distribution at each step is based on choosing
each with uniform probability
• Each of the k Normal distributions has the same variance σ2, known value.
• The learning task is to output a hypothesis h = (μ1 , . . . ,μk) that describes the means of
each of the k distributions.
• We would like to find a maximum likelihood hypothesis for these means; that is, a
hypothesis h that maximizes p(D |h).
In this case, the sum of squared errors is minimized by the sample mean
• Our problem here, however, involves a mixture of k different Normal distributions, and
we cannot observe which instances were generated by which distribution.
• Consider full description of each instance as the triple (xi, zi1, zi2),
• where xi is the observed value of the ith instance and
• where zi1 and zi2 indicate which of the two Normal distributions was used to
generate the value xi
• In particular, zij has the value 1 if xi was created by the jth Normal distribution and 0
otherwise.
• Here xi is the observed variable in the description of the instance, and zil and zi2 are
hidden variables.
• If the values of zil and zi2 were observed, we could use following Equation to solve for
the means p1 and p2
• Because they are not, we will instead use the EM algorithm
EM algorithm
Question Bank
1. Define Bayesian theorem? What is the relevance and features of Bayesian theorem?
2. Explain the practical difficulties of Bayesian theorem.
3. Define is Maximum a Posteriori (MAP) Maximum Likelihood (ML) Hypothesis. Derive
the relation for hMAP and hML using Bayesian theorem.
4. Consider a medical diagnosis problem in which there are two alternative hypotheses:1. that
the patient has a particular form of cancer (+) and 2. That the patient does not (-). A patient
takes a lab test and the result comes back positive. The test returns a correct positive result
in only 98% of the cases in which the disease is actually present, and a correct negative
result in only 97% of the cases in which the disease is not present. Furthermore, .008 of
the entire population have this cancer. Determine whether the patient has Cancer or not
using MAP hypothesis.
5. Explain Brute force Bayes Concept Learning
6. What are Consistent Learners?
7. Discuss Maximum Likelihood and Least Square Error Hypothesis
8. Describe Maximum Likelihood Hypothesis for predicting probabilities.
9. Explain the Gradient Search to Maximize Likelihood in a Neural Net
10. Describe the concept of MDL. Obtain the equation for hMDL
11. Explain Bayes optimal classifier.
12. Explain Gibbs algorithm.
13. Explain Naïve Bayes Classifier with an Example
14. What are Bayesian Belief nets? Where are they used?
15. Explain Bayesian belief network and conditional independence with example
16. Explain Gradient Ascent Training of Bayesian Networks
17. Explain the concept of EM Algorithm. Discuss what are Gaussian Mixtures