Salta al contenuto
Note per Studenti Bernoulli Distribution and Maximum Likelihood Estimation Report

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

  • X=1X=1: heads (the positive outcome);
  • X=0X=0: tails (the negative outcome).

Let θ\theta be the unknown parameter, the probability of heads: P(X=1∣θ)=θP(X=1\mid\theta)=\theta and P(X=0∣θ)=1−θP(X=0\mid\theta)=1-\theta. In one formula (the page first writes the two cases, then the compact form):

P(x∣θ)={θx=11−θx=0=θx(1−θ)1−x.P(x\mid\theta)=\begin{cases}\theta&x=1\\1-\theta&x=0\end{cases}\qquad=\qquad\theta^{x}(1-\theta)^{1-x}.

Check: for x=1x=1 the exponent of 1−θ1-\theta is 00 and only θ\theta is left; for x=0x=0 the exponent of θ\theta is 00 and only 1−θ1-\theta is left.

2. The likelihood function

Observed sequence of tosses, for instance H T T H H H T ... Each toss contributes one factor θx(1−θ)1−x\theta^{x}(1-\theta)^{1-x} (the page shows how an H gives θ\theta and a T gives 1−θ1-\theta).

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 θ\theta is used for every toss. For three tosses H T H:

P(HTH)=P(H) P(T) P(H)=θ (1−θ) θ=θ2(1−θ).P(\text{HTH})=P(\text{H})\,P(\text{T})\,P(\text{H})=\theta\,(1-\theta)\,\theta=\theta^{2}(1-\theta).

The likelihood of the data is this probability viewed as a function of θ\theta:

L(θ)=∏i=1nθxi(1−θ)1−xi.L(\theta)=\prod_{i=1}^{n}\theta^{x_i}(1-\theta)^{1-x_i}.

If heads came up KK times in nn tosses, the product collects KK factors θ\theta and n−Kn-K factors 1−θ1-\theta:

  L(θ)=θK(1−θ) n−K  (likelihood function).\boxed{\;L(\theta)=\theta^{K}(1-\theta)^{\,n-K}\;}\qquad\text{(likelihood function).}

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 θ\theta (it is increasing). The log-likelihood is

ℓ(θ)=log⁡L(θ)=Klog⁡θ+(n−K)log⁡(1−θ).\ell(\theta)=\log L(\theta)=K\log\theta+(n-K)\log(1-\theta).

Maximum likelihood estimation (MLE): choose the θ\theta that maximises the log-likelihood. Differentiate and set to zero (the chain rule gives the factor −1-1 for log⁡(1−θ)\log(1-\theta)):

∂ℓ(θ)∂θ=K⋅1θ+(n−K)⋅11−θ⋅(−1)=0  ⟹  Kθ=n−K1−θ.\frac{\partial\ell(\theta)}{\partial\theta}=K\cdot\frac1\theta+(n-K)\cdot\frac{1}{1-\theta}\cdot(-1)=0 \;\Longrightarrow\;\frac K\theta=\frac{n-K}{1-\theta}.

Cross-multiply and expand:

(1−θ)K=(n−K)θ  ⟹  K−θK=nθ−θK  ⟹  K=nθ,(1-\theta)K=(n-K)\theta\;\Longrightarrow\;K-\theta K=n\theta-\theta K\;\Longrightarrow\;K=n\theta,

the terms −θK-\theta K cancel (crossed out in the page), so

  θ^=Kn  \boxed{\;\hat\theta=\frac{K}{n}\;}

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 y^\hat y is produced by the model; the same likelihood, one factor per example, gives the cost function that logistic regression minimises.

Versione ripasso

Teoria collegata