示例#1
0
 def test_weighted(self):
     msle_obj = metrics.MeanSquaredLogarithmicError()
     self.evaluate(variables.variables_initializer(msle_obj.variables))
     y_true = constant_op.constant(((0, 1, 0, 1, 0), (0, 0, 1, 1, 1),
                                    (1, 1, 1, 1, 0), (0, 0, 0, 0, 1)))
     y_pred = constant_op.constant(((0, 0, 1, 1, 0), (1, 1, 1, 1, 1),
                                    (0, 1, 0, 1, 0), (1, 1, 1, 1, 1)))
     sample_weight = constant_op.constant((1., 1.5, 2., 2.5))
     result = msle_obj(y_true, y_pred, sample_weight=sample_weight)
     self.assertAllClose(0.26082, self.evaluate(result), atol=1e-5)
示例#2
0
    def test_config(self):
        msle_obj = metrics.MeanSquaredLogarithmicError(name='my_msle',
                                                       dtype=dtypes.int32)
        self.assertEqual(msle_obj.name, 'my_msle')
        self.assertEqual(msle_obj._dtype, dtypes.int32)

        # Check save and restore config
        msle_obj2 = metrics.MeanSquaredLogarithmicError.from_config(
            msle_obj.get_config())
        self.assertEqual(msle_obj2.name, 'my_msle')
        self.assertEqual(msle_obj2._dtype, dtypes.int32)
示例#3
0
    def test_unweighted(self):
        msle_obj = metrics.MeanSquaredLogarithmicError()
        self.evaluate(variables.variables_initializer(msle_obj.variables))
        y_true = constant_op.constant(((0, 1, 0, 1, 0), (0, 0, 1, 1, 1),
                                       (1, 1, 1, 1, 0), (0, 0, 0, 0, 1)))
        y_pred = constant_op.constant(((0, 0, 1, 1, 0), (1, 1, 1, 1, 1),
                                       (0, 1, 0, 1, 0), (1, 1, 1, 1, 1)))

        update_op = msle_obj.update_state(y_true, y_pred)
        self.evaluate(update_op)
        result = msle_obj.result()
        self.assertAllClose(0.24022, result, atol=1e-5)