code: def k_fold_cross_validation_sets(X, y, k, shuffle=True):
      """Split the data into k sets of training / test data"""
      if shuffle:
          X, y = shuffle_data(X, y)
  
      n_samples = len(y)
      left_overs = {}
      n_left_overs = n_samples % k
      if n_left_overs != 0:
          left_overs["X"] = X[-n_left_overs:]
          left_overs["y"] = y[-n_left_overs:]
          X = X[:-n_left_overs]
          y = y[:-n_left_overs]
  
      X_split = np.split(X, k)
      y_split = np.split(y, k)
      sets = []
      for i in range(k):
          X_test, y_test = X_split[i], y_split[i]
          X_train = np.concatenate(
              X_split[:i] + X_split[i + 1 :], axis=0
          )
          y_train = np.concatenate(
              y_split[:i] + y_split[i + 1 :], axis=0
          )
          sets.append([X_train, X_test, y_train, y_test])
  
      # Add left over samples to last set as training samples
      if n_left_overs != 0:
          np.append(sets[-1][0], left_overs["X"], axis=0)
          np.append(sets[-1][2], left_overs["y"], axis=0)
  
      return np.array(sets)
  
file_path: ML-From-Scratch/mlfromscratch/utils/data_manipulation.py
imports: from __future__ import division
  from itertools import combinations_with_replacement
  import numpy
  import math
  import sys
label_desc: Use image node_id 9 for calling a global function with example usage: k_fold_cross_validation_sets(X, y, k, shuffle) and returns: np