Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Not just the average
Least squares answers “what is the average y for this x?”. Often you need more: “what power can I count on 9 days out of 10?” or “how slow is the worst 5% of downlinks?”. Quantile regression fits a line for any percentile you choose: the median line, the 90th-percentile line, the 10th. Together they show how the whole spread of outcomes changes with x.
Engineering margins are about tails, not means. Power budgets need a lower bound on generation, link budgets need an upper bound on latency, and thermal design needs worst-case temperatures. Quantile regression estimates those bounds directly, with widths that grow or shrink where the data say so.
- 1. The 0.9 quantile regression line leaves about…
- 2. Quantile regression at τ = 0.5 estimates…
- 3. In the demo, when spread grows with x, the 10% and 90% lines…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The pinball loss by hand
The pinball loss for quantile τ charges τ per unit of under-prediction (y above the prediction) and 1 − τ per unit of over-prediction.
Data y = 1, 2, 3, 4, 10 with τ = 0.75. Fit a single constant c:
| c | Residuals y − c | Loss |
|---|---|---|
| 3 | −2, −1, 0, 1, 7 | 0.25·3 + 0.75·8 = 6.75 |
| 4 | −3, −2, −1, 0, 6 | 0.25·6 + 0.75·6 = 6.00 |
| 5 | −4, −3, −2, −1, 5 | 0.25·10 + 0.75·5 = 6.25 |
The minimiser is c = 4, the 75th percentile of the data. With τ = 0.5, the loss is half the absolute error and the minimiser is the median, 3. The outlier 10 does not move it.
Why a quantile? Moving c up by a little changes the loss by (1 − τ)·(number below c) − τ·(number above c). This is zero when a share τ of points lies below c.
The steps in plain English:
- Choose τ (for example 0.05 and 0.95 for a 90% interval).
- Find the β that minimises the total pinball loss of y − Xβ (linear programming, or IRLS).
- Predict xᵀβ: the estimated τ-quantile of y at x.
- Check that about a share τ of held-out points fall below the line.
- 1. Pinball loss (τ = 0.9) of residual r = +2?
- 2. Pinball loss (τ = 0.9) of r = −2?
- 3. τ = 0.5 pinball loss equals…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.The estimator
Objective: β̂(τ) = argmin Σ ρ_τ(yᵢ − xᵢᵀβ), with ρ_τ(r) = r·(τ − 1[r below 0]).
Linear program. Split each residual into positive and negative parts, uᵢ, vᵢ ≥ 0. Then minimise τΣuᵢ + (1 − τ)Σvᵢ subject to Xβ + u − v = y. Simplex or interior-point methods solve it exactly. An optimal solution passes exactly through p data points, like a minimal sample in RANSAC.
IRLS (used in the exercises). Write ρ_τ(r) = wr² with w = (τ or 1 − τ)/|r|, then alternate weighted least squares and weight updates, with a small floor on |r|.
Interpretation. If y = xᵀβ + (xᵀγ)ε, the τ-quantile line is xᵀ(β + γ·F⁻¹(τ)). Slopes differ across τ exactly when the noise scale depends on x. In exercise 1, the slopes are 2 ± 0.5·1.28.
from sklearn.linear_model import QuantileRegressor
lo = QuantileRegressor(quantile=0.05, alpha=0.0, solver="highs").fit(X, y)
hi = QuantileRegressor(quantile=0.95, alpha=0.0, solver="highs").fit(X, y)
import statsmodels.formula.api as smf; smf.quantreg("y ~ x", df).fit(q=0.9).summary()
from sklearn.ensemble import HistGradientBoostingRegressor
HistGradientBoostingRegressor(loss="quantile", quantile=0.9) # non-linear quantilesUse it when you need intervals or bounds, the spread depends on x, or y has outliers (use the median). Watch out for extreme τ with little data: the 99th percentile from 100 points is essentially one point.
- 1. The exact quantile regression problem is a…
- 2. Different quantile slopes indicate…
- 3. scikit-learn's QuantileRegressor parameter alpha is…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory and pitfalls
Consistency and inference. Under regularity conditions, √n(β̂(τ) − β(τ)) converges to N(0, τ(1 − τ)·D₁⁻¹D₀D₁⁻¹), where D₀ = E[xxᵀ] and D₁ = E[f(Q(τ|x)|x)·xxᵀ]. The variance depends on the conditional density at the quantile (the “sparsity”), which is hard to estimate. In practice, standard errors come from the bootstrap or from rank-score tests.
Equivariance. For any increasing function h, Q_τ(h(y)|x) = h(Q_τ(y|x)). So you can fit on log y and exponentiate. The mean has no such property.
Robustness. Quantile regression is robust to outliers in y (bounded influence in y) but, like Huber regression, not to leverage points.
Quantile crossing. Fitting each τ separately can make, for example, the 90% line fall below the 80% line at some x, especially far from the data. Fixes:
- rearrangement (sort the predicted quantiles at each x; Chernozhukov et al., 2010);
- joint fitting with non-crossing constraints.
Coverage guarantees. Quantile regression intervals are only approximately calibrated. Conformalized quantile regression (Romano et al., 2019) adjusts them on a calibration set, giving finite-sample marginal coverage.
Interview questions.
- Why is the pinball-loss minimiser a quantile? The subgradient balances τ·(count above) and (1 − τ)·(count below).
- How do you get a 90% prediction interval without assuming Gaussian noise? Fit τ = 0.05 and τ = 0.95, then optionally conformalize.
- 1. Quantile crossing means…
- 2. Q_τ(log y | x) equals…
- 3. Finite-sample coverage can be guaranteed by…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Power you can count on
History.
- Boscovich (1757) and Laplace fitted lines by least absolute deviations, the τ = 0.5 case, before least squares existed.
- Koenker and Bassett (1978) defined regression quantiles in general and gave the linear-programming formulation.
- Koenker’s 2005 monograph is the standard reference.
- Quantile losses later spread to gradient boosting, quantile random forests (Meinshausen, 2006) and neural forecasting (DeepAR and MQ-RNN).
Exercise 1. 2000 points with y = 1 + 2x + (0.5 + 0.5x)ε. The fitted slopes are 1.377, 1.974 and 2.673 for τ = 0.1, 0.5 and 0.9, against theoretical values 1.359, 2 and 2.641. Exactly 90.0% of the points lie below the 0.9 line, and small perturbations of the IRLS solution never lower the loss.
Exercise 2: rover solar-array power. Setup: power = 0.2·G − losses + noise, where the losses (dust, temperature, shading) are skewed and scale with irradiance G. Train on 600 points and test on 6000. Each method gives a 90% prediction interval; the table shows the coverage in brackets.
| Irradiance band | OLS ± 1.645σ̂ width (W) | Quantile regression width (W) |
|---|---|---|
| Low (100–267) | 23.6 (99.2%) | 12.2 (90.0%) |
| Mid (267–433) | 23.6 (94.8%) | 20.4 (90.3%) |
| High (433–600) | 23.6 (87.0%) | 28.7 (92.7%) |
| Overall | 23.6 (93.6%) | 20.4 (91.0%) |
- The OLS interval is miscalibrated where it matters: it wastes margin at low irradiance (99% coverage) and is too narrow at high irradiance (87%). Its average coverage of 93.6% hides both problems.
- Quantile regression adapts: the width grows from 12 to 29 W, coverage is close to 90% in every band, and the average width is 14% narrower.
Quantile regression in AI, robotics and aerospace
- Power and link budgets: lower bounds on generation, upper bounds on latency and error rates.
- Probabilistic forecasting: quantile losses in demand, weather and trajectory forecasting networks.
- Uncertainty for planners: conformalized quantile intervals as safety margins for motion planning.
- Degradation monitoring: tracking the worst decile of battery or component health over time.
References
- R. Koenker, G. Bassett (1978). “Regression quantiles.” Econometrica 46(1).
- R. Koenker (2005). Quantile Regression. Cambridge University Press.
- N. Meinshausen (2006). “Quantile regression forests.” JMLR 7.
- V. Chernozhukov, I. Fernández-Val, A. Galichon (2010). “Quantile and probability curves without crossing.” Econometrica 78(3).
- Y. Romano, E. Patterson, E. Candès (2019). “Conformalized quantile regression.” NeurIPS.