code: def split_KFold_idx(train, cv_n_folds=5, stratified=False, random_state=None):
      
      test_len(train)
      y = train[1]
      n_rows = y.shape[0]
      if stratified:
          if len(y.shape) > 1:
              if y.shape[1] > 1:
                  raise ValueError("Can't use stratified K-fold with multi-column response variable")
              else:
                  y = y[:, 0]
              # http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedKFold.html#sklearn.model_selection.StratifiedKFold.split
          return model_selection.StratifiedKFold(n_splits=cv_n_folds, shuffle=True, random_state=random_state)\
              .split(X=np.zeros((n_rows, 1)), y=y)
      else:
          return model_selection.KFold(n_splits=cv_n_folds, shuffle=True, random_state=random_state)\
              .split(X=np.zeros((n_rows, 1)))
docs: Get k-fold indices generator