code: def testConfusionMatrixMetrics(self, metric, expected_value):
      if _TF_MAJOR_VERSION < 2 and metric.__class__.__name__ in (
          "SpecificityAtSensitivity",
          "SensitivityAtSpecificity",
          "PrecisionAtRecall",
          "RecallAtPrecision",
      ):
          self.skipTest("Not supported in TFv1.")
  
      computations = metric.computations(example_weighted=True)
      histogram = computations[0]
      matrices = computations[1]
      metrics = computations[2]
  
      # tp = 1
      # tn = 2
      # fp = 3
      # fn = 4
      example1 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.6]),
          "example_weights": np.array([1.0]),
      }
      example2 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.3]),
          "example_weights": np.array([1.0]),
      }
      example3 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.2]),
          "example_weights": np.array([1.0]),
      }
      example4 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.6]),
          "example_weights": np.array([1.0]),
      }
      example5 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.7]),
          "example_weights": np.array([1.0]),
      }
      example6 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.8]),
          "example_weights": np.array([1.0]),
      }
      example7 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.1]),
          "example_weights": np.array([1.0]),
      }
      example8 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.2]),
          "example_weights": np.array([1.0]),
      }
      example9 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.3]),
          "example_weights": np.array([1.0]),
      }
      example10 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.4]),
          "example_weights": np.array([1.0]),
      }
  
      with beam.Pipeline() as pipeline:
          # pylint: disable=no-value-for-parameter
          result = (
              pipeline
              | "Create"
              >> beam.Create(
                  [
                      example1,
                      example2,
                      example3,
                      example4,
                      example5,
                      example6,
                      example7,
                      example8,
                      example9,
                      example10,
                  ]
              )
              | "Process"
              >> beam.Map(metric_util.to_standard_metric_inputs)
              | "AddSlice" >> beam.Map(lambda x: ((), x))
              | "ComputeHistogram"
              >> beam.CombinePerKey(histogram.combiner)
              | "ComputeMatrices"
              >> beam.Map(lambda x: (x[0], matrices.result(x[1])))
              | "ComputeMetrics"
              >> beam.Map(lambda x: (x[0], metrics.result(x[1])))
          )
  
          # pylint: enable=no-value-for-parameter
  
          def check_result(got):
              try:
                  self.assertLen(got, 1)
                  got_slice_key, got_metrics = got[0]
                  self.assertEqual(got_slice_key, ())
                  self.assertLen(got_metrics, 1)
                  key = metrics.keys[0]
                  self.assertIn(key, got_metrics)
                  # np.testing utils automatically cast floats to arrays which fails
                  # to catch type mismatches.
                  self.assertEqual(
                      type(expected_value), type(got_metrics[key])
                  )
                  np.testing.assert_almost_equal(
                      got_metrics[key], expected_value, decimal=5
                  )
              except AssertionError as err:
                  raise util.BeamAssertException(err)
  
          util.assert_that(result, check_result, label="result")
  
imports: import math
  from absl.testing import parameterized
  import apache_beam
  from apache_beam.testing import util
  import numpy
  import tensorflow
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.metrics import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import confusion_matrix_metrics
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
label_desc: Use image node_id 2 for calling the ConfusionMatrixMetricsTest obj's underlying member method code with example usage: obj.testConfusionMatrixMetrics(metric, expected_value) without return types