def test_gaussian_noise_binary(self):
        """
        Test Gaussian noise for binary classifier.
        """
        (_, _), (x_test, _) = self.mnist
        classifier = get_image_classifier_kr_tf_binary()
        preds = classifier.predict(x_test[0:1])
        postprocessor = GaussianNoise(scale=0.1)
        post_preds = postprocessor(preds=preds)

        classifier_prediction_expected = np.asarray([[0.5301345]], dtype=np.float32)
        post_classifier_prediction_expected = np.asarray([[0.577278]], dtype=np.float32)

        np.testing.assert_array_almost_equal(preds, classifier_prediction_expected, decimal=4)
        np.testing.assert_array_almost_equal(post_preds, post_classifier_prediction_expected, decimal=4)
Beispiel #2
0
    def test_reverse_sigmoid_gamma_binary(self):
        """
        Test reverse sigmoid parameter gamma for binary classifier
        """
        (_, _), (x_test, _) = self.mnist
        classifier = get_image_classifier_kr_tf_binary()
        preds = classifier.predict(x_test[0:1])
        postprocessor = ReverseSigmoid(beta=1.0, gamma=0.5)
        post_preds = postprocessor(preds=preds)

        classifier_prediction_expected = np.asarray([[0.5301345]], dtype=np.float32)
        post_classifier_prediction_expected = np.asarray([[0.51505363]], dtype=np.float32)

        np.testing.assert_array_almost_equal(preds, classifier_prediction_expected, decimal=4)
        np.testing.assert_array_almost_equal(post_preds, post_classifier_prediction_expected, decimal=4)
Beispiel #3
0
    def test_class_labels_binary(self):
        """
        Test class labels for binary classifier.
        """
        (_, _), (x_test, _) = self.mnist
        classifier = get_image_classifier_kr_tf_binary()
        preds = classifier.predict(x_test[0:1])
        postprocessor = ClassLabels()
        post_preds = postprocessor(preds=preds)

        classifier_prediction_expected = np.asarray([[0.5301345]], dtype=np.float32)
        post_classifier_prediction_expected = np.asarray([[1.0]], dtype=np.float32)

        np.testing.assert_array_almost_equal(preds, classifier_prediction_expected, decimal=4)
        np.testing.assert_array_almost_equal(post_preds, post_classifier_prediction_expected, decimal=4)
Beispiel #4
0
    def test_binary_decimals_0_6(self):
        """
        Test with cutoff of 0.6 for binary classifier.
        """
        (_, _), (x_test, _) = self.mnist
        classifier = get_image_classifier_kr_tf_binary()
        preds = classifier.predict(x_test[0:1])
        postprocessor = HighConfidence(cutoff=0.6)
        post_preds = postprocessor(preds=preds)

        classifier_prediction_expected = np.asarray([[0.5301345]],
                                                    dtype=np.float32)
        post_classifier_prediction_expected = np.asarray([[0.0]],
                                                         dtype=np.float32)

        np.testing.assert_array_almost_equal(preds,
                                             classifier_prediction_expected,
                                             decimal=4)
        np.testing.assert_array_almost_equal(
            post_preds, post_classifier_prediction_expected, decimal=4)