code: def cross_validate_pipeline(
      pipeline, X, y, binary=True, n_folds=N_FOLDS_DEFAULT, **kwargs
  ):
      """
      Compute metrics for each of `n_folds` folds of the training data in (X, y).
  
      pipeline: the sklearn Pipeline to train and test.
      X: feature matrix.
      y: series of labels corresponding to rows in X.
      binary: whether the label is binary or multi-ary.
      n_folds: number of non-overlapping "folds" of the data to make for cross-validation.
      """
      if binary:
          metrics = METRICS_BINARY
      else:
          metrics = METRICS_MULTICLASS
  
      df = pd.DataFrame(columns=metrics)
      results = []
  
      # TODO: how to handle classes that are so uncommon that stratified sampling
      # doesn't work? i.e. len([c for c in y if c == some_class]) < n_folds
      skf = StratifiedKFold(n_splits=n_folds)
      skf.get_n_splits(X, y)
  
      for train_index, test_index in skf.split(X, y):
          pipeline.fit(X[train_index], y[train_index])
          split_results = test_pipeline(
              pipeline=pipeline,
              X=X[test_index],
              y=y[test_index],
              binary=binary,
              **kwargs,
          )
          df = df.append([{m: split_results.get(m) for m in metrics}])
          results.append(split_results)
  
      return df, results
  
file_path: ATM/atm/metrics.py
imports: from __future__ import absolute_import, division, unicode_literals
  from builtins import range
  import numpy
  import pandas
  from sklearn.metrics import accuracy_score, average_precision_score, cohen_kappa_score, f1_score, matthews_corrcoef, precision_recall_curve, roc_auc_score, roc_curve
  from sklearn.model_selection import StratifiedKFold
  from atm.constants import METRICS_BINARY, METRICS_MULTICLASS, N_FOLDS_DEFAULT, Metrics
label_desc: Use image node_id 7 for calling a global function with example usage: cross_validate_pipeline(pipeline, X, y, binary, n_folds) and returns: df,  results