code: def test_classification_invariance_string_vs_numbers_labels(name):
      # Ensure that classification metrics with string labels are invariant
      random_state = check_random_state(0)
      y1 = random_state.randint(0, 2, size=(20,))
      y2 = random_state.randint(0, 2, size=(20,))
  
      y1_str = np.array(["eggs", "spam"])[y1]
      y2_str = np.array(["eggs", "spam"])[y2]
  
      pos_label_str = "spam"
      labels_str = ["eggs", "spam"]
  
      with ignore_warnings():
          metric = CLASSIFICATION_METRICS[name]
          measure_with_number = metric(y1, y2)
  
          # Ugly, but handle case with a pos_label and label
          metric_str = metric
          if name in METRICS_WITH_POS_LABEL:
              metric_str = partial(metric_str, pos_label=pos_label_str)
  
          measure_with_str = metric_str(y1_str, y2_str)
  
          assert_array_equal(
              measure_with_number,
              measure_with_str,
              err_msg="{0} failed string vs number invariance test".format(
                  name
              ),
          )
  
          measure_with_strobj = metric_str(
              y1_str.astype("O"), y2_str.astype("O")
          )
          assert_array_equal(
              measure_with_number,
              measure_with_strobj,
              err_msg="{0} failed string object vs number invariance test".format(
                  name
              ),
          )
  
          if name in METRICS_WITH_LABELS:
              metric_str = partial(metric_str, labels=labels_str)
              measure_with_str = metric_str(y1_str, y2_str)
              assert_array_equal(
                  measure_with_number,
                  measure_with_str,
                  err_msg="{0} failed string vs number  invariance test".format(
                      name
                  ),
              )
  
              measure_with_strobj = metric_str(
                  y1_str.astype("O"), y2_str.astype("O")
              )
              assert_array_equal(
                  measure_with_number,
                  measure_with_strobj,
                  err_msg="{0} failed string vs number  invariance test".format(
                      name
                  ),
              )
  
imports: from functools import partial
  from inspect import signature
  from itertools import chain, permutations, product
  import numpy
  import pytest
  from sklearn._config import config_context
  from sklearn.datasets import make_multilabel_classification
  from sklearn.metrics import accuracy_score, average_precision_score, balanced_accuracy_score, brier_score_loss, cohen_kappa_score, confusion_matrix, coverage_error, d2_absolute_error_score, d2_pinball_score, d2_tweedie_score, dcg_score, det_curve, explained_variance_score, f1_score, fbeta_score, hamming_loss, hinge_loss, jaccard_score, label_ranking_average_precision_score, label_ranking_loss, log_loss, matthews_corrcoef, max_error, mean_absolute_error, mean_absolute_percentage_error, mean_gamma_deviance, mean_pinball_loss, mean_poisson_deviance, mean_squared_error, mean_tweedie_deviance, median_absolute_error, multilabel_confusion_matrix, ndcg_score, precision_recall_curve, precision_score, r2_score, recall_score, roc_auc_score, roc_curve, top_k_accuracy_score, zero_one_loss
  from sklearn.metrics._base import _average_binary_score
  from sklearn.preprocessing import LabelBinarizer
  from sklearn.utils import shuffle
  from sklearn.utils._array_api import _atol_for_type, yield_namespace_device_dtype_combinations
  from sklearn.utils._testing import _array_api_for_tests, assert_allclose, assert_almost_equal, assert_array_equal, assert_array_less, ignore_warnings
  from sklearn.utils.fixes import COO_CONTAINERS
  from sklearn.utils.multiclass import type_of_target
  from sklearn.utils.validation import _num_samples, check_random_state
label_desc: Use image node_id 9 for calling a global function with example usage: test_classification_invariance_string_vs_numbers_labels(name) without return types