class_docstr: Computes squared pearson correlation (r^2) metric.
class_docstr_tok: ["Computes","squared","pearson","correlation","(","r^2",")","metric","."]
code: def add_input(
      self,
      accumulator: _SquaredPearsonCorrelationAccumulator,
      element: metric_types.StandardMetricInputs,
  ) -> _SquaredPearsonCorrelationAccumulator:
      for (
          label,
          prediction,
          example_weight,
      ) in metric_util.to_label_prediction_example_weight(
          element,
          eval_config=self._eval_config,
          model_name=self._key.model_name,
          output_name=self._key.output_name,
          aggregation_type=self._aggregation_type,
          class_weights=self._class_weights,
          example_weighted=self._example_weighted,
      ):
          example_weight = float(example_weight)
          label = float(label)
          prediction = float(prediction)
          accumulator.total_weighted_labels += example_weight * label
          accumulator.total_weighted_predictions += (
              example_weight * prediction
          )
          accumulator.total_weighted_squared_labels += (
              example_weight * label**2
          )
          accumulator.total_weighted_squared_predictions += (
              example_weight * prediction**2
          )
          accumulator.total_weighted_labels_times_predictions += (
              example_weight * label * prediction
          )
          accumulator.total_weighted_examples += example_weight
      return accumulator
  
file_path: model-analysis/tensorflow_model_analysis/metrics/squared_pearson_correlation.py
imports: from typing import Dict, Iterable, Optional
  import apache_beam
  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 _SquaredPearsonCorrelationCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: accumulator