code: def testMacroAverageWithWeights(self):
      metric_name = "test"
      class_ids = [0, 1, 2]
      class_weights = {0: 0.2, 1: 0.3, 2: 0.5}
      sub_keys = [metric_types.SubKey(class_id=i) for i in class_ids]
      sub_key_values = [0.1, 0.2, 0.3]
      computations = aggregation.macro_average(
          metric_name,
          sub_keys,
          eval_config=config_pb2.EvalConfig(),
          class_weights=class_weights,
      )
      metric = computations[0]
  
      sub_metrics = {}
      for sub_key, value in zip(sub_keys, sub_key_values):
          key = metric_types.MetricKey(
              name=metric_name, sub_key=sub_key
          )
          sub_metrics[key] = value
  
      with beam.Pipeline() as pipeline:
          # pylint: disable=no-value-for-parameter
          result = (
              pipeline
              | "Create" >> beam.Create([((), sub_metrics)])
              | "ComputeMetric"
              >> beam.Map(lambda x: (x[0], metric.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, ())
                  key = metric.keys[0]
                  expected_value = (
                      0.1 * 0.2 + 0.2 * 0.3 + 0.3 * 0.5
                  ) / (0.2 + 0.3 + 0.5)
                  self.assertDictElementsAlmostEqual(
                      got_metrics, {key: expected_value}, places=5
                  )
  
              except AssertionError as err:
                  raise util.BeamAssertException(err)
  
          util.assert_that(result, check_result, label="result")
  
file_path: model-analysis/tensorflow_model_analysis/metrics/aggregation_test.py
imports: import copy
  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 aggregation
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 3 for calling the AggregationMetricsTest obj's underlying member method code with example usage: obj.testMacroAverageWithWeights() without return types