code: def _curve(
      target,
      predicted,
      curve_type="roc",
      df=pd.DataFrame(),
      cross_cols=[],
      categorical_cols=[],
      bins=6,
      plot=True,
  ):
      if curve_type == "roc":
          curve_func = roc_curve
          y_label = "False Positive Rate"
          x_label = "True Positive Rate"
          p1 = [0, 1]
          p2 = [0, 1]
          y_lim = [0, 1.05]
          legend_loc = "lower right"
      elif curve_type == "pr":
          curve_func = precision_recall_curve
          y_label = "Recall"
          x_label = "Precision"
          p1 = [1, 0]
          p2 = [0.5, 0.5]
          y_lim = [0.25, 1.05]
          legend_loc = "lower left"
      else:
          raise ValueError(
              "Curve function provided not valid. "
              f" curve_func provided: {curve_func}"
          )
  
      grouped = _group_metrics(
          target, predicted, df, cross_cols, categorical_cols, bins
      )
  
      if plot:
          plt.figure()
  
      r1s = r2s = []
  
      for group, group_df in grouped:
          group_valid = group_df["target"]
          group_pred = group_df["predicted"]
  
          r1, r2, _ = curve_func(group_valid, group_pred)
          r1s.append(r1)
          r2s.append(r2)
  
          if plot:
              if curve_type == "pr":
                  r1, r2 = r2, r1
              plt.plot(r1, r2, label=group)
              plt.plot(p1, p2, "k--")
  
      if plot:
          plt.xlim([0.0, 1.0])
          plt.ylim(y_lim)
          plt.xlabel(x_label)
          plt.ylabel(y_label)
          plt.legend(loc=legend_loc)
          plt.show()
  
      return r1s, r2s
  
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 16 for calling a global function with example usage: _curve(target, predicted, curve_type, df, cross_cols, categorical_cols, bins, plot) and returns: r1s,  r2s