Recall the Bayes Optimal classifier. If we are provided with the true source distribution over example-label pairs , we can predict the most likely label for : One very general approach to learning motivated by this is to estimate directly from the training data. If it is possible (to a good approximation) to construct an estimate we could then use the Bayes Optimal classifier on in practice.
Many supervised learning strategies can be viewed as estimating . Generally, they fall into two categories:
When we estimate the full joint distribution , then we call it generative learning, named after the fact that we can use the estimate of to generate new samples that approximate the source distribution.
When we only estimate the conditional distributions directly, then we call it discriminative learning.
So how can we estimate 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 (ordered) sequence of outcomes: . Based on these samples, how would you estimate ?
We observed heads and tails. So, intuitively,
But is this reasoning valid? 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 sequence of coin tosses (for a particular coin with a fixed probability of coming up heads) is that the results of the flips are independent. Formally, if is the indicator random variable representing the event that the result of the th flip is heads, and we suppose that the probability of the coin coming up heads is , then
By independence, the probability of many such flips coming up in any particular way (i.e. in some specific order ) will be the product of the probabilities
We can write this a little more consisely if we let denote the number of heads and denote the number of tails.
In this case, we would just have
MLE Principle: Find to maximize the likelihood of the data, :
where here we slightly abuse notation to let also denote the event that the dataset is observed.
Often we can solve this maximization problem with a simple three step procedure:
Plug in all the terms for the distribution, and take the of the function.
Compute its derivative, and equate it with zero.
Solve the resulting equation for , and check that it's a maximum.
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 or a saddle point, by verifying that the Hessian is negative-definite.)
Returning to our coin-flipping example, 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 your model/distribution family includes the true source distribution — that is, there exists some such that — then as the number of independent examples approaches infinity, the distribution produced by MLE approaches the true source distribution .
But the MLE can overfit the data if is small. It works well when is large.
If you do not have the correct model 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
Suppose you have a hunch that is close to . But your sample size is small, so you don't trust your estimate.
Simple fix: Add imaginary throws that would result in the we have a hunch it is close to (e.g. ). For example, we could add Heads and Tails to your data, which would result in the modified MLE estimate
For large , this is an insignificant change.
For small , it incorporates your "prior belief" about what should be.
But this was all very ad hoc. Can we justify this and derive it formally?
The Bayesian Way
Model as a random variable, with its own marginal distribution .
Here and the other observed variables are jointly distributed.
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 the beta function
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 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 the conjugate prior of (the same distributional family as) the binomial distribution, which is the distribution of the number of heads that would come up in this experiment. This means that 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)
MAP Principle:
Find that maximizes the posterior distribution :
For out coin flipping scenario, we get:
A few comments:
The MAP estimate is identical to MLE with hallucinated heads and hallucinated tails. (At least, if and are integers.)
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!
The "True" Bayesian approach
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 predictions about the label of a test sample with features . Here we consider and to be a "fresh" test example independent of all the examples in the training dataset conditioned on . Concretely, this corresponds to the distribution over given by
Unfortunately, the above is generally intractable in closed form.
Sampling techniques, such as Monte Carlo approximations, are used to approximate the distribution.
A common exception where this is tractable is the case of Gaussian Processes.
Another exception is actually our coin toss example. Here, we don't really have features, so we can ignore the in the above formulation.
To make predictions using in our coin tossing example, we can see that the distribution of a fresh flip is
If we let , which is just a constant independent of , then
and
Integrating the former by parts (and observing that the boundary term is because it vanishes at both and ) gives
and so
Effectively, this says that the Bayesian posterior for a fresh example drawn from the distribution is the same as the distribution of an example selected at random from the training set with the extra "hallucinated" examples added.
Summary: 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.