I am trying to implement Quantile loss for a regression problem based on the formula from this article (number 14 at the end of the article):
Here is my implementation:
import numpy as np
def quantile():
percentiles = [0.01, 0.25, 0.5, 0.75, 0.99]
gamma = 1e-2
np.random.seed(0)
y_true = [1.0, 0.0, -1.0, 0.0, 0.4, 0.8, 0.9, 1.0 , 1.0, -0.6, -0.9, -1.0]
y_pred = np.random.rand(12)
error = bk.abs(y_true - y_pred)
cond = error < gamma
quantile_loss = bk.sum(tf.where(cond, (gamma-1) * error, gamma * error), axis=-1)
quantile()
I would like to check if my implementation is correct considering the condition (y_true<y_pred
) to be applied when multiplying gamma
. Also, if this is based on percentiles, how to apply percentiles in the loss formula?