def get_k_fold_splits(cv):
 for (k, (train, test)) in enumerate(cv):
  valid_k = (k + 1)
  if (valid_k == len(cv)):
   valid_k = 0
  valid = cv[valid_k][1]
  train = np.setdiff1d(train, valid)
  (yield (train, valid, test))

def get_k_fold_splits ( cv ) : for ( k , ( train , test ) ) in enumerate ( cv ) : valid_k = ( k + 1 ) if ( valid_k == len ( cv ) ) : valid_k = 0 valid = cv [ valid_k ] [ 1 ] train = np . setdiff1d ( train , valid ) ( yield ( train , valid , test ) )
use the test set from the next fold as the validation set for this fold .