Maximum Likelihood Estimation (MLE)

 

๐Ÿ“˜ Maximum Likelihood Estimation (MLE)

๐Ÿ”น Definition

Maximum Likelihood Estimation (MLE) is a method for estimating the parameters of a statistical model by maximizing the likelihood of the observed data.

๐Ÿ‘‰ In simple terms:
MLE finds parameter values that make the observed data most probable.


๐Ÿ”น Basic Idea

Assume:

  • Dataset: D={x1,x2,...,xn}D = \{x_1, x_2, ..., x_n\}
  • Model parameters: ฮธ\theta

๐Ÿ‘‰ Likelihood function:

L(ฮธ)=P(Dฮธ)L(\theta) = P(D \mid \theta)

๐Ÿ‘‰ Goal:

ฮธ^=argmaxฮธP(Dฮธ)\hat{\theta} = \arg\max_{\theta} P(D \mid \theta)

๐Ÿ”น Intuition

MLE answers the question:

“Given this data, what parameter values are most likely to have generated it?”


๐Ÿ”น Likelihood vs Probability

  • Probability: P(Dataฮธ)P(Data \mid \theta) → data varies
  • Likelihood: same expression, but viewed as a function of ฮธ\theta

๐Ÿ‘‰ Key difference:

  • Data is fixed
  • Parameters are variable

๐Ÿ”นLog-Likelihood 

Instead of maximizing likelihood, we maximize log-likelihood:

โ„“(ฮธ)=logP(Dฮธ)\ell(\theta) = \log P(D \mid \theta)

Why log?

  • Converts products → sums
  • Easier differentiation
  • Numerically stable

๐Ÿ”น General Steps in MLE

  1. Define probabilistic model P(xฮธ)P(x \mid \theta)
  2. Write likelihood function
  3. Take log-likelihood
  4. Differentiate w.r.t. parameters
  5. Set derivative = 0
  6. Solve for parameters

๐Ÿ”นExample 1: Bernoulli Distribution

๐Ÿ“Œ Problem:

Assume we have:

  • Data: x1,x2,...,xnx_1, x_2, ..., x_n
  • Each xi{0,1}x_i \in \{0,1\} (Bernoulli trials)

Let:

  • pp = probability of success (i.e., x=1x = 1)

๐Ÿ‘‰ Goal: Estimate pp using Maximum Likelihood Estimation (MLE)

Eg: Coin toss (Heads = 1, Tails = 0)

  • pp = probability of heads

Bernoulli Distribution

For a single observation:

P(xip)=pxi(1p)1xiP(x_i \mid p) = p^{x_i}(1-p)^{1-x_i}

Likelihood Function

For independent observations:

L(p)=i=1npxi(1p)1xiL(p) = \prod_{i=1}^{n} p^{x_i}(1-p)^{1-x_i}

L(p) = \prod p^{x_i}(1-p)^{1-x_i}

Log-Likelihood

Take logarithm:

โ„“(p)=i=1n[xilogp+(1xi)log(1p)]\ell(p) = \sum_{i=1}^{n} \left[ x_i \log p + (1-x_i)\log(1-p) \right]

Differentiate w.r.t. pp

dโ„“dp=i=1n[xip1xi1p]\frac{d\ell}{dp} = \sum_{i=1}^{n} \left[ \frac{x_i}{p} - \frac{1-x_i}{1-p} \right]

Set Derivative = 0

i=1n[xip1xi1p]=0\sum_{i=1}^{n} \left[ \frac{x_i}{p} - \frac{1-x_i}{1-p} \right] = 0

Simplify

Split the summation:

1pxi=11p(1xi)\frac{1}{p} \sum x_i = \frac{1}{1-p} \sum (1 - x_i)

Let:

  • xi=k\sum x_i = k (number of successes)
  • (1xi)=nk\sum (1-x_i) = n - k

So:

kp=nk1p\frac{k}{p} = \frac{n-k}{1-p}

Solve for pp

Cross-multiply:

k(1p)=(nk)pk(1-p) = (n-k)p
kkp=npkpk - kp = np - kp
k=npk = npp=knp = \frac{k}{n}

Final Result

p^=1ni=1nxi\hat{p} = \frac{1}{n} \sum_{i=1}^{n} x_i

๐Ÿ‘‰ This is the sample mean


Interpretation

  • p^\hat{p} = proportion of 1’s in data
  • i.e., fraction of successes

๐Ÿ‘‰ Example:

  • Data: (1, 0, 1, 1, 0)
  • p^=3/5=0.6\hat{p} = 3/5 = 0.6

 Important Insight

๐Ÿ‘‰ For Bernoulli distribution:

MLE estimate of probability = sample mean


 Why This Makes Sense

  • If many 1’s → higher probability
  • If fewer 1’s → lower probability

๐Ÿ‘‰ MLE naturally captures empirical frequency

Variance of Bernoulli Distribution

We know:

Var(X)=p(1p)\text{Var}(X) = p(1 - p)


MLE of Variance

๐Ÿ‘‰ Substitute MLE of pp:

Var^=p^(1p^)\widehat{\text{Var}} = \hat{p}(1 - \hat{p})


Final Expression

Var^=(kn)(1kn)\widehat{\text{Var}} = \left(\frac{k}{n}\right) \left(1 - \frac{k}{n}\right)


✅ Final Result

Var^=kn(1kn)\boxed{ \widehat{\text{Var}} = \frac{k}{n}\left(1 - \frac{k}{n}\right) }


Alternative Form

Var^=xห‰(1xห‰)\widehat{\text{Var}} = \bar{x}(1 - \bar{x})

where:

xห‰=1nxi\bar{x} = \frac{1}{n}\sum x_i


๐Ÿ”นExample 2: Gaussian Distribution

Problem Setup

Assume:

  • Data: x1,x2,...,xn
  • Each xiN(ฮผ,ฯƒ2)

๐Ÿ‘‰ Unknown parameters:

  • Mean ฮผ
  • Variance ฯƒ2

๐Ÿ‘‰ Goal: Estimate ฮผ and ฯƒ2 using MLE

Gaussian Probability Density Function

For one data point:

p(xฮผ,ฯƒ2)=12ฯ€ฯƒ2exp((xฮผ)22ฯƒ2)p(x \mid \mu, \sigma^2)=\frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)

Likelihood Function

For independent data:

L(ฮผ,ฯƒ2)=i=1np(xiฮผ,ฯƒ2)L(\mu, \sigma^2) = \prod_{i=1}^{n} p(x_i \mid \mu, \sigma^2)
=i=1n12ฯ€ฯƒ2exp((xiฮผ)22ฯƒ2)= \prod_{i=1}^{n} \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x_i-\mu)^2}{2\sigma^2}\right)

Log-Likelihood

Take logarithm:

โ„“(ฮผ,ฯƒ2)=n2log(2ฯ€ฯƒ2)12ฯƒ2i=1n(xiฮผ)2\ell(\mu, \sigma^2) = -\frac{n}{2}\log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\sum_{i=1}^{n}(x_i-\mu)^2

MLE for Mean ฮผ

Step 1: Differentiate w.r.t. ฮผ

โ„“ฮผ=1ฯƒ2i=1n(xiฮผ)\frac{\partial \ell}{\partial \mu} = \frac{1}{\sigma^2}\sum_{i=1}^{n}(x_i - \mu)


Step 2: Set derivative = 0

i=1n(xiฮผ)=0\sum_{i=1}^{n}(x_i - \mu) = 0

Step 3: Solve

xinฮผ=0\sum x_i - n\mu = 0
ฮผ=1ni=1nxi\mu = \frac{1}{n}\sum_{i=1}^{n} x_i

Result:

ฮผ^=sample mean\hat{\mu} = \text{sample mean}

MLE for Variance ฯƒ2\sigma^2

Step 1: Differentiate w.r.t. ฯƒ2\sigma^2


โ„“ฯƒ2=n2ฯƒ2+12ฯƒ4i=1n(xiฮผ)2\frac{\partial \ell}{\partial \sigma^2} = -\frac{n}{2\sigma^2} + \frac{1}{2\sigma^4}\sum_{i=1}^{n}(x_i - \mu)^2

Step 2: Set derivative = 0

n2ฯƒ2+12ฯƒ4(xiฮผ)2=0-\frac{n}{2\sigma^2} + \frac{1}{2\sigma^4}\sum (x_i - \mu)^2 = 0

Step 3: Solve

Multiply both sides:

nฯƒ2=(xiฮผ)2n\sigma^2 = \sum (x_i - \mu)^2
ฯƒ2=1ni=1n(xiฮผ)2\sigma^2 = \frac{1}{n}\sum_{i=1}^{n}(x_i - \mu)^2

Result:

ฯƒ^2=sample variance (with denominator n)\hat{\sigma}^2 = \text{sample variance (with denominator } n\text{)}

 Final MLE Estimates

ฮผ^=1nxi\hat{\mu} = \frac{1}{n}\sum x_i ฯƒ^2=1n(xiฮผ)2\hat{\sigma}^2 = \frac{1}{n}\sum (x_i - \mu)^2

๐Ÿ‘‰ These are intuitive:

  • Mean → average
  • Variance → spread

๐Ÿ”น Properties of MLE 

✅ 1. Consistency

  • Estimates approach true value as data increases

✅ 2. Efficiency

  • Has minimum variance (under conditions)

✅ 3. Asymptotic Normality

  • Distribution becomes normal for large samples

❌ 4. Bias

  • Can be biased for small samples

๐Ÿ”น  Advantages

  • Simple and widely applicable
  • Works for many distributions
  • Strong theoretical foundation

๐Ÿ”น Disadvantages

  • Sensitive to outliers
  • Requires correct model assumption
  • Can overfit with small data

๐Ÿ”น Applications of MLE

  • Linear Regression
  • Logistic Regression
  • Naive Bayes
  • Hidden Markov Models
  • Neural Networks (via loss functions)

๐Ÿ”น Connection to Loss Functions

MLE often leads to common loss functions:

Model    Loss Function
Gaussian    Mean Squared Error
Bernoulli    Cross-Entropy
Multinomial    Log-loss

๐Ÿ“ Summary 

  • MLE finds parameters that maximize likelihood of data
  • Uses:
    • Likelihood function
    • Log-likelihood
  • Common results:
    • Mean = average
    • Variance = spread
  • Widely used in ML models

Comments

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming