#355Pinball (Quantile) Regression LossMediumLinear RegressionStatisticsLoss FunctionsAsked atAmazon · Meta · Google
Pinball (Quantile) Regression Loss
Background
Quantile regression predicts a specific quantile of rather than the mean. The loss is the asymmetric pinball loss: under-prediction is penalised by per unit, over-prediction by per unit. The ETA-prediction case uses this to train per-quantile heads (p10, p50, p90) for delivery-time confidence intervals.
Problem statement
Implement pinball_loss(y_true, y_pred, tau):
Return the mean over all samples.
Input
y_true,y_pred- array-like of floats, same length.tau-floatin , the target quantile.
Output
float >= 0.
Examples
Input: y_true=[1.0, 2.0], y_pred=[0.0, 0.0], tau=0.5
Output: 0.5 * mean([1.0, 2.0]) = 0.75
Constraints
- . ValueError otherwise.
- Lengths must match.
Notes
- tau = 0.5 -> MAE / 2. The 50%-quantile pinball loss equals half the mean absolute error.
- Asymmetric penalty. For ETA prediction with , under-promising (predicting too high) is 9x cheaper than missing the deadline (predicting too low).
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: tau=0.5 equals half the MAE
- •Example: pure under-prediction at tau=0.9
- •Sample: mixed over/under predictions at tau=0.3