The interview problem
An operations team needs a median demand forecast and a higher forecast for costly shortages. Explain quantile regression, derive why pinball loss targets a quantile, compute an example by hand, and handle predictions whose 90th percentile falls below their median. Describe how you would evaluate the model without claiming an automatic coverage guarantee.
Original ML fundamentals practice, not a reported company question. Examples are hypothetical. Primary documentation retrieved September 27, 2026; publication date not stated; interview date not applicable.
1. Define the conditional target
For features X=x, a lower conditional quantile is qτ(x)=inf{q:F(q|x)≥τ}, with 0<τ<1. A median corresponds to τ=0.5. A 90th percentile is not the mean plus a universal safety margin: its distance from the median depends on the conditional distribution's shape and scale.
Specify the outcome and horizon before choosing a model. Tomorrow's unconstrained demand differs from observed sales when inventory limits sales. Training directly on censored sales may produce excellent sales quantiles and poor demand decisions. Features must be available when the prediction is issued, including the correct historical version of inventory and promotion plans.
The objective describes variability in future outcomes conditional on features. It does not, by itself, quantify uncertainty about estimated model parameters. A prediction interval for a new observation and a confidence interval for a mean are different objects.
2. Derive the asymmetric loss
Write the residual u=y−q. Pinball loss is ρτ(u)=τu for u≥0 and (τ−1)u for u<0. Equivalently it is τ max(y−q,0)+(1−τ)max(q−y,0). Both branches are nonnegative. At τ=0.9, underpredicting by ten units costs nine loss units, while overpredicting by ten costs one.
For a continuous conditional distribution with finite first absolute moment, differentiate expected loss with respect to q: its derivative is F(q|x)−τ. Where F(q|x)<τ, moving q upward reduces loss; where F(q|x)>τ, moving upward increases loss. A region with F(q|x)=τ can form a flat interval of minimizers. Setting the derivative to zero gives F(q|x)=τ when such a solution exists. At atoms, use the subgradient condition F(q−|x)≤τ≤F(q|x), which also handles nonunique minimizing intervals.
For a single observation away from a tie, the derivative with respect to the prediction is −τ when y>q and 1−τ when y<q. Reversing the residual without reversing the formula targets the wrong asymmetry. At τ=0.5 the loss is half the absolute error, so it has the same minimizers as absolute error but a different numerical scale.
A model minimizes the average of these losses over training observations, often plus regularization. A restricted linear model may not represent the true conditional quantile. Optimizing the sample objective does not guarantee exact conditional calibration on future data.
3. Compute a small example
For equally weighted observations [2,4,5,9,20], choose τ=0.8 and a constant prediction. At q=9, the five losses are [1.4,1.0,0.8,0,8.8], totaling 12 and averaging 2.4. At q=5, they are [0.6,0.2,0,3.2,12], totaling 16 and averaging 3.2. Predicting the median is worse under this shortage-sensitive objective.
At q=20, loss also totals 12: the values are [3.6,3.2,3.0,2.2,0]. Every q in [9,20] minimizes this empirical objective. Between 9 and 20, four observations lie below q and one above; the mean slope is 4/5−0.8=0. The lower empirical quantile convention chooses 9, while other interpolation conventions may return a different point in the minimizing interval. State your convention.
At τ=0.9, the same interval has slope 0.8−0.9=−0.1, so moving toward 20 still improves the objective. The unique minimizing observed value is then 20. At τ=0.5, 5 is the median and its mean pinball loss is 2.3, half its mean absolute error of 4.6. Compare candidate models at the same τ; losses at different τ optimize different goals.
This five-point sample is a calculation exercise, not reliable evidence for an operational tail estimate. With n independent observations, a true 99th-percentile threshold has only about 0.01n expected exceedances under a continuous distribution with the stated quantile. With n=100, that is one; tail assessment remains highly uncertain.
4. Connect the quantile to a decision
Suppose each unit of unmet demand costs cu=9 and each unit of excess provision costs co=1. Under a single-period, unconstrained decision with constant linear costs, expected cost is E[cu max(Y−q,0)+co max(q−Y,0)]. Dividing by cu+co shows this is pinball loss with τ=cu/(cu+co)=0.9, up to a positive scale factor.
The optimal quantile changes if costs change. A 90th percentile is justified here by the ratio, not because it sounds conservative. Capacity constraints, minimum order quantities, lead times, correlated decisions and nonlinear penalties can require a separate optimization layer. Do not claim a univariate quantile alone solves a multi-item inventory problem.
Quantiles also do not generally add. If two independent items each demand one unit with probability 0.1 and zero otherwise, each lower 90th percentile is zero. Their total is zero with probability 0.81, one with probability 0.18 and two with probability 0.01, so its lower 90th percentile is one. Adding the individual quantiles would give the wrong aggregate target.
5. Build an auditable prediction pipeline
versioned outcomes + features available at issue time
↓
chronological training split
↓
model predicts q0.1, q0.5 and q0.9
↓
ordering check / constrained output layer
↓
frozen evaluation → serving → delayed outcomes
↓
loss, coverage, width and slice monitoringBegin with a historical quantile baseline within meaningful cohorts, then fit a conditional model if features improve held-out loss. Train quantile-specific models or a shared model with multiple outputs. Select model complexity on a validation period and reserve a later test period. Evaluate each prediction against its own issue time and horizon; overlapping horizons can create correlated errors.
Persist the quantile levels, target definition, model version and any postprocessing with each prediction. A downstream consumer must know whether a number represents the median, an upper quantile or an optimized decision. If business costs change, the desired quantile may change even though the outcome distribution does not.
6. Handle crossing without promising calibration
Separate models can return q0.1=4, q0.5=12 and q0.9=10 for the same input. A distribution cannot have these quantiles in that order. Sorting gives [4,10,12], which restores ordering but changes the predicted median and upper quantile. It does not prove either has the desired held-out coverage.
One joint parameterization sets q0.1=a, q0.5=a+softplus(b) and q0.9=a+softplus(b)+softplus(c). In exact arithmetic this guarantees strictly increasing outputs for finite b and c; exact equality is approached as an increment tends to zero. It can be restrictive for distributions with large point masses where quantiles coincide. Other constrained formulations can allow zero increments explicitly.
A crossing penalty discourages violations but does not guarantee their absence unless the implementation enforces a hard constraint. Apply the chosen transformation identically at validation and serving time. Recompute all losses and interval metrics afterward; reporting pre-transformation loss with post-transformation intervals mixes two different predictors.
7. Evaluate loss, calibration and usefulness
Report mean pinball loss separately for each τ and compare against a frozen baseline. For continuous outcomes, inspect the fraction y≤qτ near τ, globally and by relevant slice. For discrete outcomes with atoms, exact equality need not be attainable: examine both strict and non-strict empirical fractions, consistent with the subgradient inequality. A valid quantile can have more than τ of observations at or below it.
For continuous outcomes and correct conditional quantiles, [q0.1,q0.9] contains 80% of outcomes conditionally. An estimated pair does not inherit that property merely from its labels. Measure interval coverage and width together; very broad intervals may cover well while being operationally useless. Group-level failures can be hidden by an acceptable overall average.
For example, 800 covered cases out of 1,000 give empirical coverage 80%. Under an independent Bernoulli approximation, the standard error is sqrt(0.8×0.2/1000)=0.01265, or 1.265 percentage points. A rough normal 95% interval is 77.52%–82.48%. This is uncertainty about measured aggregate coverage, not a new prediction interval and not a guarantee of future conditional coverage. Correlated cases need a suitable clustered or temporal uncertainty analysis.
Watch tail loss after distribution shifts, promotion changes and label delays. Separate zero demand from missing outcomes. Evaluate shortage and surplus costs under the intended decision policy as well as statistical loss. Keep conformal calibration, if used, as an additional procedure with its own data split and assumptions rather than attributing its guarantee to pinball training.
8. Trade-offs and follow-ups
Direct quantile models avoid specifying a complete outcome distribution but can produce inconsistent outputs across levels. A parametric distribution gives coherent quantiles while risking misspecification. Shared models borrow information across levels but may compromise tail fit. More extreme quantiles align with asymmetric costs while demanding more data to assess reliably.
Follow-ups: What happens when the target has many zeros? How do sample weights change the target population? Why does a median minimize absolute loss? Can monotone transformations of the outcome preserve quantiles? How do you estimate a portfolio quantile with dependent outcomes? What if the cost ratio varies by customer? How would you test whether a crossing correction helped?
9. Self-review rubric
- Define the conditional outcome, horizon and quantile convention.
- Get both branches and gradient signs of pinball loss correct.
- Handle ties and nonunique empirical minimizers explicitly.
- Connect cost asymmetry to a quantile only under stated assumptions.
- Distinguish aggregate quantiles from sums of marginal quantiles.
- Handle crossing and reevaluate the actual served predictor.
- Separate observed coverage, prediction intervals and parameter uncertainty.
Sources and related practice
scikit-learn: mean_pinball_loss, publication date not stated; retrieved September 27, 2026. Official reference for the quantile-loss metric and its quantile-level parameter. Derivations, data examples and the proposed evaluation pipeline here are original worked practice.
Continue with conformal prediction and forecasting under stockouts.
Continue your preparation
Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.