class_docstr: Flexible splitter for time-series cross validation and rolling window evaluation.
  Suitable for use in GridSearchCV.
  
  Attributes
  ----------
  min_splits : int
      Guaranteed min number of splits. This is always set to 1. If provided configuration results in 0 splits,
      the cross validator will yield a default split.
  
  __starting_test_index : int
      Test end index of the first CV split. Actual offset = __starting_test_index + _get_offset(X), for a particular
      dataset X.
      Cross validator ensures the last test split contains the last observation in X.
  
  Examples
  --------
  >>> from greykite.sklearn.cross_validation import RollingTimeSeriesSplit
  >>> X = np.random.rand(20, 4)
  >>> tscv = RollingTimeSeriesSplit(forecast_horizon=3, max_splits=4)
  >>> tscv.get_n_splits(X=X)
  4
  >>> for train, test in tscv.split(X=X):
  ...     print(train, test)
  [2 3 4 5 6 7] [ 8  9 10]
  [ 5  6  7  8  9 10] [11 12 13]
  [ 8  9 10 11 12 13] [14 15 16]
  [11 12 13 14 15 16] [17 18 19]
  >>> X = np.random.rand(20, 4)
  >>> tscv = RollingTimeSeriesSplit(forecast_horizon=2,
  ...                               min_train_periods=4,
  ...                               expanding_window=True,
  ...                               periods_between_splits=4,
  ...                               periods_between_train_test=2,
  ...                               max_splits=None)
  >>> tscv.get_n_splits(X=X)
  4
  >>> for train, test in tscv.split(X=X):
  ...     print(train, test)
  [0 1 2 3] [6 7]
  [0 1 2 3 4 5 6 7] [10 11]
  [ 0  1  2  3  4  5  6  7  8  9 10 11] [14 15]
  [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15] [18 19]
  >>> X = np.random.rand(5, 4)  # default split if there is not enough data
  >>> for train, test in tscv.split(X=X):
  ...     print(train, test)
  [0 1 2 3] [4]
class_docstr_tok: ["Flexible","splitter","for","time-series","cross","validation","and","rolling","window","evaluation",".","Suitable","for","use","in","GridSearchCV",".","Attributes","--","--","--","--","--","min_splits",":","int","Guaranteed","min","number","of","splits",".","This","is","always","set","to","1",".","If","provided","configuration","results","in","0","splits",",","the","cross","validator","will","yield","a","default","split",".","__starting_test_index",":","int","Test","end","index","of","the","first","CV","split",".","Actual","offset","=","__starting_test_index","+","_get_offset","(","X",")",",","for","a","particular","dataset","X",".","Cross","validator","ensures","the","last","test","split","contains","the","last","observation","in","X",".","Examples","--","--","--","--",">",">",">","from","greykite.sklearn.cross_validation","import","RollingTimeSeriesSplit",">",">",">","X","=","np.random.rand","(","20",",","4",")",">",">",">","tscv","=","RollingTimeSeriesSplit","(","forecast_horizon=3",",","max_splits=4",")",">",">",">","tscv.get_n_splits","(","X=X",")","4",">",">",">","for","train",",","test","in","tscv.split","(","X=X",")",":","...","print","(","train",",","test",")","[","2","3","4","5","6","7","]","[","8","9","10","]","[","5","6","7","8","9","10","]","[","11","12","13","]","[","8","9","10","11","12","13","]","[","14","15","16","]","[","11","12","13","14","15","16","]","[","17","18","19","]",">",">",">","X","=","np.random.rand","(","20",",","4",")",">",">",">","tscv","=","RollingTimeSeriesSplit","(","forecast_horizon=2",",","...","min_train_periods=4",",","...","expanding_window=True",",","...","periods_between_splits=4",",","...","periods_between_train_test=2",",","...","max_splits=None",")",">",">",">","tscv.get_n_splits","(","X=X",")","4",">",">",">","for","train",",","test","in","tscv.split","(","X=X",")",":","...","print","(","train",",","test",")","[","0","1","2","3","]","[","6","7","]","[","0","1","2","3","4","5","6","7","]","[","10","11","]","[","0","1","2","3","4","5","6","7","8","9","10","11","]","[","14","15","]","[","0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","]","[","18","19","]",">",">",">","X","=","np.random.rand","(","5",",","4",")","#","default","split","if","there","is","not","enough","data",">",">",">","for","train",",","test","in","tscv.split","(","X=X",")",":","...","print","(","train",",","test",")","[","0","1","2","3","]","[","4","]"]
docstr: Generates indices to split data into training and test CV folds according to rolling
    window time series cross validation
  
  Parameters
  ----------
  X : array-like, shape (n_samples, n_features)
      Training data, where n_samples is the number of samples
      and n_features is the number of features.
      Must have `shape` method.
  
  y : array-like, shape (n_samples,), optional
      The target variable for supervised learning problems. Always ignored, exists for compatibility.
  
  groups : array-like, with shape (n_samples,), optional
      Group labels for the samples used while splitting the dataset into
      train/test set. Always ignored, exists for compatibility.
  
  Yields
  ------
  train : `numpy.array`
      The training set indices for that split.
  
  test : `numpy.array`
      The testing set indices for that split.
docstr_tok: ["Generates","indices","to","split","data","into","training","and","test","CV","folds","according","to","rolling","window","time","series","cross","validation","Parameters","--","--","--","--","--","X",":","array-like",",","shape","(","n_samples",",","n_features",")","Training","data",",","where","n_samples","is","the","number","of","samples","and","n_features","is","the","number","of","features",".","Must","have","`","shape","`","method",".","y",":","array-like",",","shape","(","n_samples",",",")",",","optional","The","target","variable","for","supervised","learning","problems",".","Always","ignored",",","exists","for","compatibility",".","groups",":","array-like",",","with","shape","(","n_samples",",",")",",","optional","Group","labels","for","the","samples","used","while","splitting","the","dataset","into","train\/test","set",".","Always","ignored",",","exists","for","compatibility",".","Yields","--","--","--","train",":","`","numpy.array","`","The","training","set","indices","for","that","split",".","test",":","`","numpy.array","`","The","testing","set","indices","for","that","split","."]
code: def split(self, X, y=None, groups=None):
      """Generates indices to split data into training and test CV folds according to rolling
        window time series cross validation
  
      Parameters
      ----------
      X : array-like, shape (n_samples, n_features)
          Training data, where n_samples is the number of samples
          and n_features is the number of features.
          Must have `shape` method.
  
      y : array-like, shape (n_samples,), optional
          The target variable for supervised learning problems. Always ignored, exists for compatibility.
  
      groups : array-like, with shape (n_samples,), optional
          Group labels for the samples used while splitting the dataset into
          train/test set. Always ignored, exists for compatibility.
  
      Yields
      ------
      train : `numpy.array`
          The training set indices for that split.
  
      test : `numpy.array`
          The testing set indices for that split.
      """
      num_samples = X.shape[0]
      indices = np.arange(num_samples)
  
      n_splits_without_capping = self.get_n_splits_without_capping(X=X)
      n_splits = self.get_n_splits(X=X)
      if n_splits_without_capping == 0:
          warnings.warn(
              "There are no CV splits under the requested settings. Decrease `forecast_horizon` and/or"
              " `min_train_periods`. Using default 90/10 CV split"
          )
      elif n_splits == 1:
          warnings.warn("There is only one CV split")
      elif n_splits >= 10:
          warnings.warn(
              f"There is a high number of CV splits ({n_splits}). If training is slow, increase "
              f"`periods_between_splits` or `min_train_periods`, or decrease `max_splits`"
          )
  
      log_message(
          f"There are {n_splits} CV splits.", LoggingLevelEnum.INFO
      )
  
      if n_splits_without_capping == 0:  # uses default split
          default_split_ratio = 0.9
          train_samples = int(round(num_samples * default_split_ratio))
          yield indices[:train_samples], indices[train_samples:]
      else:  # determines which splits to keep so that up to max_splits are returned
          splits_to_keep = self._sample_splits(n_splits_without_capping)
  
          last_index = num_samples - 1
          test_end_index = (
              self.__starting_test_index + self._get_offset(X=X)
          )
          current_split_index = 0
          while test_end_index <= last_index:
              test_start_index = (
                  test_end_index - self.forecast_horizon + 1
              )
              train_end_index = (
                  test_start_index - self.periods_between_train_test - 1
              )
              train_start_index = (
                  0
                  if self.expanding_window
                  else train_end_index - self.min_train_periods + 1
              )
              assert (
                  train_start_index >= 0
              )  # guaranteed by n_splits > 0
  
              if current_split_index in splits_to_keep:
                  log_message(
                      f"CV split: Train {train_start_index} to {train_end_index}. "
                      f"Test {test_start_index} to {test_end_index}.",
                      LoggingLevelEnum.DEBUG,
                  )
                  yield indices[
                      train_start_index : train_end_index + 1
                  ], indices[test_start_index : test_end_index + 1]
  
              test_end_index += self.periods_between_splits
              current_split_index += 1
  
file_path: greykite/greykite/sklearn/cross_validation.py
imports: import math
  import random
  import warnings
  import numpy
  from sklearn.model_selection import BaseCrossValidator
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import get_integer
label_desc: Use image node_id 2 for calling the RollingTimeSeriesSplit obj's underlying member method code with example usage: obj.split(X, y, groups) without return types