Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Predicting a bound, not an average
Sometimes the useful prediction is not “how long will the battery last on average” but “how long will it last in the worst 10% of cases”. The quantile loss trains a model to predict such a bound. It charges more for errors on one side: for the 90th percentile, predicting too low costs 0.9 per unit and too high only 0.1, so the model settles where 90% of outcomes fall below its prediction. Two quantiles, say the 5th and the 95th, give an interval that adapts to how noisy and how lopsided the data are.
Engineering decisions run on bounds: worst-case descent time, the 95th percentile of wind gusts, the 5th percentile of battery capacity, demand forecasts for spares. Real noise is often skewed (delays can be long but not negative) and its spread changes with conditions. Quantile regression gives intervals that stay honest under both, without assuming Gaussian noise.
- 1. The 90% quantile loss charges under-predictions…
- 2. The τ = 0.5 quantile loss targets…
- 3. Quantile intervals require Gaussian noise?
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Pinball loss: ρ_τ(r) = τ·r if r ≥ 0, and (τ − 1)·r if r < 0, with r = y − q.
- Examples with τ = 0.9: y = 5, q = 3 costs 0.9 × 2 = 1.8; y = 1, q = 3 costs 0.1 × 2 = 0.2.
- τ = 0.5: ρ = ½|r|, half the absolute error, so its minimiser is the median.
- Best constant: the τ-quantile of the data. Its subgradient is −τ·#(above) + (1 − τ)·#(below), which is zero when a share τ of the points lies below.
- Interval: fit τ = α/2 and 1 − α/2. For a 90% interval, τ = 0.05 and 0.95.
- Interval (Winkler) score: (hi − lo) + (2/α)·(lo − y) if y < lo, + (2/α)·(y − hi) if y > hi. It rewards narrow intervals and penalises misses. A proper scoring rule for intervals.
- 1. Pinball loss (τ = 0.25) for y = 2, q = 0?
- 2. For a 80% central interval you fit τ =…
- 3. The interval score penalises a miss by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Quantiles in code
Exercise 1.
- The pinball loss at τ = 0.5 is half the MAE.
- On exponential samples, the best constant found by search put exactly a share τ of the data below it, matching the true quantiles −log(1 − τ): 0.105, 0.693 and 2.303.
- The interval score and a quantile-crossing check are implemented.
Practice.
- Multi-quantile heads: one network outputs several quantiles at once (τ = 0.1, 0.5, 0.9), trained with the sum of pinball losses.
- Crossing: separately fitted quantiles can cross (q₀.₁ > q₀.₉ at some x). Fix it by sorting the outputs, or by predicting positive increments between quantiles.
- Optimisation: the loss is piecewise linear, so plain subgradient descent converges slowly, especially for extreme τ. Adam or a smoothed (Huberised) pinball loss help; linear quantile regression can be solved exactly by linear programming.
- Conformal calibration: adjusting the bounds on a held-out set guarantees finite-sample coverage.
def pinball(y, q, tau): r = y - q; return torch.maximum(tau * r, (tau - 1) * r).mean()- 1. Quantile crossing means…
- 2. Linear quantile regression can be solved exactly by…
- 3. Plain subgradient descent on extreme quantiles is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why the minimiser is a quantile. E[ρ_τ(Y − q)] has derivative −τ·P(Y > q) + (1 − τ)·P(Y < q) = P(Y < q) − τ, which is zero when F(q) = τ. The expected pinball loss is convex in q and minimised at the τ-quantile. Conditionally, a flexible model trained with ρ_τ predicts the conditional quantile q_τ(x).
Distribution-free. Nothing assumes a noise family: skewness and changing spread are captured as long as the model can represent the quantile function. In exercise 2 the true quantiles were linear in x, so linear quantile regression was correctly specified even though the noise was skewed and heteroscedastic.
Consistency and properness. The pinball loss is a consistent scoring function for quantiles (Gneiting, 2011): no other report has lower expected loss than the true quantile. The interval score is proper for central intervals.
Limitations.
- Intervals from quantile regression have only asymptotic coverage guarantees and can under-cover in small samples or under model misspecification. Conformalised quantile regression (Romano, Patterson and Candès, 2019) fixes finite-sample coverage.
- Extreme quantiles need lots of data.
- 1. The derivative of the expected pinball loss is…
- 2. Quantile regression was introduced by…
- 3. Finite-sample coverage can be guaranteed by…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Honest intervals for skewed noise
History.
- R. Koenker and G. Bassett (1978) introduced regression quantiles.
- Gradient boosting and neural forecasters (for example the multi-horizon quantile networks of R. Wen et al., 2017) brought quantile losses to large-scale forecasting.
- Y. Romano, E. Patterson and E. Candès (2019) introduced conformalised quantile regression.
- T. Gneiting (2011) formalised consistent scoring functions.
Exercise 2. y = 2x + (0.2 + x)(E − 1), with E ~ Exponential(1) and x uniform on [0, 1]: noise that is skewed (long upper tail) and grows with x. A 90% interval is fitted in two ways, on 2000 training points, and evaluated on 20 000 test points in the low-x and high-x halves:
- linear quantile regression at τ = 0.05 and 0.95, trained with Adam on the pinball loss;
- least squares with a symmetric mean ± 1.645σ interval of one width.
The fitted 5% line was (−0.185, 1.048), against the true (−0.190, 1.051); the 95% line was (0.38, 4.32), against the true (0.40, 4.00).
| interval | region | below the lower bound (target 0.05) | above the upper bound (target 0.05) |
|---|---|---|---|
| quantile regression | x < 0.5 | 0.063 | 0.046 |
| quantile regression | x ≥ 0.5 | 0.053 | 0.039 |
| mean ± 1.645σ | x < 0.5 | 0.000 | 0.025 |
| mean ± 1.645σ | x ≥ 0.5 | 0.000 | 0.087 |
- Quantile regression was close to 5% in every cell (3.9–6.3%), in both regions and on both sides. Its 95% line’s slope was somewhat too steep, as expected for an extreme quantile from 2000 points.
- The Gaussian interval was wrong in three of four cells. It never missed below, because skewed noise is bounded below, so its lower bound was wasted width. Above, it missed 2.5% of the time where noise was small and 8.7% where it was large.
- An optimisation lesson: plain subgradient descent with a decaying step had not converged for τ = 0.95 in a first attempt (slope 1.83 against 4.0). Adam fixed it. Always compare fitted quantiles with empirical coverage.
Quantile losses in AI, robotics and aerospace
- Planning under uncertainty: quantile predictions of travel time, energy use or wind give risk-aware margins for mission planning.
- Maintenance and reliability: lower quantiles of remaining useful life set conservative replacement schedules.
- Forecasting: demand, delay and arrival-time forecasts are reported as quantiles (P10, P50, P90) rather than single numbers.
References
- R. Koenker, G. Bassett (1978). “Regression quantiles.” Econometrica 46(1).
- R. Koenker (2005). Quantile Regression. Cambridge University Press.
- T. Gneiting (2011). “Making and evaluating point forecasts.” Journal of the American Statistical Association 106.
- Y. Romano, E. Patterson, E. Candès (2019). “Conformalized quantile regression.” Advances in NeurIPS 32.
- R. Wen, K. Torkkola, B. Narayanaswamy, D. Madeka (2017). “A multi-horizon quantile recurrent forecaster.” NeurIPS Time Series Workshop.