Quantile Regression
Quantile regression estimates a percentile of an outcome conditional on the information available at the time of the forecast. It allows an upper or lower tail to change with the circumstances, even when the average changes little. A demand forecast can reach its intended coverage across all periods and still leave the same kinds of orders consistently short.
The conditional quantile
A depot stocks seal kits for overhauls. Its 90th percentile of demand is the smallest number of kits that would cover at least 90% of delivery periods. Suppose three kits would cover 75% of periods and four kits would cover 95%. The 90th percentile is four kits. There need never be a stock level that covers exactly nine periods in ten.
Let x denote what is known when the order is placed. Given that information, Fₓ(k) is the probability that customers will request at most k kits before delivery. The quantile at level τ is
The median corresponds to τ = ½. The mean has a different use. A workshop budgeting for a year of seal replacements needs an estimate of total consumption. The storekeeper needs to know how much stock will see him through the next delivery. Both can use the same order history and reasonably arrive at different figures.1
The overhaul calendar
Consider an illustrative record of 100 two-week delivery periods. For each fortnight the workshop kept the booking sheet as it stood on the day the depot placed its order. It also recorded how many kits customers subsequently requested, including orders the depot could only partly fill. Each cell counts fortnights. For instance, four of the twenty fortnights with one job booked required four kits.
| Kits | 0 jobs | 1 job | 2 jobs |
|---|---|---|---|
| 0 | 70 | 0 | 0 |
| 2 | 5 | 15 | 0 |
| 4 | 0 | 4 | 4 |
| 8 | 0 | 1 | 1 |
| Total | 75 | 20 | 5 |
Two kits would have lasted until delivery in 90 of the 100 fortnights. The ten shortages all fell in periods with booked work. Half came from just five fortnights, the ones with two jobs booked.
With one overhaul booked, customers requested 54 kits over twenty fortnights, a mean of 2.7 kits. The median request was two kits. The 90th percentile was four, enough for nineteen of the twenty fortnights.
Across the three booking levels, the historical 90th percentiles are zero, four and eight. The rule four kits per booked overhaul fits all three. The last figure rests on five fortnights. An event with a 10% chance per fortnight goes unseen in five independent fortnights about 59% of the time.
A backtest would fit the rule on earlier dates and score it on later ones, using the booking sheet the buyer actually saw each time. A canceled job belongs on that sheet if it was still booked when he ordered. The depot also needs a record of requests. If it had only four kits and recorded only shipments, a request for eight could leave exactly the same record as a request for four.
Fitting the forecast with pinball loss
Write the forecast as q = b + ax, where x counts booked overhauls. The intercept b allows for requests that arrive even when the calendar is empty. Least squares would fit this line to average consumption. To fit the 90th percentile, score every kit of underforecast at 0.9 and every kit of overforecast at 0.1. For a residual r = demand − forecast, this is pinball loss.
Consider raising the standing forecast from two to three kits. It was already sufficient on 90 dates, so the extra kit adds 90 × 0.1 to the loss. On the ten shortage dates it saves 10 × 0.9. The two changes cancel. The same arithmetic holds all the way to four kits, since no one requested three. Every constant forecast from two to four ties for the lowest mean loss, 0.392. The smallest-quantile convention selects two.
Using the booking sheet brings the mean loss down to 0.172 on the training records. The five unexpected two-kit requests on an empty calendar account for 9 units of loss. The one-job fortnights contribute 6.6 and the two-job fortnights 1.6, giving 17.2 across the hundred dates. Here the three historical percentiles happen to lie on a line. Where they do not, the fitted line can trade a larger error at one booking level for a smaller one at another.
Differentiable programming in Envision
In Envision, Lokad’s supply chain programming language, an autodiff block can fit the two coefficients directly. Each row of Windows records one completed fortnight. Booked was known at the start and Kits is the quantity requested by the end. The forecaster writes the forecast and the loss on a row. Envision uses the derivatives of that loss to adjust the two parameters.2
autodiff Windows with
params baseline auto
params perOverhaul auto
forecast = baseline + perOverhaul * Windows.Booked
residual = Windows.Kits - forecast
return max(0.9 * residual, -0.1 * residual)
Start with a baseline of zero and three kits per booking. On a date with two jobs booked and eight kits requested, the forecast is six. Raising it by one kit saves 0.9 in loss. A small increase in perOverhaul raises this forecast by twice that increase, so the derivative of loss with respect to perOverhaul is −1.8. On a date with no bookings it is zero. An unexpected order on an empty calendar therefore contributes to the baseline gradient alone.
Pinball loss has a corner at an exact forecast. An observation above the forecast contributes a slope of −0.9, one below it contributes +0.1, and at a tie any slope between the two is a valid subgradient. For demand D at a given booking level, the expected loss therefore has left and right slopes P(D < q) − 0.9 and P(D ≤ q) − 0.9. They bracket zero wherever demand is at or below q with probability at least 90%, and strictly below it with probability at most 90%. That is how fitting the loss recovers a quantile, even for parts ordered in batches.
For a straight line the fitting problem is convex and can also be solved by linear programming. With hundreds of seal references, a forecaster might give each its own baseline and share a booking coefficient among kits used in the same class of repair. Envision can differentiate that program too. Records for a frequently ordered kit then help estimate the booking effect for a seldom ordered one. Later orders can tell the forecaster whether he grouped the right kits together.
Demand until the next delivery
Weekly means add up to expected demand over a delivery period, even when demand is correlated across weeks. For a percentile of the total, it matters whether one busy week tends to be followed by another.
Take a spare sold by the box of 50. Each week brings either no request (99% chance) or one request for a box (1%). The weekly 99th percentile is zero kits. With two independent weeks, the chance of no request falls to 0.99², or 98.01%. One box covers every outcome except two requests, giving 99.99% coverage. The two-week 99th percentile is 50 kits. Now suppose the two weeks are always busy together or quiet together. The weekly figures are identical, yet zero kits again suffice for 99% coverage over the two weeks.
With independent weeks, one box lasts through fifteen weeks with 99.037% probability. At sixteen weeks that falls to 98.907%. One extra week doubles the stock required for the same coverage.
A depot can fit a quantile directly to demand from order to receipt. Even when the lead time varies, the dates of past receipts tell the forecaster where each historical demand window ended. Using the actual receipt date as a predictor, however, would give the forecast advance notice of late deliveries. Another approach is to generate future requests and delivery dates jointly. In each scenario, count the kits requested up to that scenario’s delivery date, then take the percentile of the resulting totals. This lets a busy spell both increase requests and delay resupply. Lead Demand examines this dependence in more detail.
What a percentile leaves out
One shortcut to an upper quantile is to take a mean forecast and add a multiple of its residual standard deviation. On the depot’s 75 dates without bookings, mean demand was 0.13 kits and the standard deviation was about 0.50. A normal distribution fitted to those figures gives a 90th percentile of about 0.77 kits. Rounding up to one kit gives the same coverage as zero because all five unexpected requests were for two kits. The historical 90th percentile was already zero.
Even a correctly estimated percentile says little about the size of a shortage. Return to the twenty fortnights with one booking. If the largest request had been 80 kits instead of eight, four kits would still have covered nineteen fortnights. The 90th percentile would still be four. On the remaining date, the depot would have been 76 kits short instead of four.
For the spread of future demand, a forecaster can fit several quantiles. At each booking level the 95th percentile must be at least as high as the 90th. Independently fitted curves can cross, particularly where there are few orders. They can also be fitted together under an ordering constraint.3 The interval between two demand quantiles describes variation in orders. A confidence interval for the 90th percentile answers a separate question about how precisely the sample locates that one quantity.
Suppose each unfilled kit costs nine times as much as a kit left over at delivery. Stocking to the 90th percentile then minimizes the expected cost over that delivery period. This is one rationale for a quantile-based reorder point. Now suppose the first missing kit stops an overhaul and the next three merely join the same backorder. Four missing kits need not mean four times the expense. To price the delay, the buyer needs the distribution of requests and the repair schedule that tells him which job would have to wait.
References
-
Roger Koenker and Kevin F. Hallock, “Quantile Regression,” Journal of Economic Perspectives, 15(4), 2001, pp. 143–156. ↩︎
-
The Envision documentation gives a worked implementation. The lecture Structured Predictive Modeling for Supply Chain shows the forward calculation and the gradients on a sample of historical observations. ↩︎
-
Ichiro Takeuchi, Quoc V. Le, Timothy D. Sears and Alexander J. Smola, “Nonparametric Quantile Estimation,” Journal of Machine Learning Research, 7, 2006, pp. 1231–1264. ↩︎