code: def create_predict_spearman_rank_with_cv(
      cv_metafeatures, cv_experiments, iterator
  ):
      X = []
      Y = []
      Y_names = []
      # Calculate the pairwise ranks between datasets
      dataset_names = [name for name in cv_metafeatures]
      cross_product = []
      folds_product = []
  
      if iterator == "combination":
          for cross in itertools.combinations_with_replacement(
              dataset_names, r=2
          ):
              cross_product.append(cross)
          for folds in itertools.combinations_with_replacement(
              range(10), r=2
          ):
              folds_product.append(folds)
      elif iterator == "permutation":
          for cross in itertools.permutations(dataset_names, r=2):
              cross_product.append(cross)
          for folds in itertools.permutations(range(10), r=2):
              folds_product.append(folds)
      else:
          raise NotImplementedError()
  
      logging.info(
          "Create spearman rank dataset with CV data %s", iterator
      )
      logging.info("Using %d datasets", len(dataset_names))
      logging.info(
          "This will results in %d training points",
          len(cross_product) * len(folds_product),
      )
      logging.info(
          "Length of dataset crossproduct %s", len(cross_product)
      )
      logging.info(
          "Length of folds crossproduct %s", len(folds_product)
      )
  
      # Create inputs and targets
      for i, cross in enumerate(cross_product):
          print(
              "%d/%d: %s" % (i, len(cross_product), cross),
          )
          for folds in folds_product:
              name = "%s-%d_%s-%d" % (
                  cross[0],
                  folds[0],
                  cross[1],
                  folds[1],
              )
              mf_1 = cv_metafeatures[cross[0]][folds[0]]
              mf_2 = cv_metafeatures[cross[1]][folds[1]]
              assert mf_1.dtype == np.float64
              assert mf_2.dtype == np.float64
              x = np.hstack((mf_1, mf_2))
              columns = cv_metafeatures[cross[0]][folds[0]].index.values
              index = np.hstack(("0_" + columns, "1_" + columns))
              x = pd.Series(data=x, name=name, index=index)
              X.append(x)
  
              experiments_1 = cv_experiments[cross[0]][folds[0]]
              experiments_2 = cv_experiments[cross[1]][folds[1]]
              assert len(experiments_1) == len(experiments_2)
  
              responses_1 = np.zeros(
                  (len(experiments_1)), dtype=np.float64
              )
              responses_2 = np.zeros(
                  (len(experiments_1)), dtype=np.float64
              )
              for idx, zipped in enumerate(
                  zip(experiments_1, experiments_2)
              ):
                  # Test if the order of the params is the same
                  exp_1, exp_2 = zipped
                  assert exp_1.params == exp_2.params
                  responses_1[idx] = exp_1.result
                  responses_2[idx] = exp_2.result
  
              rho, p = scipy.stats.spearmanr(responses_1, responses_2)
              # A nan is produced if all values of one of the response lists
              # are equal. This results in a division by zero. Because there is
              #  no correlation if all values are the same, rho is replaced by
              # zero...
              # It would probably be better to assign random ranks for equal
              # values, but scipy doesn't support this...
              if not np.isfinite(rho):
                  rho = 0
              Y.append(rho)
              Y_names.append(name)
  
      X = pd.DataFrame(X)
      Y = pd.Series(Y, index=Y_names)
      logging.info("CV_Metafeatures %s", cv_metafeatures.shape)
      logging.info("X.shape %s", X.shape)
      logging.info("Y.shape %s", Y.shape)
      # train sklearn regressor (tree) with 10fold CV
      indices = range(len(X))
      np_rs = np.random.RandomState(42)
      np_rs.shuffle(indices)
      X = X.iloc[indices]
      Y = Y.iloc[indices]
      return X, Y
  
file_path: auto-sklearn/autosklearn/metalearning/metalearning/create_datasets.py
imports: import itertools
  import logging
  import numpy
  import pandas
  import scipy.stats
label_desc: Use image node_id 3 for calling a global function with example usage: create_predict_spearman_rank_with_cv(cv_metafeatures, cv_experiments, iterator) and returns: X,  Y