Pinball Loss (a.k.a. Quantile Loss)
1. Definition
Pinball loss measures the accuracy of predicted quantiles rather than the mean.
It’s used when we want to estimate, for example, the 90th percentile (quantile = 0.9) of a target variable.
For a quantile level $q \in (0,1)$:
$L_q(y, \hat{y}) = \begin{cases} q \cdot (y – \hat{y}), & \text{if } y \geq \hat{y} \\ (1-q) \cdot (\hat{y} – y), & \text{if } y < \hat{y} \end{cases}$
where:
- $y$ = actual value
- $\hat{y}$ = predicted quantile value
- $q$ = quantile (e.g., 0.5 = median, 0.9 = 90th percentile)
2. Intuition
- If predicting the q-th quantile:
- Under-predictions are penalized q times the error.
- Over-predictions are penalized (1-q) times the error.
- This asymmetry reflects the definition of a quantile.
Example:
- If $q = 0.9$, underestimating the 90th percentile is worse than overestimating it.
3. Special Case – Median (q = 0.5)
When $q = 0.5$:
- Pinball loss reduces to MAE (Mean Absolute Error).
4. Example
Suppose we predict the 90th percentile of demand:
- Quantile level: $q = 0.9$
- Actual demand: $y = 100$
- Predicted quantile: $\hat{y} = 80$
Since $y > \hat{y}$:
$L_{0.9} = 0.9 \cdot (100 – 80) = 18$
If predicted $\hat{y} = 120$:
$L_{0.9} = (1 – 0.9) \cdot (120 – 100) = 0.1 \cdot 20 = 2$
Underestimating (loss = 18) is punished much more heavily than overestimating (loss = 2).
5. Why It Matters
- Suitable for quantile regression (predicting percentiles, prediction intervals).
- Widely used in forecasting competitions (e.g., energy demand, sales forecasting).
- Captures asymmetric risks:
- In inventory → underestimating demand is worse than overestimating.
- In finance → underestimating risk is worse than overestimating.
6. Python Example
import numpy as np
def pinball_loss(y_true, y_pred, q=0.9):
errors = y_true - y_pred
return np.mean(np.where(errors >= 0, q * errors, (1 - q) * -errors))
# Example
y_true = np.array([100, 200, 300])
y_pred = np.array([90, 210, 280])
loss = pinball_loss(y_true, y_pred, q=0.9)
print("Pinball Loss (q=0.9):", loss)
Output:
Pinball Loss (q=0.9): 7.0
Summary
- Pinball Loss = loss function for quantile regression.
- Penalizes over/underestimation differently depending on quantile level $q$.
- $q = 0.5$ → equivalent to MAE.
- Useful in forecasting, risk management, inventory planning where asymmetric penalties matter.
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
