Skip to contents

A generalized version of the quantile loss. The model can predict multiple quantiles at once.

Usage

loss_quantile(...)

loss_pinball(...)

Arguments

quantiles

List of quantiles (numeric vector with values between 0 and 1).

Details

Loss value for a single sample-timestep-quantile is computed as: $$QL(y_t, \hat{y}_t, q) = max(q(y_t - \hat{y}_t), (q - 1)(y_t - \hat{y}_t))$$ or equivalently as : $$QL(y_t, \hat{y}_t, q) = max(q(y_t - \hat{y}_t), 0) + max((1 - q)(\hat{y}_t - y_t), 0)$$

When multiple quantiles are defined, the generalized, averaged loss is computed according to the equation: $$\mathcal{L}(\Omega, W) = \Sigma_{y_t \in \Omega}\Sigma_{q \in \mathcal{Q}}\Sigma^{\tau_{max}}_{\tau=1} \frac{QL(y_t, \hat{y}(q, t - \tau, \tau), q)}{M_{\tau_{max}}}$$

The loss function is computed as above when reduction = 'auto or reduction = 'mean'.

Note

For the moment, you can only use loss_quantile to instantiate a class and not call directly like other loss in keras. Please see: #1342 issue

See also

Examples

y_pred <- array(runif(60), c(2, 10, 3))
y_true <- array(runif(20), c(2, 10, 1))

loss_quantile(quantiles = c(0.1, 0.5, 0.9), reduction = 'auto')(y_true, y_pred)
#> tf.Tensor(0.15113433, shape=(), dtype=float32)
loss_quantile(quantiles = c(0.1, 0.5, 0.9), reduction = 'sum')(y_true, y_pred)
#> tf.Tensor(9.06806, shape=(), dtype=float32)