コード例 #1
0
    def test_multiclass_prediction(self):
        classes = [['a', 'b', 'c']]
        predicted_probabilities = [[0, 0, 0.99], [0, 0.99, 0], [0.99, 0, 0],
                                   [0, 0.99, 0], [0, 0, 0.99]]
        predicted_indexes = [2, 1, 0, 1, 2]
        expected_result = ['c', 'b', 'a', 'b', 'c']

        automl_mock = mock.Mock()
        automl_mock.predict.return_value = np.array(predicted_probabilities)

        classifier = AutoMLClassifier(automl_mock)
        classifier._classes = [np.array(classes)]
        classifier._n_outputs = 1
        classifier._n_classes = np.array([3])

        actual_result = classifier.predict([None] * len(predicted_indexes))

        np.testing.assert_array_equal(expected_result, actual_result)
コード例 #2
0
    def test_multiclass_prediction(self):
        classes = [['a', 'b', 'c']]
        predicted_probabilities = [[0, 0, 0.99], [0, 0.99, 0], [0.99, 0, 0],
                                   [0, 0.99, 0], [0, 0, 0.99]]
        predicted_indexes = [2, 1, 0, 1, 2]
        expected_result = ['c', 'b', 'a', 'b', 'c']

        automl_mock = unittest.mock.Mock()
        automl_mock.predict.return_value = np.array(predicted_probabilities)

        classifier = AutoMLClassifier(automl_mock)
        classifier._classes = [np.array(classes)]
        classifier._n_outputs = 1
        classifier._n_classes = np.array([3])

        actual_result = classifier.predict([None] * len(predicted_indexes))

        np.testing.assert_array_equal(expected_result, actual_result)
コード例 #3
0
    def test_multilabel_prediction(self):
        classes = [[1, 2], [13, 17]]
        predicted_probabilities = [[0.99, 0], [0.99, 0], [0, 0.99],
                                   [0.99, 0.99], [0.99, 0.99]]
        predicted_indexes = np.array([[1, 0], [1, 0], [0, 1], [1, 1], [1, 1]])
        expected_result = np.array([[2, 13], [2, 13], [1, 17], [2, 17],
                                    [2, 17]])

        automl_mock = unittest.mock.Mock()
        automl_mock.predict.return_value = np.array(predicted_probabilities)

        classifier = AutoMLClassifier(automl_mock)
        classifier._classes = list(map(np.array, classes))
        classifier._n_outputs = 2
        classifier._n_classes = np.array([3, 2])

        actual_result = classifier.predict([None] * len(predicted_indexes))

        np.testing.assert_array_equal(expected_result, actual_result)
コード例 #4
0
    def test_multilabel_prediction(self):
        classes = [['a', 'b', 'c'], [13, 17]]
        predicted_probabilities = [[[0, 0, 0.99], [0.99, 0]],
                                   [[0, 0.99, 0], [0.99, 0]],
                                   [[0.99, 0, 0], [0, 0.99]],
                                   [[0, 0.99, 0], [0, 0.99]],
                                   [[0, 0, 0.99], [0, 0.99]]]
        predicted_indexes = [[2, 0], [1, 0], [0, 1], [1, 1], [2, 1]]
        expected_result = np.array([['c', 13], ['b', 13], ['a', 17], ['b', 17], ['c', 17]], dtype=object)

        automl_mock = unittest.mock.Mock()
        automl_mock.predict.return_value = np.matrix(predicted_probabilities)

        classifier = AutoMLClassifier(automl_mock)
        classifier._classes = list(map(np.array, classes))
        classifier._n_outputs = 2
        classifier._n_classes = np.array([3, 2])

        actual_result = classifier.predict([None] * len(predicted_indexes))

        np.testing.assert_array_equal(expected_result, actual_result)