KatInterview

Targeting the Right Quantile When Errors Have Unequal Costs

Statistics & ExperimentsModel answer
MediumModel answerStatistics & Experimentsquantile regressionloss functionsforecasting

Last updated

Derive which statistic each loss function optimizes, then translate an asymmetric stockout-vs-overstock cost ratio into a concrete quantile target.

Setting the Scene

You are building a demand forecasting model for a retail chain's inventory system. Each day the model produces a prediction for how many units of a product will sell. You are deciding between two styles of output:

  • A single-number forecast (a point prediction of expected demand).
  • A distributional forecast that reports specific percentiles of the predicted demand, such as the 10th, 50th, and 90th.

What You Need to Work Through

Part 1 — Define the loss

Write out the quantile loss function (also called pinball loss) for a quantile level tau, a predicted value y_hat, and an observed value y:

If y >= y_hat:  L = tau * (y - y_hat)
If y <  y_hat:  L = (1 - tau) * (y_hat - y)

Explain intuitively what this expression is doing and how the slope changes depending on which side of y_hat the observation falls.

Part 2 — What does each loss function actually estimate?

Explain, with a brief derivation, why:

  • A model trained to minimize MSE / RMSE converges to the conditional mean of the target distribution.
  • A model trained to minimize quantile loss at tau = 0.5 converges to the conditional median.

Why does this distinction matter in practice, especially for demand data?

Part 3 — Turning a cost ratio into a quantile target

The business has estimated that running out of stock (under-predicting demand) is five times more costly per unit than holding excess inventory (over-predicting demand). Using the quantile loss framework, derive the optimal quantile to target when setting your inventory level, and explain the reasoning behind the formula.

Hints

Hint 1

For Part 2, try minimizing the expected loss over a single free parameter c. Take the derivative with respect to c and set it to zero — the CDF will appear naturally in the pinball case.

Hint 2

For Part 3, think about the marginal cost of adding one more unit of stock: it saves you from a stockout with some probability and causes overstock with the complementary probability. Where is the breakeven point?

Hint 3

The formula that falls out of Part 3 is tau* = cost_under / (cost_under + cost_over). Check that the direction makes sense: when under-predicting is more expensive, tau* should be above 0.5, meaning you stock high.