Bayesian Rule & Gaussian Mixture Models Jianping Fan Dept of Computer Science UNC-Charlotte
Input Output Basic Classification Spam vs. Not-Spam Spam Binary filtering Binary !!!!$$$!!!!
C Input Output Basic Classification Multi-Class Character recognition C vs. other 25 characters
Structured Classification Input Output Handwriting recognition Structured output Graph Model brace building 3D object recognition tree
Overview of Bayesian Decision Bayesian classification: one example E.g. How to decide if a patient is sick or healthy, based on A probabilistic model of the observed data (data distributions) Prior knowledge (ratio or importance) Majority has bigger voice
Overview of Bayesian Decision Test patient Group assignment for test patient; Prior knowledge about the assigned group (c) Properties of the assigned group (sick or healthy)
Overview of Bayesian Decision Test patient Observations: Bayesian decision process is a data modeling process, e.g., estimate the data distribution K-means clustering: any relationship & difference?
Bayes’ Rule: normalization Who is who in Bayes’ rule
Classification problem Training data: examples of the form (d,h(d)) where d are the data objects to classify (inputs) and h(d) are the correct class info for d, h(d){1,…K} Goal: given dnew, provide h(dnew)
Why Bayesian? Provides practical learning algorithms E.g. Naïve Bayes Prior knowledge and observed data can be combined It is a generative (model based) approach, which offers a useful conceptual framework E.g. sequences could also be classified, based on a probabilistic model specification Any kind of objects can be classified, based on a probabilistic model specification
Bayes’ Rule: P(d|h): data distribution of group h P(h): importance data distribution of whole data set
Bayes’ Rule: Estimating the data distribution for whole data set Works to support Bayesian decision: Estimating the data distribution for whole data set Estimating the data distribution for specific group Prior knowledge about specific group
Gaussian Mixture Model (GMM) How to estimate the data distribution for a given dataset?
Gaussian Mixture Model (GMM)
Gaussian Mixture Model (GMM) What does GMM mean? 100 = 5*10 + 2*20 + 2*5 100 = 100*1 100 = 10*10 ………………. GMM may prefer larger K with ``smaller” Gaussians
Gaussian Mixture Model (GMM)
Gaussian Mixture Model (GMM) Real Data Distribution
Gaussian Mixture Model (GMM) Real Data Distribution Approximated Gaussian functions
Gaussian Mixture Model (GMM) Parameters to be estimated: Training Set: We assume K is available (or pre-defined)! Algorithms may always prefer larger K!
Matching between Gaussian Function and Samples Sampling
Given x, it is a function of and 2 Maximum Likelihood Sampling We want to maximize it. Given x, it is a function of and 2
Log-Likelihood Function Maximize this instead By setting and
Max. the Log-Likelihood Function
Max. the Log-Likelihood Function
Gaussian Mixture Models Rather than identifying clusters by “nearest” centroids Fit a Set of k Gaussians to the data Maximum Likelihood over a mixture model p(x) = \pi_0f_0(x) + \pi_1f_1(x) + \pi_2f_2(x) + \ldots + \pi_kf_k(x)
GMM example
Mixture Models Formally a Mixture Model is the weighted sum of a number of pdfs where the weights are determined by a distribution,
Gaussian Mixture Models GMM: the weighted sum of a number of Gaussians where the weights are determined by a distribution,
Expectation Maximization Both the training of GMMs and Graphical Models with latent variables can be accomplished using Expectation Maximization Step 1: Expectation (E-step) Evaluate the “responsibilities” of each cluster with the current parameters Step 2: Maximization (M-step) Re-estimate parameters using the existing “responsibilities” Similar to k-means training.
Latent Variable Representation We can represent a GMM involving a latent variable What does this give us? TODO: plate notation
GMM data and Latent variables
One last bit We have representations of the joint p(x,z) and the marginal, p(x)… The conditional of p(z|x) can be derived using Bayes rule. The responsibility that a mixture component takes for explaining an observation x.
Maximum Likelihood over a GMM As usual: Identify a likelihood function And set partials to zero…
Maximum Likelihood of a GMM Optimization of means.
Maximum Likelihood of a GMM Optimization of covariance Note the similarity to the regular MLE without responsibility terms.
Maximum Likelihood of a GMM Optimization of mixing term \frac{\partial \ln p(x|\pi, \mu,\Sigma) + \lambda\left(\sum_{k=1}^K \pi_k -1\right)}{\partial \pi_k}&=&
MLE of a GMM
EM for GMMs Initialize the parameters Evaluate the log likelihood Expectation-step: Evaluate the responsibilities Maximization-step: Re-estimate Parameters Check for convergence
EM for GMMs E-step: Evaluate the Responsibilities
EM for GMMs M-Step: Re-estimate Parameters
EM for GMMs Evaluate the log likelihood and check for convergence of either the parameters or the log likelihood. If the convergence criterion is not satisfied, return to E-Step.
Visual example of EM
Incorrect Number of Gaussians
Incorrect Number of Gaussians
Too many parameters For n-dimensional data, we need to estimate at least 3n parameters
Relationship to K-means K-means makes hard decisions. Each data point gets assigned to a single cluster. GMM/EM makes soft decisions. Each data point can yield a posterior p(z|x) Soft K-means is a special case of EM.
Soft means as GMM/EM Assume equal covariance matrices for every mixture component: Likelihood: Responsibilities: As epsilon approaches zero, the responsibility approaches unity. p(x|\mu_k,\Sigma_k) = \frac{1}{(2\pi\epsilon)^{M/2}}\exp\left\{-\frac{1}{2\epsilon}\lVert x-\mu_k\rVert^2\right\}
Soft K-Means as GMM/EM Overall Log likelihood as epsilon approaches zero: The expectation of soft k-means is the inter-cluster variability Note: only the means are re-estimated in Soft K- means. The covariance matrices are all tied.
General form of EM Given a joint distribution over observed and latent variables: Want to maximize: Initialize parameters E Step: Evaluate: M-Step: Re-estimate parameters (based on expectation of complete-data log likelihood) Check for convergence of parameters or likelihood
Gaussian Mixture Model
The conditional probability p(zk = 1|x) denoted by γ(zk ) is obtained by Bayes' theorem, We view πk as the prior probability of zk = 1, and γ(zk ) as the posterior probability. γ(zk ) is the responsibility that k-component takes for explaining the observation x.
Maximum Likelihood Estimation Given a data set of X = {x1,…, xN}, the log of the likelihood function is s.t.
Setting the derivatives of ln p(X|π, μ, Σ) with respect to μk to zero, we obtain
Finally, we maximize ln p(X|π, μ, Σ) with respect to the mixing coefficients πk. We use a Largrange multiplier objective ftn. f(x) constraints g(x) max f(x) s.t. g(x)=0
which gives we find λ = -N and
Initialise the means μk , covariances Σk and mixing coefficients πk. Ε step: Evaluate the responsibilities using the current parameter values 3. M step: RE-estimate the parameters using the current responsibilities 4. Evaluate the log likelihood and check for convergence of either the parameters or the log likelihood. If the convergence criterion is not satisfied, return to step 2.
Source code for GMM 1. EPFL http://lasa.epfl.ch/sourcecode/ 2. Google Source Code on GMM http://code.google.com/p/gmmreg/ 3. GMM & EM http://crsouza.blogspot.com/2010/10/gaussian-mixture-models-and-expectation.html
Probabilities – auxiliary slide for memory refreshing Have two dice h1 and h2 The probability of rolling an i given die h1 is denoted P(i|h1). This is a conditional probability Pick a die at random with probability P(hj), j=1 or 2. The probability for picking die hj and rolling an i with it is called joint probability and is P(i, hj)=P(hj)P(i| hj). For any events X and Y, P(X,Y)=P(X|Y)P(Y) If we know P(X,Y), then the so-called marginal probability P(X) can be computed as
Does patient have cancer or not? A patient takes a lab test and the result comes back positive. It is known that the test returns a correct positive result in only 98% of the cases and a correct negative result in only 97% of the cases. Furthermore, only 0.008 of the entire population has this disease. 1. What is the probability that this patient has cancer? 2. What is the probability that he does not have cancer? 3. What is the diagnosis?
Choosing Hypotheses Maximum Likelihood hypothesis: Generally we want the most probable hypothesis given training data. This is the maximum a posteriori hypothesis: Useful observation: it does not depend on the denominator P(d)
Now we compute the diagnosis To find the Maximum Likelihood hypothesis, we evaluate P(d|h) for the data d, which is the positive lab test and chose the hypothesis (diagnosis) that maximises it: To find the Maximum A Posteriori hypothesis, we evaluate P(d|h)P(h) for the data d, which is the positive lab test and chose the hypothesis (diagnosis) that maximises it. This is the same as choosing the hypotheses gives the higher posterior probability.
Naïve Bayes Classifier What can we do if our data d has several attributes? Naïve Bayes assumption: Attributes that describe data instances are conditionally independent given the classification hypothesis it is a simplifying assumption, obviously it may be violated in reality in spite of that, it works well in practice The Bayesian classifier that uses the Naïve Bayes assumption and computes the MAP hypothesis is called Naïve Bayes classifier One of the most practical learning methods Successful applications: Medical Diagnosis Text classification
Example. ‘Play Tennis’ data
Naïve Bayes solution Classify any new datum instance x=(a1,…aT) as: To do this based on training examples, we need to estimate the parameters from the training examples: For each target value (hypothesis) h For each attribute value at of each datum instance
Based on the examples in the table, classify the following datum x: x=(Outl=Sunny, Temp=Cool, Hum=High, Wind=strong) That means: Play tennis or not? Working:
Learning to classify text Learn from examples which articles are of interest The attributes are the words Observe the Naïve Bayes assumption just means that we have a random sequence model within each class! NB classifiers are one of the most effective for this task Resources for those interested: Tom Mitchell: Machine Learning (book) Chapter 6.
Results on a benchmark text corpus
Remember Bayes’ rule can be turned into a classifier Maximum A Posteriori (MAP) hypothesis estimation incorporates prior knowledge; Max Likelihood doesn’t Naive Bayes Classifier is a simple but effective Bayesian classifier for vector data (i.e. data with several attributes) that assumes that attributes are independent given the class. Bayesian classification is a generative approach to classification
Resources Textbook reading (contains details about using Naïve Bayes for text classification): Tom Mitchell, Machine Learning (book), Chapter 6. Software: NB for classifying text: http://www-2.cs.cmu.edu/afs/cs/project/theo-11/www/naive-bayes.html Useful reading for those interested to learn more about NB classification, beyond the scope of this module: http://www-2.cs.cmu.edu/~tom/NewChapters.html
GMM & Bayesian Decision Open Issues Number of Gaussians K Initializations of parameters Pay more attentions on majority
GMM & Bayesian Rule Advantages Intuitive modeling Probabilistic Disadvantages Intuitive modeling Probabilistic Multi-class solution Number of Gaussians K Initializations of Parameters Not-discriminative Feature dimensions Majority vs. minority
GMM for K-Means Clustering
GMM for K-Means Clustering
KNN (K nearest neighbors) Classifier Test sample
Problems of GMM Number of Gaussians K How to estimate K? Majority vs. Minority How to make right decision for rare events?
Problems of GMM Parameter Initialization & Feature Dimensions What are the solutions? Not-discriminative What’s the solution?