从极大似然估计(MLE)角度看损失函数(loss function)

    科技2022-07-10  167

    1. 极大似然估计的理解

    极大似然估计(Maximum likelihood estimation, 简称MLE),对于给定样本 X = ( x 1 , x 2 , . . . , x n ) X =(x_1,x_2,...,x_n) X=(x1,x2,...,xn),我们推定模型参数 θ \theta θ,使得由该模型产生给定样本的概率最大,即似然函数 f ( X ∣ θ ) f(X|\theta) f(Xθ)最大。

    假设每个样本独立,似然函数为: l i k e l i h o o d ( θ ) = f ( X ∣ θ ) = ∏ i = 1 n f ( x i ∣ θ ) likelihood(\theta)=f(X|\theta) = \prod_{i=1}^{n}f(x_i|\theta) likelihood(θ)=f(Xθ)=i=1nf(xiθ) 取对数似然: l ( θ ) = l o g ( f ( X ∣ θ ) ) = ∑ i = 1 n l o g ( f ( x i ∣ θ ) ) l(\theta) = log(f(X|\theta))=\sum_{i=1}^{n}log(f(x_i|\theta)) l(θ)=log(f(Xθ))=i=1nlog(f(xiθ))

    我们得到的参数 θ \theta θ应该使 l ( θ ) l(\theta) l(θ)最大。

    详细的有关MLE,MAP的内容可以参考: 最大似然估计,最大后验估计,贝叶斯估计联系与区别

    2. 为什么LR的loss一般是残差平方和?

    以LR为例,回顾一下线性回归(LR): h θ ( x ) = ∑ i = 0 d θ i x i h_{\theta}(x)=\sum_{i=0}^{d}\theta_ix_i hθ(x)=i=0dθixi h ( θ ) = θ T x h(\theta)=\theta^Tx h(θ)=θTx loss function: J ( θ ) = 1 2 ∑ i = 0 n ( h θ ( x ( i ) ) − y ( i ) ) 2 J(\theta) = \frac{1}{2} \sum_{i=0}^{n}(h_{\theta}(x^{(i)})-y^{(i)})^2 J(θ)=21i=0n(hθ(x(i))y(i))2

    那么,为什么LR的loss取残差平方和而不是绝对值或者四次方? 因为我们有一个预设,我们假设现实中残差满足均值为0的高斯分布,即 e i = h θ ( x ( i ) ) − y ( i ) ∼ N ( 0 , σ 2 ) e_i = h_{\theta}(x^{(i)})-y^{(i)} \sim N(0,\sigma^2) ei=hθ(x(i))y(i)N(0,σ2)

    怎么理解? 对于LR,我们要采取的是MLE,即最大化似然函数(最大化对数似然) m a x a , b log ⁡ N ( e i , σ 2 ) \underset{a,b}{max} \log N(e_i,\sigma^2) a,bmaxlogN(ei,σ2) = m a x a , b log ⁡ 1 2 π σ 2 e x p ( − 1 2 σ 2 ( e i ) 2 ) = \underset{a,b}{max} \log \frac{1}{\sqrt{{2\pi\sigma^2}}}exp(-\frac{1}{2\sigma^2}(e_i)^2) =a,bmaxlog2πσ2 1exp(2σ21(ei)2) = m a x a , b log ⁡ 1 2 π σ 2 − 1 2 σ 2 e i 2 = \underset{a,b}{max} \log \frac{1}{2\pi\sigma^2} - \frac{1}{2\sigma^2}e_i^2 =a,bmaxlog2πσ212σ21ei2 即等价于 m i n a , b   e i 2 = m i n a , b ( h θ ( x ( i ) ) − y ( i ) ) 2 \underset{a,b}{min} \ e_i^2 = \underset{a,b}{min} (h_{\theta}(x^{(i)})-y^{(i)})^2 a,bmin ei2=a,bmin(hθ(x(i))y(i))2

    所以,我们的损失函数loss取残差平方和。

    同样的道理,如果残差满足拉普拉斯分布, 则loss为绝对值

    Processed: 0.013, SQL: 8