Back to Classic ML Mind Map
中文·English
📊 Classic MLID: loss-huber-focal

Huber Loss & Focal Loss

Huber 与 Focal Loss
🎯Core Definition
Huber loss (smooth L1): for residual r=yf(x)r = y - f(x), quadratic for small errors and linear for large ones, piecewise defined as Lδ(r)={12r2,rδδ(r12δ),r>δ\mathcal{L}_\delta(r) = \begin{cases} \frac{1}{2}r^2, & |r| \le \delta \\ \delta(|r| - \frac{1}{2}\delta), & |r| > \delta \end{cases} — continuous and differentiable at r=δ|r| = \delta, with constant gradient (no explosion) on large outliers while keeping L2's fast convergence on typical samples; in object detection it appears as Smooth L1. Focal Loss: FL(pt)=αt(1pt)γlogptFL(p_t) = -\alpha_t (1-p_t)^\gamma \log p_t where ptp_t is the predicted probability of the true class, γ[0,5]\gamma \in [0,5] is the modulating factor (typically 2) and αt\alpha_t the class weight — as pt1p_t \to 1 (easy samples) the factor (1pt)γ0(1-p_t)^\gamma \to 0 and the loss is sharply down-weighted; as ptp_t is small (hard samples) the weight is near 1 and the loss is kept. Proposed by RetinaNet to solve “easy negatives drowning the gradient”.
💡Use Cases
Huber/Smooth L1 — regression with outliers needing stable gradients (bounding-box regression in detection, coordinate regression); Focal — dense object detection and heavily imbalanced classification (background vs object boxes up to 1:1000).
Key Problems Solved
for outliers, MSE's gradient grows linearly with the error and a single anomaly can dominate, while MAE is robust but non-differentiable at zero and converges slowly; Huber compromises — L2 for small errors (fast convergence), L1 gradient clipped at ±δ\pm\delta for large ones (robust and differentiable everywhere). Focal solves “easy negatives contribute almost all CE loss and dilute the gradient”: the modulating factor exponentially down-weights easy samples so training focuses on the few hard positives — complementary to, not a replacement for, resampling and class weights.
🎯5 High-Frequency Exam Points
1
Write the piecewise Huber loss Lδ(r)\mathcal{L}_\delta(r); what does δ control? Why is it continuous and differentiable at r=δ|r|=\delta?
2
Huber vs MSE vs MAE: gradient on outliers, differentiability at zero, and convergence speed?
3
Write FL(pt)=αt(1pt)γlogptFL(p_t) = -\alpha_t(1-p_t)^\gamma \log p_t; what do γ and α each do?
4
Why does Focal loss help with class imbalance? Is it a replacement or complement to resampling and class weights?
5
How are Smooth L1 and Huber related? Why does detection use Smooth L1 for box regression instead of MSE?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Huber Loss & Focal Loss"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardResampling Methods: SMOTE/ADASYN/TomekNext CardTarget Encoding

🔗 More Classic ML Knowledge Cards

AdaBoost DerivationBagging & Random ForestBaum-Welch (HMM EM)GBDT Negative Gradient