MATH ML Learning Lab
B18
B18 · 20–30 min

从似然到损失函数From Likelihood to Loss Functions

为什么让观察到的数据更可信,可以变成最小化一个损失?Why can making observed data more likely become minimizing a loss?

前置知识:Prerequisites: B02、B08、B10、B13、B16、B17。B02, B08, B10, B13, B16 and B17.

复习前置:Review prerequisites: B02 · 指数与对数:增长和尺度Exponentials & Logarithms: Growth and Scale · B08 · 一元链式法则The Single-Variable Chain Rule · B10 · 损失函数与梯度下降Loss Functions & Gradient Descent · B13 · 条件概率Conditional Probability · B16 · 期望、方差与样本统计Expectation, Variance & Sample Statistics · B17 · 积分直觉与连续分布Integral Intuition & Continuous Distributions

学完后你能:After this lesson you can: 固定数据比较似然与负对数损失,并说明 MSE 等价条件。Compare likelihood and negative log loss for fixed data and state the conditions for MSE equivalence.

动手观察Explore

固定观察顺序 HHH T,拖动硬币正面概率,比较似然与负对数损失的极值。Fix the observed sequence HHH T and move the heads probability; compare the extrema of likelihood and negative log loss.

从观察到解释From observation to explanation

固定数据,改变参数Fix data and vary the parameter

观察顺序 HHH T 固定时,独立同概率硬币的似然是 p³(1−p),其中 p 是每次正面的概率。它描述不同 p 对这组固定数据的相对支持,不是 p 的概率分布。For the fixed observed sequence HHH T from independent identical coin tosses, the likelihood is p³(1−p), where p is the probability of heads. It compares how different p values support the fixed data; it is not a probability distribution over p.

对数把乘法变加法Logarithms turn products into sums

在似然为正的参数处,负对数损失是 −3 ln p−ln(1−p)。对数严格递增,取负号后最大似然点与最小损失点相同,都是 p=3/4。零似然对应无限损失。Where likelihood is positive, negative log loss is −3 ln p−ln(1−p). The logarithm is strictly increasing, so after negation the maximum-likelihood and minimum-loss points coincide at p=3/4. Zero likelihood gives infinite loss.

与平方误差的联系Connecting to squared error

若预测误差在给定输入下条件独立、均服从零均值且共同固定方差 σ²>0 的高斯分布,负对数似然等于一个与预测参数无关的常数加平方误差和乘正系数,因此与最小化 MSE 有相同最优预测参数。If prediction errors are conditionally independent given inputs and all follow a zero-mean Gaussian with the same fixed variance σ²>0, negative log likelihood is a parameter-independent constant plus a positive multiple of squared error. Thus it has the same optimal prediction parameters as MSE.

公式与符号Formula and symbols

θ 是待估参数,zᵢ 是固定的第 i 个观测;pθ 是该参数下的概率或密度,∏ 表示连乘,L 是似然,J 是负对数损失。独立观测的对数将乘积变为求和。θ is the parameter, zᵢ the fixed i-th observation; pθ is the probability or density under that parameter, ∏ denotes a product, L is likelihood and J negative log loss. For independent observations, logarithms turn the product into a sum.

留意这个区别Watch for this

若方差也被优化或随输入变化,不能随意省略方差相关项;连续观测使用密度,而不是把单点概率当作正数。If variance is optimized or varies with input, its terms cannot be dropped. Continuous observations use density, not a positive single-point probability.

继续探索Explore further

课后练习

检验你的理解