Example #1
0
    def test_accuracy_binary_classifier(self):
        layer = tl.Accuracy(classifier=tl.ThresholdToBinary())
        targets = np.array([[0, 0, 1, 1], [1, 1, 1, 0]])
        weights = np.ones_like(targets)

        model_outputs = np.array([[.499, .500, .501, .502],
                                  [.503, .502, .501, .500]])
        accuracy = layer([model_outputs, targets, weights])
        self.assertEqual(accuracy, 1.0)

        model_outputs = np.array([[.498, .499, .500, .501],
                                  [.502, .501, .500, .499]])
        accuracy = layer([model_outputs, targets, weights])
        self.assertEqual(accuracy, .75)
Example #2
0
 def test_threshold_to_binary(self):
     layer = tl.ThresholdToBinary()
     x = np.array([.30, .49, .50, .51, .70])
     y = layer(x)
     self.assertEqual(y.tolist(), [0, 0, 0, 1, 1])