Пример #1
0
 def test_no_reduction(self):
     mape_obj = losses.MeanAbsolutePercentageError(
         reduction=losses_utils.Reduction.NONE)
     y_true = K.constant([1, 9, 2, -5, -2, 6], shape=(2, 3))
     y_pred = K.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
     loss = mape_obj(y_true, y_pred, sample_weight=2.3)
     assert np.allclose(K.eval(loss), [621.8518, 352.6666], atol=1e-3)
Пример #2
0
 def test_timestep_weighted(self):
     mape_obj = losses.MeanAbsolutePercentageError()
     y_true = K.constant([1, 9, 2, -5, -2, 6], shape=(2, 3, 1))
     y_pred = K.constant([4, 8, 12, 8, 1, 3], shape=(2, 3, 1))
     sample_weight = K.constant([3, 6, 5, 0, 4, 2], shape=(2, 3))
     loss = mape_obj(y_true, y_pred, sample_weight=sample_weight)
     assert np.allclose(K.eval(loss), 694.4445, atol=1e-3)
Пример #3
0
 def test_sample_weighted(self):
     mape_obj = losses.MeanAbsolutePercentageError()
     y_true = K.constant([1, 9, 2, -5, -2, 6], shape=(2, 3))
     y_pred = K.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
     sample_weight = K.constant([1.2, 3.4], shape=(2, 1))
     loss = mape_obj(y_true, y_pred, sample_weight=sample_weight)
     assert np.allclose(K.eval(loss), 422.8888, atol=1e-3)
Пример #4
0
 def test_unweighted(self):
     mape_obj = losses.MeanAbsolutePercentageError()
     y_true = K.constant([1, 9, 2, -5, -2, 6], shape=(2, 3))
     y_pred = K.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
     loss = mape_obj(y_true, y_pred)
     assert np.allclose(K.eval(loss), 211.8518, atol=1e-3)
Пример #5
0
 def test_all_correct_unweighted(self):
     mape_obj = losses.MeanAbsolutePercentageError()
     y_true = K.constant([4, 8, 12, 8, 1, 3], shape=(2, 3))
     loss = mape_obj(y_true, y_true)
     assert np.allclose(K.eval(loss), 0.0, atol=1e-3)
Пример #6
0
 def test_config(self):
     mape_obj = losses.MeanAbsolutePercentageError(
         reduction=losses_utils.Reduction.SUM, name='mape_1')
     assert mape_obj.name == 'mape_1'
     assert mape_obj.reduction == losses_utils.Reduction.SUM