def _test_tf(avg, beta, act, pred, threshold): act = tf.constant(act, tf.float32) pred = tf.constant(pred, tf.float32) fbeta = FBetaScore(3, avg, beta, threshold) fbeta.update_state(act, pred) return fbeta.result().numpy()
def _test_tf(self, avg, beta, act, pred, threshold): act = tf.constant(act, tf.float32) pred = tf.constant(pred, tf.float32) fbeta = FBetaScore(3, avg, beta, threshold) self.evaluate(tf.compat.v1.variables_initializer(fbeta.variables)) self.evaluate(fbeta.update_state(act, pred)) return self.evaluate(fbeta.result())
def test_eq(): f1 = F1Score(3) fbeta = FBetaScore(3, beta=1.0) preds = [ [0.9, 0.1, 0], [0.2, 0.6, 0.2], [0, 0, 1], [0.4, 0.3, 0.3], [0, 0.9, 0.1], [0, 0, 1], ] actuals = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0], [1, 0, 0], [0, 0, 1]] fbeta.update_state(actuals, preds) f1.update_state(actuals, preds) np.testing.assert_allclose(fbeta.result().numpy(), f1.result().numpy())
def test_eq(self): f1 = F1Score(3) fbeta = FBetaScore(3, beta=1.0) self.evaluate(tf.compat.v1.variables_initializer(f1.variables)) self.evaluate(tf.compat.v1.variables_initializer(fbeta.variables)) preds = [[0.9, 0.1, 0], [0.2, 0.6, 0.2], [0, 0, 1], [0.4, 0.3, 0.3], [0, 0.9, 0.1], [0, 0, 1]] actuals = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 0], [1, 0, 0], [0, 0, 1]] self.evaluate(fbeta.update_state(actuals, preds)) self.evaluate(f1.update_state(actuals, preds)) self.assertAllClose( self.evaluate(fbeta.result()), self.evaluate(f1.result()))