autopycoin.losses.SymetricMeanAbsolutePercentageError#
- class autopycoin.losses.SymetricMeanAbsolutePercentageError(reduction: Optional[str] = 'auto', name: Optional[str] = 'smape')[source]#
Calculate the symetric mean absolute percentage error between y_true and y_pred.
To avoid infinite error, we add epsilon value to zeros denominator. This behavior can be modified by setting mask to True. then, infinite instances are not taken into account in calculation.
- Parameters
- 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.
- name
str, Optional name for the op. Default to “smape”.
Examples
>>> import tensorflow as tf >>> from autopycoin.losses import SymetricMeanAbsolutePercentageError >>> y_true = [[0., 1.], [0., 0.]] >>> y_pred = [[1., 1.], [1., 0.]] >>> # Using 'auto'/'sum_over_batch_size' reduction type. >>> smape = SymetricMeanAbsolutePercentageError() >>> smape(y_true, y_pred).numpy() 99.999985 >>> # Calling with 'sample_weight'. >>> smape(y_true, y_pred, sample_weight=[0.7, 0.3]).numpy() 49.999992 >>> # Using 'sum' reduction type. >>> smape = SymetricMeanAbsolutePercentageError( ... reduction=tf.keras.losses.Reduction.SUM) >>> smape(y_true, y_pred).numpy() 199.99997 >>> # Using 'none' reduction type. >>> smape = SymetricMeanAbsolutePercentageError( ... reduction=tf.keras.losses.Reduction.NONE) >>> smape(y_true, y_pred).numpy() array([100., 100.], dtype=float32)