code: def test_num_label_issues():
      cj_calibrated_off_diag_sum = data["cj"].sum() - data["cj"].trace()
  
      n1 = count.num_label_issues(  # should throw warning as cj is passed in but also recalculated
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          confident_joint=data["cj"],
          estimation_method="off_diagonal_calibrated",
      )
  
      n2 = count.num_label_issues(
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          estimation_method="off_diagonal_calibrated",
      )  # this should calculate and calibrate the confident joint into same matrix as data["cj"]
  
      n_custom = count.num_label_issues(
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          confident_joint=data["cj"],
          estimation_method="off_diagonal_custom",
      )
  
      ones_joint = np.ones_like(data["cj"])
      n_custom_bad = count.num_label_issues(
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          confident_joint=ones_joint,
          estimation_method="off_diagonal_custom",
      )
  
      # data["cj"] is already calibrated and recalibrating it should not change the values
      assert n2 == cj_calibrated_off_diag_sum
      # should calculate and calibrate the confident joint into same matrix as data["cj"]
      assert n1 == n2
      # estimation_method='off_diagonal_custom' should use the passed in confident joint correctly
      assert n_custom == n1
      assert n_custom_bad != n1
  
      f = filter.find_label_issues(  # this should throw warning since cj passed in and filter by confident_learning
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          confident_joint=data["cj"],
      )
  
      assert sum(f) == 35
  
      f1 = filter.find_label_issues(  # this should throw warning since cj passed in and filter by confident_learning
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          filter_by="confident_learning",
          confident_joint=data["cj"],
      )
  
      n = count.num_label_issues(  # should throw warning as cj is passed in but also recalculated
          labels=data["labels"],
          pred_probs=data["pred_probs"],
          confident_joint=data["cj"],
          estimation_method="off_diagonal",
      )
  
      n3 = count.num_label_issues(
          labels=data["labels"],
          pred_probs=data["pred_probs"],
      )
  
      assert (
          sum(f1) == n3
      )  # values should be equivalent for `filter_by='confident_learning'`
      assert n == n3  # passing in cj should not affect calculation
  
      # check wrong estimation_method throws ValueError
      try:
          count.num_label_issues(
              labels=data["labels"],
              pred_probs=data["pred_probs"],
              estimation_method="not_a_real_method",
          )
      except Exception as e:
          assert "not a valid estimation method" in str(e)
          with pytest.raises(ValueError) as e:
              count.num_label_issues(
                  labels=data["labels"],
                  pred_probs=data["pred_probs"],
                  estimation_method="not_a_real_method",
              )
  
      # check not passing in cj with estimation_method_custom throws ValueError
      try:
          count.num_label_issues(
              labels=data["labels"],
              pred_probs=data["pred_probs"],
              estimation_method="off_diagonal_custom",
          )
      except Exception as e:
          assert "you need to provide pre-calculated" in str(e)
          with pytest.raises(ValueError) as e:
              count.num_label_issues(
                  labels=data["labels"],
                  pred_probs=data["pred_probs"],
                  estimation_method="off_diagonal_custom",
              )
  
imports: import cleanlab.multilabel_classification.dataset
  from cleanlab import count, filter
  from cleanlab.count import get_confident_thresholds, estimate_py_and_noise_matrices_from_probabilities
  from cleanlab.internal.latent_algebra import compute_inv_noise_matrix
  from cleanlab.benchmarking.noise_generation import generate_noise_matrix_from_trace
  from cleanlab.benchmarking.noise_generation import generate_noisy_labels
  from cleanlab.internal.util import value_counts
  from cleanlab.internal.multilabel_utils import int2onehot
  from cleanlab.experimental.label_issues_batched import find_label_issues_batched
  import numpy
  import scipy
  import pytest
  from sklearn.multioutput import MultiOutputClassifier
  from sklearn.linear_model import LogisticRegression
  from sklearn.model_selection import cross_val_predict
  from tempfile import mkdtemp
  import os.path
label_desc: Use image node_id 29 for calling a global function with example usage: test_num_label_issues() without return types