一、什么是极大似然估计
机器学习中,概率模型的训练过程就是**参数估计(Parameter Estimation)**的过程,对于参数估计,统计学界的两个学派分别提供了不同的解决方案:频率主义学派认为参数虽然未知,但却是客观存在的固定值,因此可以通过优化似然函数等准则来确定参数值;贝叶斯学派则认为参数是未观察到的随机变量,其本身也可有分布,因此可假定参数服从一个先验分布,然后基于观测的数据来计算参数的后验分布。**极大似然估计(Maximum LikeliHood Estimation)**源自于频率主义学派,它是一种根据数据采样来估计概率分布参数的经典方法。
二、参数训练过程
令
D
c
D_c
Dc表示训练集
D
D
D中第
c
c
c类样本组成的集合,假设这些样本是独立同分布的,则参数
θ
c
θ_c
θc对于数据集
D
c
D_c
Dc的似然是
P
(
D
c
∣
θ
c
)
=
∏
x
∈
D
c
P
(
x
∣
θ
c
)
(1)
P\left(D_{c} | \theta_{c}\right)=\prod_{x \in D_{c}} P\left(x | \theta_{c}\right)\tag{1}
P(Dc∣θc)=x∈Dc∏P(x∣θc)(1)
对
θ
c
\theta_c
θc进行极大似然估计,就是去寻找能最大化似然
P
(
D
c
∣
θ
c
)
P\left(D_{c} | \theta_{c}\right)
P(Dc∣θc)的参数值
θ
c
^
\hat{\theta_c}
θc^。直观上看,极大似然估计是视图在
θ
c
\theta_c
θc上所有可能的取值中,找到一个能使数据出现的“可能性”最大的值。
式(1)中的连乘操作容易造成下溢,通常使用对数似然(log-likelihood)
L
(
θ
c
)
=
log
P
(
D
c
∣
θ
c
)
=
∑
x
∈
D
c
log
P
(
x
∣
θ
c
)
(2)
\begin{aligned} L\left(\theta_{c}\right) &=\log P\left(D_{c} | \theta_{c}\right) \\ &=\sum_{x \in D_{c}} \log P\left(x | \theta_{c}\right) \end{aligned}\tag{2}
L(θc)=logP(Dc∣θc)=x∈Dc∑logP(x∣θc)(2)
此时的参数
θ
c
\theta_c
θc的极大似然估计
θ
c
^
\hat{\theta_c}
θc^为
θ
^
c
=
arg
max
θ
c
L
(
θ
c
)
(3)
\hat{\theta}_{c}=\underset{\theta_{c}}{\arg \max } L\left(\theta_{c}\right)\tag{3}
θ^c=θcargmaxL(θc)(3)
【例 1】假设一个袋子装有白球与红球,比例未知,现在抽取10次(每次抽完都放回,保证事件独立性),假设抽到了7次白球和3次红球,在此数据样本条件下,采用极大似然估计法求解袋子中白球的比例。
【解】设
θ
\theta
θ为袋子中白球的比例,根据公式(1)可以建立实际情况下的概率
P
(
x
1
,
x
2
,
…
,
x
10
∣
θ
)
=
P
(
x
1
∣
θ
)
⋅
P
(
x
2
∣
θ
)
…
P
(
x
10
∣
θ
)
(4)
P\left(x_1,x_2,\ldots,x_{10} | \theta\right)=P\left(x_1|\theta\right) \cdot P\left(x_2|\theta\right) \ldots P\left(x_{10}|\theta\right)\tag{4}
P(x1,x2,…,x10∣θ)=P(x1∣θ)⋅P(x2∣θ)…P(x10∣θ)(4)
对数似然为
L
(
θ
)
=
ln
P
(
x
1
,
x
2
,
…
,
x
10
∣
θ
)
=
ln
[
θ
7
(
1
−
θ
)
3
]
(5)
L(\theta)=\ln P\left(x_1,x_2,\ldots,x_{10} | \theta\right)=\ln \left[\theta^7(1-\theta)^3\right]\tag{5}
L(θ)=lnP(x1,x2,…,x10∣θ)=ln[θ7(1−θ)3](5)
对
θ
\theta
θ求导数可以得到
L
′
(
θ
)
=
7
θ
−
3
1
−
θ
=
0
⇒
θ
^
=
0.7
(6)
L^{\prime}(\theta)=\frac{7}{\theta}-\frac{3}{1-\theta}=0 \Rightarrow \hat{\theta}=0.7 \tag{6}
L′(θ)=θ7−1−θ3=0⇒θ^=0.7(6)
由此可得,当抽取白球的概率为0.7时,最可能产生10次抽取抽到白球7次的事件。
【例 2】假设有一组采样值 ( x 1 , x 2 , … , x n ) (x_1,x_2,\ldots,x_n) (x1,x2,…,xn)服从正态分布 N ( μ , σ 2 ) N(\mu,\sigma^2) N(μ,σ2),采用极大似然估计法估计参数,使得产生这个采样值的概率最大。
【解】正态分布的概率为
f
(
x
)
=
1
2
π
σ
exp
(
−
(
x
−
μ
)
2
2
σ
2
)
(7)
f(x)=\frac{1}{\sqrt{2 \pi} \sigma} \exp \left(-\frac{(x-\mu)^{2}}{2 \sigma^{2}}\right)\tag{7}
f(x)=2πσ1exp(−2σ2(x−μ)2)(7)
则产生采样值
(
x
1
,
x
2
,
…
,
x
n
)
(x_1,x_2,\ldots,x_n)
(x1,x2,…,xn)的概率为
P
(
x
1
,
x
2
,
…
,
x
n
∣
θ
)
=
(
1
2
π
σ
)
n
exp
(
−
1
2
σ
2
∑
i
=
1
n
(
x
i
−
μ
)
2
)
(8)
P\left(x_{1}, x_{2}, \ldots, x_{n} | \theta\right)=\left(\frac{1}{\sqrt{2 \pi} \sigma}\right)^{n} \exp \left(-\frac{1}{2 \sigma^{2}} \sum_{i=1}^{n}(x_i-\mu)^{2}\right) \tag{8}
P(x1,x2,…,xn∣θ)=(2πσ1)nexp(−2σ21i=1∑n(xi−μ)2)(8)
对上式两边取对数可以得到
L
(
θ
)
=
ln
P
(
x
1
,
x
2
,
…
,
x
n
∣
θ
)
=
n
ln
1
2
π
σ
−
1
2
σ
2
∑
i
=
1
n
(
x
i
−
μ
)
2
(9)
L(\theta)=\ln P\left(x_1,x_2,\ldots,x_{n} | \theta\right)=n\ln\frac{1}{\sqrt{2 \pi} \sigma}-\frac{1}{2 \sigma^{2}} \sum_{i=1}^{n}(x_i-\mu)^{2}\tag{9}
L(θ)=lnP(x1,x2,…,xn∣θ)=nln2πσ1−2σ21i=1∑n(xi−μ)2(9)
θ
\theta
θ有两个参数
μ
,
σ
2
\mu,\sigma^2
μ,σ2,对
μ
\mu
μ求偏导数得
∂
L
(
θ
)
∂
μ
=
−
1
σ
2
∑
i
=
1
n
(
μ
−
x
i
)
=
0
(10)
\frac{\partial L(\theta)}{\partial \mu}=-\frac{1}{\sigma_{2}}\sum_{i=1}^{n}(\mu-x_i)=0\tag{10}
∂μ∂L(θ)=−σ21i=1∑n(μ−xi)=0(10)
可以得到
μ
^
=
1
n
∑
i
=
1
n
x
i
(11)
\hat{\mu}=\frac{1}{n}\sum_{i=1}^{n}x_i\tag{11}
μ^=n1i=1∑nxi(11)
对
σ
2
\sigma^2
σ2求偏导数得
∂
L
(
θ
)
∂
σ
2
=
−
n
+
1
σ
2
∑
i
=
1
n
(
x
i
−
μ
^
)
2
=
0
(12)
\frac{\partial L(\theta)}{\partial \sigma^{2}}=-n+\frac{1}{\sigma^{2}} \sum_{i=1}^{n}(x_i-\hat{\mu})^{2}=0\tag{12}
∂σ2∂L(θ)=−n+σ21i=1∑n(xi−μ^)2=0(12)
可以得到
σ
2
^
=
1
n
∑
i
=
1
n
(
x
i
−
μ
^
)
2
(13)
\hat{\sigma^{2}}=\frac{1}{n}\sum_{i=1}^{n}(x_i-\hat{\mu})^{2}\tag{13}
σ2^=n1i=1∑n(xi−μ^)2(13)
三、参考
[1] 周志华. 机器学习, 清华大学出版社
[2] 简书博客