code: def _indicator_confusion_matrix(
      y_true: _NumbersT,
      y_pred: _NumbersT,
      *,
      pos_label: str | int | bytes = 1,
      multiclass: bool = False,
      average: AverageType = AverageType.MICRO,
  ) -> _ConfusionMatrix:
      """Calculates confusion matix.
  
      Args:
        y_true: ground truth classification labels. This has to be encoded in one of
          the `input_type`.
        y_pred: classification preditions. This has to be encoded in one of the
          `input_type`.
        pos_label: label to be recognized as positive class, only relevant when
          input type is "binary".
        multiclass: If True, input is encoded as 2D array-like of "multi-hot"
          encoding in a shape of Batch X NumClass.
        average: average type of the confusion matrix.
  
      Returns:
        Confusion matrix.
      """
      if average in (AverageType.MICRO, AverageType.BINARY):
          axis = None
      elif average is None or average == AverageType.MACRO:
          axis = 0
      elif average == AverageType.SAMPLES:
          axis = 1
      else:
          raise NotImplementedError(
              f'"{average}" average is not supported.'
          )
  
      y_true, y_pred = np.asarray(y_true), np.asarray(y_pred)
      if multiclass and (y_true.ndim < 2 or y_pred.ndim < 2):
          raise ValueError(
              "Multiclass indicator input needs to be 2D array, actual dimensions:"
              f" y_true: {y_true.ndim}; y_pred: {y_pred.ndim}"
          )
  
      true = y_true == pos_label
      positive = y_pred == pos_label
      # Forces the input to binary if average type is binary.
      if multiclass and average == AverageType.BINARY:
          if true.shape[1] > 2:
              raise ValueError(
                  "Non-binary multiclass indicator input is not supported for `binary`"
                  f" average. #classes is {true.shape[1]}"
              )
          true = true[:, 0]
          positive = positive[:, 0]
      # Reshapes to a multi-class format to Batch X Classes
      elif not multiclass and average != AverageType.BINARY:
          true = np.vstack((true, ~true)).T
          positive = np.vstack((positive, ~positive)).T
      negative = ~positive
      tp = positive & true
      fn = negative & true
  
      positive_cnt = positive.sum(axis=axis)
      tp_cnt = tp.sum(axis=axis)
      fp_cnt = positive_cnt - tp_cnt
      fn_cnt = fn.sum(axis=axis)
      negative_cnt = negative.sum(axis=axis)
      tn_cnt = negative_cnt - fn_cnt
      return _ConfusionMatrix(tp_cnt, tn_cnt, fp_cnt, fn_cnt)
  
imports: from collections.abc import Iterable, Sequence
  import dataclasses
  import enum
  import itertools
  from typing import Any
  import numpy
  from numpy import typing
  from tensorflow_model_analysis.experimental.lazytf import api
label_desc: Use image node_id 6 for calling a global function with example usage: _indicator_confusion_matrix(y_true, y_pred) and returns: _ConfusionMatrix