code: def testBinaryConfusionMatricesTopK(self):
      computations = (
          binary_confusion_matrices.binary_confusion_matrices(
              thresholds=[float("-inf")],
              sub_key=metric_types.SubKey(top_k=3),
              use_histogram=True,
          )
      )
      histogram = computations[0]
      matrices = computations[1]
  
      example1 = {
          "labels": np.array([2]),
          "predictions": np.array([0.1, 0.2, 0.1, 0.25, 0.35]),
          "example_weights": np.array([1.0]),
      }
      example2 = {
          "labels": np.array([1]),
          "predictions": np.array([0.2, 0.3, 0.05, 0.15, 0.3]),
          "example_weights": np.array([1.0]),
      }
      example3 = {
          "labels": np.array([3]),
          "predictions": np.array([0.01, 0.2, 0.09, 0.5, 0.2]),
          "example_weights": np.array([1.0]),
      }
      example4 = {
          "labels": np.array([4]),
          "predictions": np.array([0.3, 0.2, 0.05, 0.4, 0.05]),
          "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])
              | "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])))
          )  # pyformat: disable
  
          # 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)
                  thresholds = [float("-inf")]
                  name = metric_util.generate_private_name_from_arguments(
                      binary_confusion_matrices.BINARY_CONFUSION_MATRICES_NAME,
                      thresholds=thresholds,
                      example_id_key=None,
                      example_ids_count=None,
                  )
                  key = metric_types.MetricKey(
                      name=name, sub_key=metric_types.SubKey(top_k=3)
                  )
                  self.assertIn(key, got_metrics)
                  got_matrices = got_metrics[key]
                  self.assertEqual(
                      got_matrices,
                      binary_confusion_matrices.Matrices(
                          thresholds=[float("-inf")],
                          tp=[2.0],
                          fp=[10.0],
                          tn=[6.0],
                          fn=[2.0],
                      ),
                  )
  
              except AssertionError as err:
                  raise util.BeamAssertException(err)
  
          util.assert_that(result, check_result, label="result")
  
file_path: model-analysis/tensorflow_model_analysis/metrics/binary_confusion_matrices_test.py
imports: 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 metric_types
  from tensorflow_model_analysis.metrics import metric_util
label_desc: Use image node_id 5 for calling the BinaryConfusionMatricesTest obj's underlying member method code with example usage: obj.testBinaryConfusionMatricesTopK() without return types