code: def num_label_issues(
      labels: LabelLike,
      pred_probs: np.ndarray,
      *,
      confident_joint: Optional[np.ndarray] = None,
      estimation_method: str = "off_diagonal",
      multi_label: bool = False,
  ) -> int:
      """Estimates the number of label issues in a classification dataset. Use this method to get the most accurate
      estimate of number of label issues when you don't need the indices of the examples with label issues.
  
      Parameters
      ----------
      labels : np.ndarray or list
        Given class labels for each example in the dataset, some of which may be erroneous,
        in same format expected by :py:func:`filter.find_label_issues <cleanlab.filter.find_label_issues>` function.
  
      pred_probs :
        Model-predicted class probabilities for each example in the dataset,
        in same format expected by :py:func:`filter.find_label_issues <cleanlab.filter.find_label_issues>` function.
  
      confident_joint :
        Array of estimated class label error statisics used for identifying label issues,
        in same format expected by :py:func:`filter.find_label_issues <cleanlab.filter.find_label_issues>` function.
        The `confident_joint` can be computed using `~cleanlab.count.compute_confident_joint`.
        It is internally computed from the given (noisy) `labels` and `pred_probs`.
  
      estimation_method :
        Method for estimating the number of label issues in dataset by counting the examples in the off-diagonal of the `confident_joint` ``P(label=i, true_label=j)``.
  
        * ``'off_diagonal'``: Counts the number of examples in the off-diagonal of the `confident_joint`. Returns the same value as ``sum(find_label_issues(filter_by='confident_learning'))``
  
        * ``'off_diagonal_calibrated'``: Calibrates confident joint estimate ``P(label=i, true_label=j)`` such that
          ``np.sum(cj) == len(labels)`` and ``np.sum(cj, axis = 1) == np.bincount(labels)`` before counting the number
          of examples in the off-diagonal. Number will always be equal to or greater than
          ``estimate_issues='off_diagonal'``. You can use this value as the cutoff threshold used with ranking/scoring
          functions from :py:mod:`cleanlab.rank` with `num_label_issues` over ``estimation_method='off_diagonal'`` in
          two cases:
  
          #. As we add more label and data quality scoring functions in :py:mod:`cleanlab.rank`, this approach will always work.
          #. If you have a custom score to rank your data by label quality and you just need to know the cut-off of likely label issues.
  
        * ``'off_diagonal_custom'``: Counts the number of examples in the off-diagonal of a provided `confident_joint` matrix.
  
        TL;DR: Use this method to get the most accurate estimate of number of label issues when you don't need the indices of the label issues.
  
        Note: ``'off_diagonal'`` may sometimes underestimate issues for data with few classes, so consider using ``'off_diagonal_calibrated'`` instead if your data has < 4 classes.
  
      multi_label : bool, optional
        Set ``False`` if your dataset is for regular (multi-class) classification, where each example belongs to exactly one class.
        Set ``True`` if your dataset is for multi-label classification, where each example can belong to multiple classes.
        See documentation of `~cleanlab.count.compute_confident_joint` for details.
  
      Returns
      -------
      num_issues :
        The estimated number of examples with label issues in the dataset.
      """
      valid_methods = [
          "off_diagonal",
          "off_diagonal_calibrated",
          "off_diagonal_custom",
      ]
      if (
          isinstance(confident_joint, np.ndarray)
          and estimation_method != "off_diagonal_custom"
      ):
          warn_str = (
              "The supplied `confident_joint` is ignored as `confident_joint` is recomuputed internally using "
              "the supplied `labels` and `pred_probs`. If you still want to use custom `confident_joint` call function "
              "with `estimation_method='off_diagonal_custom'`."
          )
          warnings.warn(warn_str)
  
      if multi_label:
          return _num_label_issues_multilabel(
              labels=labels,
              pred_probs=pred_probs,
              confident_joint=confident_joint,
          )
      labels = labels_to_array(labels)
      assert_valid_inputs(X=None, y=labels, pred_probs=pred_probs)
  
      if estimation_method == "off_diagonal":
          _, cl_error_indices = compute_confident_joint(
              labels=labels,
              pred_probs=pred_probs,
              calibrate=False,
              return_indices_of_off_diagonals=True,
          )
  
          label_issues_mask = np.zeros(len(labels), dtype=bool)
          label_issues_mask[cl_error_indices] = True
  
          # Remove label issues if model prediction is close to given label
          mask = _reduce_issues(pred_probs=pred_probs, labels=labels)
          label_issues_mask[mask] = False
          num_issues = np.sum(label_issues_mask)
      elif estimation_method == "off_diagonal_calibrated":
          calculated_confident_joint = compute_confident_joint(
              labels=labels,
              pred_probs=pred_probs,
              calibrate=True,
          )
          assert isinstance(calculated_confident_joint, np.ndarray)
          # Estimate_joint calibrates the row sums to match the prior distribution of given labels and normalizes to sum to 1
          joint = estimate_joint(
              labels,
              pred_probs,
              confident_joint=calculated_confident_joint,
          )
          frac_issues = 1.0 - joint.trace()
          num_issues = np.rint(frac_issues * len(labels)).astype(int)
      elif estimation_method == "off_diagonal_custom":
          if not isinstance(confident_joint, np.ndarray):
              raise ValueError(
                  f"""
                  No `confident_joint` provided. For 'estimation_method' = {estimation_method} you need to provide pre-calculated
                  `confident_joint` matrix. Use a different `estimation_method` if you want the `confident_joint` matrix to
                  be calculated for you.
                  """
              )
          else:
              joint = estimate_joint(
                  labels, pred_probs, confident_joint=confident_joint
              )
              frac_issues = 1.0 - joint.trace()
              num_issues = np.rint(frac_issues * len(labels)).astype(
                  int
              )
      else:
          raise ValueError(
              f"""
                  {estimation_method} is not a valid estimation method!
                  Please choose a valid estimation method: {valid_methods}
                  """
          )
  
      return num_issues
  
imports: from sklearn.linear_model import LogisticRegression
  from sklearn.model_selection import StratifiedKFold
  from sklearn.metrics import confusion_matrix
  import sklearn.base
  import numpy
  import warnings
  from typing import Tuple, Union, Optional
  from cleanlab.typing import LabelLike
  from cleanlab.internal.multilabel_utils import stack_complement, get_onehot_num_classes
  from cleanlab.internal.constants import TINY_VALUE, CONFIDENT_THRESHOLDS_LOWER_BOUND, FLOATING_POINT_COMPARISON
  from cleanlab.internal.util import value_counts_fill_missing_classes, clip_values, clip_noise_rates, round_preserving_row_totals, append_extra_datapoint, train_val_split, get_num_classes, get_unique_classes, is_torch_dataset, is_tensorflow_dataset
  from cleanlab.internal.latent_algebra import compute_inv_noise_matrix, compute_py, compute_noise_matrix_from_inverse
  from cleanlab.internal.validation import assert_valid_inputs, labels_to_array
label_desc: Use image node_id 1 for calling a global function with example usage: num_label_issues(labels, pred_probs) and returns: num_issues, _num_label_issues_multilabel