Bernoulli Distribution and Maximum Likelihood Estimation
In questa pagina 4
Preparation for Logistic RegressionLogistic regression models the probability p of the positive class: the logit (log of the odds p/(1-p)) is assumed linear in the input, logit(p) = w^T x = z. Inverting it gives p = 1/(1 + e^(-z)), the logistic sigmoid; an object goes to class 1 when the sigmoid exceeds 0.5, i.e. when z > 0. The parameters are learned by maximising the Bernoulli log-likelihood, equivalently minimising the cost J = -y log(yhat) - (1 - y) log(1 - yhat), by gradient descent with gradient (1/m) X^T (h(x) - y).Logistic Regression →, taken from the handwritten page of the lecture that introduces it. The general theory of the method is in Maximum Likelihood Estimation - OverviewMaximum likelihood estimation starts from a probability model of the noise, turns it into the likelihood of the parameters given the data, and chooses the parameters that maximise it, instead of only minimising a weighted squared error.Maximum Likelihood Estimation - Overview →; the distribution itself in Bernoulli, Uniform and Binomial Random VariablesBernoulli, discrete uniform and binomial random variables are the basic families with finite alphabet; the binomial counts successes in n independent identical trials, and when independence or constant probability fails (urns without replacement) the hypergeometric density appears instead.Bernoulli, Uniform and Binomial Random Variables →.
1. The Bernoulli distribution (binary variables)
A coin is tossed; the outcomes are
- : heads (the positive outcome);
- : tails (the negative outcome).
Let be the unknown parameter, the probability of heads: and . In one formula (the page first writes the two cases, then the compact form):
Check: for the exponent of is and only is left; for the exponent of is and only is left.
2. The likelihood function
Observed sequence of tosses, for instance H T T H H H T ... Each toss contributes one factor (the page shows how an H gives and a T gives ).
Independence assumption (of the data points) and identical distribution: the observations are i.i.d. (identically and independently distributed). Independence lets the probability of a sequence be the product of the probabilities of the single tosses; "identical" says that the same is used for every toss. For three tosses H T H:
The likelihood of the data is this probability viewed as a function of :
If heads came up times in tosses, the product collects factors and factors :
3. Log-likelihood and maximum likelihood estimation
A product is awkward to differentiate; the logarithm turns it into a sum and has its maximum at the same (it is increasing). The log-likelihood is
Maximum likelihood estimation (MLE): choose the that maximises the log-likelihood. Differentiate and set to zero (the chain rule gives the factor for ):
Cross-multiply and expand:
the terms cancel (crossed out in the page), so
The maximum likelihood estimate of the probability of heads is the observed fraction of heads. (The page does not check the second derivative; the conclusion is the intuitive one.)
4. Why it matters in the course
In Logistic RegressionLogistic regression models the probability p of the positive class: the logit (log of the odds p/(1-p)) is assumed linear in the input, logit(p) = w^T x = z. Inverting it gives p = 1/(1 + e^(-z)), the logistic sigmoid; an object goes to class 1 when the sigmoid exceeds 0.5, i.e. when z > 0. The parameters are learned by maximising the Bernoulli log-likelihood, equivalently minimising the cost J = -y log(yhat) - (1 - y) log(1 - yhat), by gradient descent with gradient (1/m) X^T (h(x) - y).Logistic Regression → each example is a Bernoulli trial whose probability of the positive class is produced by the model; the same likelihood, one factor per example, gives the cost function that logistic regression minimises.
Versione ripasso
- Bernoulli: (heads, positive) with probability , (tails) with ; .
- i.i.d. assumption: independent and identically distributed, so probabilities multiply: .
- Likelihood ; with heads: .
- Log-likelihood ; maximise it = MLE.
- .
- Used for Logistic RegressionLogistic regression models the probability p of the positive class: the logit (log of the odds p/(1-p)) is assumed linear in the input, logit(p) = w^T x = z. Inverting it gives p = 1/(1 + e^(-z)), the logistic sigmoid; an object goes to class 1 when the sigmoid exceeds 0.5, i.e. when z > 0. The parameters are learned by maximising the Bernoulli log-likelihood, equivalently minimising the cost J = -y log(yhat) - (1 - y) log(1 - yhat), by gradient descent with gradient (1/m) X^T (h(x) - y).Logistic Regression → (see Maximum Likelihood Estimation - OverviewMaximum likelihood estimation starts from a probability model of the noise, turns it into the likelihood of the parameters given the data, and chooses the parameters that maximise it, instead of only minimising a weighted squared error.Maximum Likelihood Estimation - Overview →).
- Typical errors: forgetting the factor when differentiating ; confusing likelihood (function of ) with probability of data.