def testPrepareMultipleLabelsAndPredictionsMultiDimension(self):
        labels = [[0], [1]]
        preds = {'probabilities': [[0.2, 0.8], [0.3, 0.7]]}
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([[0], [1]]))
        self.assertAllClose(got_preds, np.array([[0.2, 0.8], [0.3, 0.7]]))
  def testPrepareLabelsAndPredictionsEmptySparseTensorValue(self):
    labels = tf.compat.v1.SparseTensorValue(
        values=np.array([]), indices=np.array([]), dense_shape=(0, 2))
    preds = {'probabilities': [0.2, 0.7, 0.1], 'all_classes': ['a', 'b', 'c']}
    got_labels, got_preds = metric_util.prepare_labels_and_predictions(
        labels, preds)

    self.assertAllClose(got_labels, np.array([0, 0, 0]))
    self.assertAllClose(got_preds, np.array([0.2, 0.7, 0.1]))
    def testPrepareLabelsAndPredictionsMixedBatching(self):
        labels = np.array([1])
        preds = {
            'predictions': np.array([[0.8]]),
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1]))
        self.assertAllClose(got_preds, np.array([[0.8]]))
    def testPrepareLabelsAndPredictions(self):
        labels = [0]
        preds = {
            'logistic': np.array([0.8]),
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([0]))
        self.assertAllClose(got_preds, np.array([0.8]))
    def testPrepareMultipleLabelsAndPredictionsPythonList(self):
        labels = ['b', 'c', 'a']
        preds = {
            'probabilities': [0.2, 0.7, 0.1],
            'all_classes': ['a', 'b', 'c']
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1, 2, 0]))
        self.assertAllClose(got_preds, np.array([0.2, 0.7, 0.1]))
    def testPrepareMultipleLabelsAndPredictions(self):
        labels = np.array(['b', 'c', 'a'])
        preds = {
            'scores': np.array([0.2, 0.7, 0.1]),
            'classes': np.array(['a', 'b', 'c'])
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1, 2, 0]))
        self.assertAllClose(got_preds, np.array([0.2, 0.7, 0.1]))
    def testPrepareLabelsAndPredictionsBatched(self):
        labels = [['b']]
        preds = {
            'logistic': np.array([[0.8]]),
            'all_classes': np.array([['a', 'b', 'c']])
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([[1]]))
        self.assertAllClose(got_preds, np.array([[0.8]]))
Example #8
0
    def testPrepareLabelsAndPredictionsUsingBinaryScoresUnbatched(self):
        labels = np.array([1])
        preds = {
            'scores': np.array([0.3, 0.7]),
            'classes': np.array(['a', 'b'])
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1]))
        self.assertAllClose(got_preds, np.array([0.3, 0.7]))
Example #9
0
    def testPrepareLabelsAndPredictionsUsingBinaryScoresSparse(self):
        labels = np.array([1, 0])
        preds = {
            'scores': np.array([[0.9, 0.2], [0.3, 0.7]]),
            'classes': np.array([['a', 'b'], ['a', 'b']])
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1, 0]))
        self.assertAllClose(got_preds, np.array([[0.9, 0.2], [0.3, 0.7]]))
  def testPrepareLabelsAndPredictionsSparseTensorValueWithBatching(self):
    labels = tf.compat.v1.SparseTensorValue(
        indices=np.array([1, 2]), values=np.array([1, 1]), dense_shape=(1, 2))
    preds = {
        'probabilities': [[0.2, 0.7, 0.1]],
        'all_classes': [['a', 'b', 'c']]
    }
    got_labels, got_preds = metric_util.prepare_labels_and_predictions(
        labels, preds)

    self.assertAllClose(got_labels, np.array([[0, 1, 1]]))
    self.assertAllClose(got_preds, np.array([[0.2, 0.7, 0.1]]))
Example #11
0
    def testPrepareLabelsAndPredictionsSparseTensorValueAndVocab(self):
        labels = types.SparseTensorValue(indices=np.array([0, 2]),
                                         values=np.array(['c', 'a']),
                                         dense_shape=np.array([1, 2]))
        preds = {
            'probabilities': [0.2, 0.7, 0.1],
            'all_classes': ['a', 'b', 'c']
        }
        got_labels, got_preds = metric_util.prepare_labels_and_predictions(
            labels, preds)

        self.assertAllClose(got_labels, np.array([1, 0, 1]))
        self.assertAllClose(got_preds, np.array([0.2, 0.7, 0.1]))