コード例 #1
0
 def test_singleton_batch(self):
     """
     In the case of a batch size of 1, y_true has shape (number_of_classes,) and accuracy should be correctly computed.
     """
     y_true = np.ones((10,))
     y_true_compare = np.ones((1, 10))
     y_prob = -np.ones((1, 10))
     assert_equals(accuracy.hamming_accuracy_from_blob(y_true, y_prob),
                   accuracy.hamming_accuracy_from_blob(y_true_compare, y_prob))
コード例 #2
0
 def test_accuracy_0(self):
     """
     Extreme case with accuracy 0 and no threshold
     """
     for n in range(2, 100):
         y_true = np.ones((n, n))
         y_prob = -np.ones((n, n)) / n
         assert_equals(accuracy.hamming_accuracy_from_blob(y_true, y_prob), 0)
コード例 #3
0
 def test_accuracy_1_with_threshold_0(self):
     """
     Accuracy 0 if all values under threshold
     """
     threshold = 1
     for n in range(2, 100):
         y_true = np.ones((n, n))
         y_prob = np.ones((n, n)) / n
         assert_equals(accuracy.hamming_accuracy_from_blob(y_true, y_prob, threshold), 0)
コード例 #4
0
 def test_extra_dimension(self):
     """
     If y_true has extra dimensions, we use a regular compact matricial form in 2D.
     """
     y_true = np.array([[[[1]],
                         [[0]],
                         [[0]]],
                        [[[0]],
                         [[1]],
                         [[0]]],
                        [[[0]],
                         [[0]],
                         [[1]]], ])
     y_true_compare = np.identity(3)
     y_prob = np.array([[+1, -1, -1],
                        [-1, +1, -1],
                        [-1, -1, +1]])
     assert_equals(accuracy.hamming_accuracy_from_blob(y_true, y_prob),
                   accuracy.hamming_accuracy_from_blob(y_true_compare, y_prob))