Ordinary regression predicts the mean. To forecast "demand will be at most X with 90% probability", predict a quantile instead by minimising the pinball loss:
Implement:
pinball_loss(y, y_hat, q)fit_quantile(X, y, q, lr=0.05, epochs=3000): a linear model X @ w + b, starting from zeros, trained by full-batch subgradient descent. The gradient of the loss with respect to each prediction is ((y_hat >= y) - q) / n. Return (w, b).coverage(y, y_hat): the fraction of targets at or below the prediction