Simple Algorithm
Machine Learning · Convergence · 26 min

Robust Regression

Outliers, Huber loss, quantile regression and breakdown points.

One bad point can drag a least-squares fit anywhere it likes. Robust regression asks how many bad points an estimator can survive, and what that protection costs when the data are clean. This lesson builds the answers: Huber's loss and its reweighted fitting algorithm, least absolute deviations and quantile regression, high-breakdown fits and RANSAC, and estimators made for heavy tails.

What you’ll learn

  • Define the breakdown point, and show that least squares, least absolute deviations and Huber regression all break down with a single bad leverage point.
  • Derive M-estimators from their ψ\psi-functions, compute the efficiency of Huber's estimator and of the median at the normal, and fit M-estimators by iteratively reweighted least squares.
  • Prove that the pinball loss is minimized by a quantile, and use quantile regression to model data whose spread varies.
  • Compare high-breakdown methods (LMS, LTS, MM, RANSAC), and prove the median-of-means deviation bound for heavy-tailed data.

How fragile is least squares?

Contamination comes in two kinds of outliers. A vertical outlier has an ordinary xi\mathbf x_i and a wild yiy_i. A bad leverage point has an unusual xi\mathbf x_i and a yiy_i that disagrees with the rest, and it is the more dangerous kind, because its high leverage lets it pull the fit toward itself and hide its own residual. To compare estimators, ask how much contamination they can absorb.

For least squares, changing one response by Δ\Delta moves the coefficients by exactly (X⊤X)−1xiΔ(X^\top X)^{-1}\mathbf x_i\Delta, which is unbounded in Δ\Delta, so εn∗=1/n\varepsilon_n^* = 1/n: a single point suffices, and the asymptotic breakdown point is 0. The sample mean behaves the same way, while the sample median survives until about half the points are replaced. No regression-equivariant estimator can do better than roughly one half: beyond that, the "contamination" is the majority and becomes the data.

M-estimators and Huber's loss

Replace the square by a loss ρ\rho that grows more slowly, and scale the residuals by a robust estimate σ^\hat\sigma of the noise level:

w^=arg min⁡w ∑i=1nρ(yi−xi⊤wσ^),or, setting the gradient to zero,∑i=1nψ(yi−xi⊤wσ^)xi=0,\hat{\mathbf w} = \argmin_{\mathbf w}\ \sum_{i=1}^n \rho\Big(\frac{y_i - \mathbf x_i^\top\mathbf w}{\hat\sigma}\Big), \qquad\text{or, setting the gradient to zero,}\qquad \sum_{i=1}^n \psi\Big(\frac{y_i - \mathbf x_i^\top\mathbf w}{\hat\sigma}\Big)\mathbf x_i = \mathbf 0,

with ψ=ρ′\psi = \rho'. Least squares has ψ(r)=r\psi(r) = r, unbounded: a residual's pull grows without limit. Least absolute deviations has ψ(r)=sign⁡r\psi(r) = \sign r. The Huber loss interpolates: quadratic near zero, linear in the tails,

ρc(r)={12r2∣r∣≤cc∣r∣−12c2∣r∣>c,ψc(r)=max⁡(−c,min⁡(c,r)).\rho_c(r) = \begin{cases} \tfrac12 r^2 & \abs r \le c \\ c\abs r - \tfrac12 c^2 & \abs r > c\end{cases}, \qquad \psi_c(r) = \max\big(-c, \min(c, r)\big).

A common scale is the median absolute deviation of the residuals of a preliminary robust fit, divided by 0.67450.6745, which estimates σ\sigma consistently for Gaussian noise.

Predict before you look

At the standard normal, Huber's estimator with c=1.345c = 1.345 is 95% efficient relative to the mean. What is the efficiency of the sample median (the least-absolute-deviations estimate of location)?

Show the answer

64 %

For ψ=sign⁡\psi = \sign, E[ψ2]=1\E[\psi^2] = 1 and E[ψ′]=2φ(0)=2/2π\E[\psi'] = 2\varphi(0) = 2/\sqrt{2\pi} (the jump of the sign function, weighted by the density at 0). So V=2π/4=π/2V = 2\pi/4 = \pi/2 and the efficiency is 2/π≈64%2/\pi \approx 64\%: the median needs about 57% more Gaussian data than the mean for the same precision, the price of its 50% breakdown point in the location problem.

DerivationIteratively reweighted least squares (IRLS)
  1. ∑iψ(ri) xi=∑iωi ri xi=0,ωi=ψ(ri)ri,Huber: ωi=min⁡(1,c∣ri∣)\sum_i \psi(r_i)\,\mathbf x_i = \sum_i \omega_i\, r_i\,\mathbf x_i = \mathbf 0, \qquad \omega_i = \frac{\psi(r_i)}{r_i}, \qquad\text{Huber: } \omega_i = \min\Big(1, \frac{c}{\abs{r_i}}\Big)

    Write the estimating equation as a weighted least-squares equation, with weights that depend on the current residuals ri=(yi−xi⊤w)/σ^r_i = (y_i - \mathbf x_i^\top\mathbf w)/\hat\sigma:

  2. w(t+1)=(X⊤Ω(t)X)−1X⊤Ω(t)y,Ω(t)=diag⁡(ω1(t),…,ωn(t))\mathbf w^{(t+1)} = \big(X^\top\Omega^{(t)}X\big)^{-1}X^\top\Omega^{(t)}\mathbf y, \qquad \Omega^{(t)} = \diag\big(\omega_1^{(t)}, \dots, \omega_n^{(t)}\big)

    Freeze the weights and solve the weighted normal equations; recompute residuals and weights; repeat. Points with large residuals are down-weighted in proportion to their excess:

  3. ρ(r)≤ρ(r0)+ψ(r0)2r0(r2−r02)for all r\rho(r) \le \rho(r_0) + \frac{\psi(r_0)}{2r_0}\big(r^2 - r_0^2\big)\quad\text{for all } r

    Why it descends: if ρ(r)=g(r2)\rho(r) = g(r^2) with gg concave (equivalently, ψ(r)/r\psi(r)/r is nonincreasing in ∣r∣\abs r, as for Huber), the tangent line of gg gives a quadratic upper bound that touches ρ\rho at the current residual. Each IRLS step minimizes the sum of these bounds, so the objective never increases: IRLS is a majorize–minimize algorithm. For a convex ρ\rho such as Huber's, it converges to the global minimizer under mild conditions.

Least absolute deviations and quantile regression

Least absolute deviations (LAD), min⁡w∑i∣yi−xi⊤w∣\min_{\mathbf w}\sum_i\abs{y_i - \mathbf x_i^\top\mathbf w}, estimates a conditional median instead of a mean; Boscovich used a version of it in the 1750s, half a century before least squares. Tilting the absolute value gives every other quantile. The pinball (check) loss at level τ∈(0,1)\tau \in (0, 1) is

ρτ(u)=u (τ−1{u<0})={τ uu≥0(τ−1) uu<0,\rho_\tau(u) = u\,\big(\tau - \mathbf 1\{u < 0\}\big) = \begin{cases} \tau\, u & u \ge 0\\ (\tau - 1)\, u & u < 0\end{cases},

and ρ1/2(u)=∣u∣/2\rho_{1/2}(u) = \abs u/2 recovers LAD.

DerivationThe pinball loss is minimized by a quantile
  1. L(q)=E ρτ(Y−q)=τ E[(Y−q)1{Y>q}]+(1−τ) E[(q−Y)1{Y<q}]L(q) = \E\,\rho_\tau(Y - q) = \tau\,\E\big[(Y - q)\mathbf 1\{Y > q\}\big] + (1 - \tau)\,\E\big[(q - Y)\mathbf 1\{Y < q\}\big]

    Let YY have a continuous distribution function FF and consider the expected loss of predicting qq. Split it at qq:

  2. L′(q)=−τ Pr⁡(Y>q)+(1−τ)Pr⁡(Y<q)=F(q)−τL'(q) = -\tau\,\Pr(Y > q) + (1 - \tau)\Pr(Y < q) = F(q) - \tau

    Differentiate under the expectation. Raising qq lowers the loss on the points above it and raises it on the points below:

  3. arg min⁡q E ρτ(Y−q)=F−1(τ)\argmin_q\ \E\,\rho_\tau(Y - q) = F^{-1}(\tau)

    LL is convex and its derivative vanishes where F(q)=τF(q) = \tau: the minimizer is the τ\tau-quantile. Conditioning on x\mathbf x turns this into the conditional quantile, which is what quantile regression estimates.

Quantile regression (Koenker & Bassett, 1978) fits w^(τ)=arg min⁡w∑iρτ(yi−xi⊤w)\hat{\mathbf w}(\tau) = \argmin_{\mathbf w}\sum_i\rho_\tau(y_i - \mathbf x_i^\top\mathbf w) for each level of interest. It is a linear program, and some solution passes exactly through dd of the data points (a vertex of the feasible region). Its strengths:

  • Heteroscedasticity becomes signal. If the spread of yy grows with xx, the fitted lines for τ=0.1,0.5,0.9\tau = 0.1, 0.5, 0.9 fan out, describing the whole conditional distribution rather than its mean alone.
  • Robustness in yy. Like LAD, it ignores how far a point lies beyond the line, only on which side.
  • Equivariance. Quantiles commute with increasing transformations, Qτ(h(Y))=h(Qτ(Y))Q_\tau(h(Y)) = h(Q_\tau(Y)); means do not.

Separately fitted quantile lines can cross in finite samples, which is a known nuisance. With i.i.d. errors of density ff, n (w^(τ)−w(τ))\sqrt n\,(\hat{\mathbf w}(\tau) - \mathbf w(\tau)) is asymptotically normal with covariance τ(1−τ)f(F−1(τ))2(lim⁡1nX⊤X)−1\frac{\tau(1-\tau)}{f(F^{-1}(\tau))^2}\big(\lim\tfrac1nX^\top X\big)^{-1}, so extreme quantiles, where data are sparse, are estimated less precisely.

Think first A retailer forecasts demand with the pinball loss at τ=0.9\tau = 0.9. How many times more does an under-forecast of one unit cost than an over-forecast of one unit, and why would anyone want that?

τ/(1−τ)=0.9/0.1=9\tau/(1-\tau) = 0.9/0.1 = 9 times. Running out of stock is costly, so the forecast should sit at the level that demand exceeds only 10% of the time. The asymmetric loss turns "forecast the 90th percentile" into a minimization problem, and the same logic sets any quantile from the ratio of the two costs.

High breakdown: LMS, LTS, MM and RANSAC

To survive close to half the data being arbitrary, including bad leverage points, an estimator must be able to ignore points entirely. Rousseeuw (1984) proposed two such estimators:

  • Least median of squares (LMS) minimizes median⁡i ri2\operatorname{median}_i\, r_i^2. Geometrically, in simple regression it finds the narrowest strip that covers half of the points. Its breakdown point is about 50%, the maximum possible, but it is statistically inefficient.
  • Least trimmed squares (LTS) minimizes the sum of the hh smallest squared residuals, with hh about n/2n/2: least squares on the best-fitting half, chosen by the estimator itself. It keeps the 50% breakdown point and behaves better statistically, which is why LTS is usually preferred.

Both objectives are non-convex and combinatorial. Practical algorithms start from many random elemental fits through dd points and improve each by concentration steps: refit least squares on the hh points with the smallest current residuals, which can never increase the LTS objective. MM-estimators (Yohai, 1987) then recover efficiency: start from a high-breakdown fit and its robust scale, and finish with an M-estimate using a redescending ψ\psi, achieving breakdown point 0.5 together with high efficiency (85–95% are common targets) at the normal.

RANSAC (Fischler & Bolles, 1981), the workhorse of computer vision, takes the elemental-subset idea all the way. Repeat: sample ss points (the minimum needed to determine the model, s=ds = d for a hyperplane), fit them exactly, and count the inliers, the points within a threshold of the fit. Keep the model with the largest consensus set, then refit on its inliers. If a fraction ϵ\epsilon of the data are outliers, one sample is all inliers with probability (1−ϵ)s(1 - \epsilon)^s, so the number of trials NN needed to succeed with probability pp satisfies

1−(1−(1−ϵ)s)N ≥ p⟺N ≥ log⁡(1−p)log⁡(1−(1−ϵ)s).1 - \big(1 - (1 - \epsilon)^s\big)^N \ \ge\ p \quad\Longleftrightarrow\quad N \ \ge\ \frac{\log(1 - p)}{\log\big(1 - (1 - \epsilon)^s\big)}.
Predict before you look

RANSAC fits a line (s=2s = 2 points per sample) to data in which half the points are outliers (ϵ=0.5\epsilon = 0.5). How many random samples guarantee at least a 99% chance that one of them is outlier-free?

Show the answer

17 samples

One sample is clean with probability 0.52=0.250.5^2 = 0.25, so N≥log⁡(0.01)/log⁡(0.75)=4.605/0.288≈16.01N \ge \log(0.01)/\log(0.75) = 4.605/0.288 \approx 16.01, hence 17 samples. A plane (s=3s = 3) needs 35 and a 4-point model 72: the count grows exponentially in ss, which is why RANSAC suits low-dimensional geometric models.

EstimatorBreakdown point in regressionEfficiency at the normalConvex?
Least squares1/n1/n100%yes
LAD / quantile regression1/n1/n (leverage points)2/π≈64%2/\pi \approx 64\% (LAD)yes (a linear program)
Huber, c=1.345c = 1.3451/n1/n (leverage points)95%yes
LMSabout 50%lowno
LTS, h≈n/2h \approx n/2about 50%low unless followed by a reweighting stepno
MM (Yohai)50%tunable, e.g. 85–95%no
Robustness to outliers in yy, robustness to leverage points, efficiency on clean data and computational ease pull in different directions; no single method wins all four.

Heavy tails: median-of-means

Sometimes nothing is "wrong" with any point: the noise simply has heavy tails, with finite variance but rare enormous values. Then the question is not breakdown but how fast the error concentrates. For the sample mean, a variance bound alone gives only Chebyshev's guarantee, ∣Xˉ−μ∣≤σ/δn\abs{\bar X - \mu} \le \sigma/\sqrt{\delta n} with probability at least 1−δ1-\delta, which deteriorates quickly for small δ\delta. Splitting the data and taking a median repairs the dependence on δ\delta.

DerivationProof
  1. Pr⁡(∣Xˉj−μ∣>2σ/m)≤σ2/m4σ2/m=14\Pr\big(\abs{\bar X_j - \mu} > 2\sigma/\sqrt m\big) \le \frac{\sigma^2/m}{4\sigma^2/m} = \frac14

    Each block mean Xˉj\bar X_j has variance σ2/m\sigma^2/m, so by Chebyshev's inequality it misses μ\mu by more than 2σ/m2\sigma/\sqrt m with probability at most 1/41/4:

  2. Pr⁡(#{bad blocks}≥k2)≤exp⁡(−2k(12−14)2)=e−k/8\Pr\Big(\#\{\text{bad blocks}\} \ge \tfrac k2\Big) \le \exp\Big(-2k\big(\tfrac12 - \tfrac14\big)^2\Big) = e^{-k/8}

    The median misses by more than 2σ/m2\sigma/\sqrt m only if at least half of the block means do. The number of bad blocks is a sum of kk independent indicators with mean at most 1/41/4, so Hoeffding's inequality bounds the chance that it reaches k/2k/2:

  3. 2σm=2σkn=2σ8ln⁡(1/δ)n=σ32ln⁡(1/δ)n\frac{2\sigma}{\sqrt m} = 2\sigma\sqrt{\frac kn} = 2\sigma\sqrt{\frac{8\ln(1/\delta)}{n}} = \sigma\sqrt{\frac{32\ln(1/\delta)}{n}}

    Choose k=8ln⁡(1/δ)k = 8\ln(1/\delta), so that e−k/8=δe^{-k/8} = \delta, and substitute m=n/km = n/k:

At δ=10−6\delta = 10^{-6}, Chebyshev guarantees the sample mean only within 1000 σ/n1000\,\sigma/\sqrt n, while median-of-means guarantees 21 σ/n21\,\sigma/\sqrt n under the same assumption. (For moderate δ\delta such as 0.010.01, the loose constant 32 makes the simple bound no better than Chebyshev's; the gain is in the log⁡(1/δ)\sqrt{\log(1/\delta)} dependence.) That dependence is optimal: a lower bound due to Devroye, Lerasle, Lugosi & Oliveira shows that no estimator can guarantee better than order σlog⁡(1/δ)/n\sigma\sqrt{\log(1/\delta)/n} for all distributions with variance σ2\sigma^2 (see the survey of Lugosi & Mendelson, 2019). For least-squares regression, a generalized median-of-means estimator reaches a constant-factor approximation of the best achievable squared loss from about dlog⁡(1/δ)d\log(1/\delta) samples (up to logarithmic factors), assuming only bounded low-order moments and without assuming bounded or sub-Gaussian features or noise (Hsu & Sabato, 2016).

Key takeaways

  • The breakdown point is the smallest fraction of arbitrary points that can carry an estimate anywhere. Least squares breaks down with one point; the median and high-breakdown regression estimators survive close to half.
  • M-estimators replace the square by ρ\rho with bounded ψ=ρ′\psi = \rho'. Huber's loss with c=1.345c = 1.345 keeps 95% efficiency at the normal (the median keeps 2/π≈64%2/\pi \approx 64\%) and is fitted by iteratively reweighted least squares, a majorize–minimize scheme. Bounded ψ\psi still does not stop bad leverage points.
  • The pinball loss ρτ\rho_\tau is minimized by the τ\tau-quantile; quantile regression is a linear program that describes how the whole conditional distribution changes with x\mathbf x.
  • LMS and LTS reach 50% breakdown by ignoring points, MM-estimators add efficiency, and RANSAC needs about log⁡(1−p)/log⁡(1−(1−ϵ)s)\log(1-p)/\log(1 - (1-\epsilon)^s) random samples.
  • For heavy tails, median-of-means achieves σ32ln⁡(1/δ)/n\sigma\sqrt{32\ln(1/\delta)/n} under a variance bound alone, the optimal log⁡(1/δ)\sqrt{\log(1/\delta)} dependence.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

What are the (asymptotic) breakdown points of the sample mean and the sample median as estimates of location?

  1. 0 and 1/2
  2. 1/2 and 1/2
  3. 0 and 1
  4. 1/n and 1/n
Show the answer

A. 0 and 1/2

Moving a single point far enough moves the mean as far as you like: breakdown 1/n→01/n \to 0. The median stays within the range of the uncontaminated points until about half of them are replaced: breakdown →1/2\to 1/2, the best possible for an equivariant estimator.

Question 2

Huber regression is applied to data with one point far out in x\mathbf x whose response is badly wrong. What happens?

  1. Huber's loss caps that point's influence, so the fit is safe
  2. The point is automatically removed because its residual exceeds cc
  3. The fit can still be dragged arbitrarily far: the point's leverage tilts the line toward it, and its large xi\mathbf x_i multiplies even a clipped ψ\psi
  4. Huber regression fails to converge
Show the answer

C. The fit can still be dragged arbitrarily far: the point's leverage tilts the line toward it, and its large xi\mathbf x_i multiplies even a clipped ψ\psi

Huber's ψ\psi bounds the effect of large residuals, but the estimating equation weights each ψ(ri)\psi(r_i) by xi\mathbf x_i, and a high-leverage point keeps its own residual small by pulling the fit. Regression M-estimators with monotone ψ\psi have breakdown point 1/n1/n; LTS, MM-estimators or RANSAC are needed.

Question 3

A quantile regression with τ=0.9\tau = 0.9 is fitted to house prices. What does the fitted value x⊤w^(0.9)\mathbf x^\top\hat{\mathbf w}(0.9) estimate?

  1. The average price of houses with features x\mathbf x, plus 90%
  2. The price that 90% of houses with features x\mathbf x fall below
  3. The price predicted with 90% confidence
  4. The price after removing the most expensive 10% of houses from the data
Show the answer

B. The price that 90% of houses with features x\mathbf x fall below

The pinball loss at level τ\tau is minimized by the τ\tau-quantile, so the fit estimates the conditional 90th percentile of price given x\mathbf x. Comparing fits at several τ\tau shows how the whole conditional distribution shifts and spreads with x\mathbf x.

Question 4

For heavy-tailed data with finite variance, what does median-of-means improve over the sample mean's Chebyshev guarantee?

  1. It removes the dependence on σ\sigma
  2. It converges at rate 1/n1/n instead of 1/n1/\sqrt n
  3. It needs no assumptions at all on the distribution
  4. The dependence on the failure probability: log⁡(1/δ)\sqrt{\log(1/\delta)} instead of 1/δ1/\sqrt\delta
Show the answer

D. The dependence on the failure probability: log⁡(1/δ)\sqrt{\log(1/\delta)} instead of 1/δ1/\sqrt\delta

Both scale as σ/n\sigma/\sqrt n. Median-of-means achieves σ32ln⁡(1/δ)/n\sigma\sqrt{32\ln(1/\delta)/n}, the sub-Gaussian shape, versus Chebyshev's σ/δn\sigma/\sqrt{\delta n}, a dramatic gain for small δ\delta, and the log⁡(1/δ)\sqrt{\log(1/\delta)} order cannot be improved in general.

Further reading

  • P. J. Huber, "Robust estimation of a location parameter," Annals of Mathematical Statistics 35(1), 73–101 (1964).
  • R. Koenker & G. Bassett, "Regression quantiles," Econometrica 46(1), 33–50 (1978).
  • P. J. Rousseeuw, "Least median of squares regression," Journal of the American Statistical Association 79(388), 871–880 (1984).
  • M. A. Fischler & R. C. Bolles, "Random sample consensus: a paradigm for model fitting with applications to image analysis and automated cartography," Communications of the ACM 24(6), 381–395 (1981).
  • G. Lugosi & S. Mendelson, "Mean estimation and regression under heavy-tailed distributions: a survey," Foundations of Computational Mathematics 19(5), 1145–1190 (2019).