class_docstr: Computes binary confusion matrix in TFMA.
class_docstr_tok: ["Computes","binary","confusion","matrix","in","TFMA","."]
code: def add_input(
      self,
      accumulator: MatrixAccumulator,
      element: metric_types.StandardMetricInputs,
  ) -> MatrixAccumulator:
      example_id = None
      if (
          self._example_id_key
          and self._example_id_key in element.features
      ):
          example_id = element.features[self._example_id_key]
  
      labels = []
      predictions = []
      example_weights = []
  
      for (
          label,
          prediction,
          example_weight,
      ) in self._extract_label_prediction_and_weight(
          element,
          eval_config=self._eval_config,
          model_name=self._key.model_name,
          output_name=self._key.output_name,
          sub_key=self._key.sub_key,
          fractional_labels=self._enable_fractional_labels,
          flatten=True,
          aggregation_type=self._aggregation_type,
          class_weights=self._class_weights,
          example_weighted=self._example_weighted,
      ):
          example_weights.append(
              metric_util.safe_to_scalar(example_weight)
          )
          labels.append(metric_util.safe_to_scalar(label))
          predictions.append(metric_util.safe_to_scalar(prediction))
  
      return self._binary_confusion_matrices.add_input(
          accumulator=accumulator,
          labels=labels,
          predictions=predictions,
          example_weights=example_weights,
          example_id=example_id,
      )
  
imports: from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.contrib.aggregates import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import calibration_histogram
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
label_desc: Use image node_id 3 for calling the _BinaryConfusionMatrixCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: self