Remember the Bayes Optimal classifier: If we are provided with we can predict the most likely label for , formally . It is therefore worth considering if we can estimate directly from the training data. If this is possible (to a good approximation) we could then use the Bayes Optimal classifier in practice on our estimate of .
In fact, many supervised learning can be viewed as estimating . Generally, they fall into two categories:
When we estimate , then we call it generative learning.
When we only estimate directly, then we call it discriminative learning.
So how can we estimated probability distributions from samples?
Simple scenario: coin toss
Suppose you find a coin and it's ancient and very valuable. Naturally, you ask yourself, "What is the probability that this coin comes up heads when I toss it?"
You toss it times and obtain the following sequence of outcomes: . Based on these samples, how would you estimate ?
We observed heads and tails. So, intuitively,
Can we derive this more formally?
Maximum Likelihood Estimation (MLE)
The estimator we just mentioned is the Maximum Likelihood Estimate (MLE). For MLE you typically proceed in two steps: First, you make an explicit modeling assumption about what type of distribution your data was sampled from. Second, you set the parameters of this distribution so that the data you observed is as likely as possible.
Let us return to the coin example. A natural assumption about a coin toss is that the distribution of the observed outcomes is a binomial distribution. The binomial distribution has two parameters and and it captures the distribution of independent Bernoulli (i.e. binary) random events that have a positive outcome with probability . In our case is the number of coin tosses, and could be the probability of the coin coming up heads (e.g. ). Formally, the binomial distribution is defined as
and it computes the probability that we would observe exactly heads, tails, if a coin was tossed times and its probability of coming up heads is .
MLE Principle: Find to maximize the likelihood of the data, :
Often we can solve this maximization problem with a simple two step procedure: 1. plug in all the terms for the distribution, and take the of the function. 2. Compute its derivative, and equate it with zero. Taking the log of the likelihood (often referred to as the log-likelihood) does not change its maximum (as the log is a monotonic function, and the likelihood positive), but it turns all products into sums which are much easier to deal with when you differentiate. Equating the derivative with zero is a standard way to find an extreme point. (To be precise you should verify that it really is a maximum and not a minimum, by verifying that the second derivative is negative.)
Returning to our binomial distribution, we can now plug in the definition and compute the log-likelihood:
We can then solve for by taking the derivative and equating it with zero. This results in
A nice sanity check is that .
MLE gives the explanation of the data you observed.
If is large and your model/distribution is correct (that is includes the true model), then MLE finds the true parameters.
But the MLE can overfit the data if is small. It works well when is large.
If you do not have the correct model (and is small) then MLE can be terribly wrong!
For example, suppose you observe H,H,H,H,H. What is ?
Simple scenario: coin toss with prior knowledge
Assume you have a hunch that is close to . But your sample size is small, so you don't trust your estimate.
Simple fix: Add imaginery throws that would result in (e.g. ). Add Heads and Tails to your data.
For large , this is an insignificant change.
For small , it incorporates your "prior belief" about what should be.
Can we derive this formally?
The Bayesian Way
Model as a random variable, drawn from a distribution .
Note that is not a random variable associated with an event in a sample space.
In frequentist statistics, this is forbidden. In Bayesian statistics, this is allowed and you can specify a prior belief defining what values you believe is likely to take on.
Now, we can look at (recall Bayes Rule!), where
is the prior distribution over the parameter(s) , before we see any data.
is the likelihood of the data given the parameter(s) .
is the posterior distribution over the parameter(s) after we have observed the data.
A natural choice for the prior ) is the Beta distribution:
where is the normalization constant (if this looks scary don't worry about it, it is just there to make sure everything sums to and to scare children at Halloween). Note that here we only need a distribution over a single binary random variable . (The multivariate generalization of the Beta distribution is the Dirichlet distribution.)
Why is the Beta distribution a good fit?
it models probabilities ( lives on )
it is of the same distributional family as the binomial distribution (conjugate prior) the math will turn out nicely:
So far, we have a distribution over . How can we get an estimate for ?
Maximum a Posteriori Probability Estimation (MAP)
For example, we can choose to be the most likely given the data.
MAP Principle:
Find that maximizes the posterior distribution :
For our coin flipping scenario, we get:
A few comments:
The MAP estimate is identical to MLE with hallucinated heads and hallucinated tails
As , as and become irrelevant compared to very large .
MAP is a great estimator if an accurate prior belief is available (and mathematically tractable).
If is small, MAP can be very wrong if prior belief is wrong!
"True" Bayesian approach
Note that MAP is only one way to get an estimator. There is much more information in , and it seems like a shame to simply compute the mode and throw away all other information. A true Bayesian approach is to use the posterior predictive distribution directly to make prediction about the label of a test sample with features :
Unfortunately, the above is generally intractable in closed form and
sampling techniques, such as Monte Carlo approximations, are used to approximate the distribution. A pleasant exception are Gaussian Processes, which we will cover later in this course.
Another exception is actually our coin toss example.
To make predictions using in our coin tossing example, we can use
Here, we used the fact that we defined (this is only the case because we assumed that our data is drawn from a binomial distribution - in general this would not hold).
Machine Learning and estimation
In supervised Machine learning you are provided with training data . You use this data to train a model, represented by its parameters . With this model you want to make predictions on a test point .
MLE Prediction: Learning: . Here is purely a model parameter.
MAP Prediction: Learning: . Here is a random variable.
"True Bayesian" Prediction: . Here is integrated out - our prediction takes all possible models into account.
As always the differences are subtle. In MLE we maximize in MAP we maximize . So essentially in MAP we only add the term to our optimization. This term is independent of the data and penalizes if the parameters, deviate too much from what we believe is reasonable. We will later revisit this as a form of regularization, where will be interpreted as a measure of classifier complexity.