class_docstr: Creates multi-label confusion matrix at thresholds from standard inputs.
class_docstr_tok: ["Creates","multi-label","confusion","matrix","at","thresholds","from","standard","inputs","."]
code: def add_input(
      self,
      accumulator: _Matrices,
      element: metric_types.StandardMetricInputs,
  ) -> _Matrices:
      labels, predictions, example_weight = next(
          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,
              example_weighted=self._example_weighted,
              flatten=False,
              require_single_example_weight=True,
          )
      )
      if not labels.shape:
          raise ValueError(
              "Labels missing from example: StandardMetricInputs={}".format(
                  element
              )
          )
      if predictions.shape in ((), (1,)):
          raise ValueError(
              "Predictions shape must be > 1 for multi-label confusion matrix: "
              "shape={}, StandardMetricInputs={}".format(
                  predictions.shape, element
              )
          )
      # If the label and prediction shapes are different then assume the labels
      # are sparse and convert them to dense.
      if (
          len(labels.shape) != len(predictions.shape)
          or labels.shape[-1] != predictions.shape[-1]
      ):
          labels = metric_util.one_hot(labels, predictions)
      example_weight = float(example_weight)
      for threshold in self._thresholds:
          if threshold not in accumulator:
              accumulator[threshold] = {}
          for actual_class_id, label in enumerate(labels):
              if not label:
                  continue
              for class_id, prediction in enumerate(predictions):
                  matrix_key = _MatrixEntryKey(
                      actual_class_id, class_id
                  )
                  fn = (
                      labels[class_id] and prediction <= threshold
                  ) * example_weight
                  fp = (
                      not labels[class_id] and prediction > threshold
                  ) * example_weight
                  tn = (
                      not labels[class_id] and prediction <= threshold
                  ) * example_weight
                  tp = (
                      labels[class_id] and prediction > threshold
                  ) * example_weight
                  if matrix_key in accumulator[threshold]:
                      accumulator[threshold][
                          matrix_key
                      ].false_negatives += fn
                      accumulator[threshold][
                          matrix_key
                      ].true_negatives += tn
                      accumulator[threshold][
                          matrix_key
                      ].false_positives += fp
                      accumulator[threshold][
                          matrix_key
                      ].true_positives += tp
                  else:
                      matrix = _ConfusionMatrix()
                      matrix.false_negatives = fn
                      matrix.true_negatives = tn
                      matrix.false_positives = fp
                      matrix.true_positives = tp
                      accumulator[threshold][matrix_key] = matrix
      return accumulator
  
file_path: model-analysis/tensorflow_model_analysis/metrics/multi_label_confusion_matrix_plot.py
imports: from typing import Dict, Iterable, List, Optional, NamedTuple
  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
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
label_desc: Use image node_id 3 for calling the _MultiLabelConfusionMatrixPlotCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: accumulator