code: def testCalibrationMetricsWithWeights(self, metric, expected_value):
      computations = metric.computations(example_weighted=True)
      weighted_totals = computations[0]
      metric = computations[1]
  
      example1 = {
          "labels": np.array([0.0]),
          "predictions": np.array([1.0]),
          "example_weights": np.array([0.5]),
      }
      example2 = {
          "labels": np.array([1.0]),
          "predictions": np.array([0.7]),
          "example_weights": np.array([0.7]),
      }
      example3 = {
          "labels": np.array([0.0]),
          "predictions": np.array([0.5]),
          "example_weights": np.array([0.9]),
      }
  
      with beam.Pipeline() as pipeline:
          # pylint: disable=no-value-for-parameter
          result = (
              pipeline
              | "Create" >> beam.Create([example1, example2, example3])
              | "Process"
              >> beam.Map(metric_util.to_standard_metric_inputs)
              | "AddSlice" >> beam.Map(lambda x: ((), x))
              | "ComputeWeightedTotals"
              >> beam.CombinePerKey(weighted_totals.combiner)
              | "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]
                  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/calibration_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 calibration
  from tensorflow_model_analysis.metrics import metric_util
label_desc: Use image node_id 2 for calling the CalibrationMetricsTest obj's underlying member method code with example usage: obj.testCalibrationMetricsWithWeights(metric, expected_value) without return types