code: def _group_metrics(
      target,
      predicted,
      df,
      cross_cols,
      categorical_cols,
      bins,
      target_threshold=None,
  ):
      if not all(c in df.columns for c in cross_cols):
          raise KeyError(
              "Cross columns don't match columns in dataframe provided."
          )
  
      df_tmp = df.copy()
      df_tmp["target"] = target
      df_tmp["predicted"] = predicted
  
      # Convert predictions into classes
      if target_threshold and df_tmp["predicted"].dtype.kind == "f":
          df_tmp["predicted"] = convert_probs(
              df_tmp["predicted"], threshold=target_threshold
          )
  
      if not categorical_cols and cross_cols:
          categorical_cols = _infer_categorical(df_tmp)
  
      if not cross_cols:
          grouped = [
              ("target", df_tmp),
          ]
      else:
          grouped = group_by_columns(
              df_tmp,
              cross_cols,
              bins=bins,
              categorical_cols=categorical_cols,
          )
  
      return grouped
  
imports: import pandas
  import matplotlib.pyplot
  import numpy
  from scipy.stats import spearmanr
  from scipy.cluster import hierarchy
  from typing import List, Any, Union, Tuple, Optional, Dict
  import random, math
  from sklearn.metrics import roc_curve, precision_recall_curve, roc_auc_score, confusion_matrix
  import itertools
  import logging
label_desc: Use image node_id 18 for calling a global function with example usage: _group_metrics(target, predicted, df, cross_cols, categorical_cols, bins, target_threshold) and returns: grouped