code: def testSquaredPearsonCorrelationWithWeights(self):
      computations = squared_pearson_correlation.SquaredPearsonCorrelation().computations(
          example_weighted=True
      )
      metric = computations[0]
  
      example1 = {
          "labels": np.array([1.0]),
          "predictions": np.array([1.0]),
          "example_weights": np.array([1.0]),
      }
      example2 = {
          "labels": np.array([4.0]),
          "predictions": np.array([2.0]),
          "example_weights": np.array([2.0]),
      }
      example3 = {
          "labels": np.array([3.0]),
          "predictions": np.array([3.0]),
          "example_weights": np.array([3.0]),
      }
      example4 = {
          "labels": np.array([3.0]),
          "predictions": np.array([4.0]),
          "example_weights": np.array([4.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))
              | "ComputeMetric" >> beam.CombinePerKey(metric.combiner)
          )
  
          # 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]
                  # 1: prediction = 1, label = 1
                  # 2: prediction = 2, label = 4
                  # 3: prediction = 3, label = 3
                  # 4: prediction = 4, label = 3
                  #
                  # pred_x_labels = 1x1x1 + 2x2x4 + 3x3x3 + 4x4x3 = 92
                  # labels = 1x1 + 2x4 + 3x3 + 4x3 = 30
                  # preds = 1 + 2x2 + 3x3 + 4x4= 30
                  # sq_labels = 1x1x1 + 2x4x4+ 3x3x3 + 4x3x3 = 96
                  # sq_preds = 1x1x1 + 2x2x2 + 3x3x3 + 4x4x4 = 100
                  # examples = 1 + 2 + 3 + 4 = 10
                  #
                  # r^2 = (92 - 30 * 30 / 10)^2 / (100 - 30^2 / 10) * (96 - 30^2 / 10)
                  # r^2 = 4 / (10 * 6) = 0.06667
                  self.assertDictElementsAlmostEqual(
                      got_metrics, {key: 0.06667}, 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/squared_pearson_correlation_test.py
imports: import math
  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 metric_util
  from tensorflow_model_analysis.metrics import squared_pearson_correlation
label_desc: Use image node_id 2 for calling the SquaredPearsonCorrelationTest obj's underlying member method code with example usage: obj.testSquaredPearsonCorrelationWithWeights() without return types