code: def gain_chart(df, col_true=None, col_pred=None, col_scores=None, pos_label=1):
      r
      if not col_pred:
          col_pred = get_field_name_by_role(df, FieldRole.PREDICTED_CLASS)
      if not col_scores:
          col_scores = get_field_name_by_role(df, FieldRole.PREDICTED_SCORE)
      thresh, tp, fn, tn, fp = _run_roc_node(df, pos_label, col_true, col_pred, col_scores)
  
      depth = (tp + fp) * 1.0 / (tp + fp + tn + fn)
      tpr = tp * 1.0 / (tp + fn)
  
      gain_result = namedtuple('GainChartResult', 'depth tpr thresh')
      return gain_result(depth=depth, tpr=tpr, thresh=thresh)
docs: r"""
      Compute positive proportion, true positive rate (TPR) and threshold from predicted DataFrame. The trace can be plotted as a cumulative gain chart
  
      Note that this method will trigger the defined flow to execute.
  
      :param df: predicted data frame
      :type df: DataFrame
      :param pos_label: positive label
      :type pos_label: str
      :param col_true: true column
      :type col_true: str
      :param col_pred: predicted column, 'prediction_result' if absent.
      :type col_pred: str
      :param col_scores: score column, 'prediction_score' if absent.
      :type col_scores: str
  
      :return: positive proportion, true positive rate and threshold, in numpy array format.
  
      :Example:
  
      >>> import matplotlib.pyplot as plt
      >>> depth, tpr, thresh = gain_chart(predicted)
      >>> plt.plot(depth, tpr)