autopycoin.losses.QuantileLossError#

class autopycoin.losses.QuantileLossError(quantiles: Union[int, float, List[Union[int, float, List[Union[int, float]]]]] = 0.5, reduction: Optional[str] = 'sum', name: Optional[str] = 'q_loss', **kwargs: dict)[source]#

Calculate the quantile loss error between y_true and y_pred across all examples.

Parameters
quantilesarray, dataframe, list or tensor of shape (batch_size, d0, .. dN)

The set of quantiles on which is calculated the quantile loss.

reductiontf.keras.losses.Reduction, Optional

Type of tf.keras.losses.Reduction`to apply to loss. Default value is `AUTO. AUTO indicates that the reduction option will be determined by the usage context. For almost all cases this defaults to SUM_OVER_BATCH_SIZE. When used with tf.distribute.Strategy, outside of built-in training lotf such as tf.keras compile and fit, using AUTO or SUM_OVER_BATCH_SIZE will raise an error. Please see this custom training [tutorial]( https://www.tensorflow.org/tutorials/distribute/custom_training) for more details.

namestr, Optional

name for the op. Default to ‘quantile_loss’.

Returns
errortensor of shape (batch_size, d0, .. dN)

The error.

Examples

>>> import tensorflow as tf
>>> from autopycoin.losses import QuantileLossError
>>> y_true = [[[0.], [1.]], [[0.], [0.]]]
>>> y_pred = [[[1.], [1.]], [[1.], [0.]]]
>>> # Using 'auto'/'sum_over_batch_size' reduction type.
>>> ql = QuantileLossError(quantiles=[0.5])
>>> ql(y_true, y_pred).numpy()
0.5
>>> # Calling with 'sample_weight'.
>>> ql(y_true, y_pred, sample_weight=[0.7, 0.3]).numpy()
0.25
>>> # Using 'AUTO' reduction type.
>>> ql = QuantileLossError(quantiles=[0.5],
...     reduction=tf.keras.losses.Reduction.AUTO)
>>> ql(y_true, y_pred).numpy()
0.25
>>> # Using 'none' reduction type.
>>> ql = QuantileLossError(quantiles=[0.5],
...     reduction=tf.keras.losses.Reduction.NONE)
>>> ql(y_true, y_pred).numpy()
array([0.25, 0.25], dtype=float32)
>>> # Using multiple quantiles.
>>> y_pred = [[[1.,1.,1.], [1.,1.,1.]], [[1.,1.,1.], [0.,0.,0.]]]
>>> ql = QuantileLossError(quantiles=[0.1, 0.5, 0.9])
>>> ql(y_true, y_pred).numpy()
1.5
Attributes
quantileslist[float]