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: Samples up to ``max_splits`` items from list(range(`num_splits`)).
  
  If ``use_most_recent_splits`` is True, highest split indices up to ``max_splits``
  are retained. Otherwise, the following sampling scheme is implemented:
  
      - takes the last 2 splits
      - samples from the rest uniformly at random
  
  Parameters
  ----------
  num_splits : `int`
      Number of splits before sampling.
  
  seed : `int`
      Seed for random sampling.
  
  Returns
  -------
  n_splits : `list`
      Indices of splits to keep (subset of `list(range(num_splits))`).
docstr_tok: ["Samples","up","to","``","max_splits","``","items","from","list","(","range","(","`","num_splits","`",")",")",".","If","``","use_most_recent_splits","``","is","True",",","highest","split","indices","up","to","``","max_splits","``","are","retained",".","Otherwise",",","the","following","sampling","scheme","is","implemented",":","-","takes","the","last","2","splits","-","samples","from","the","rest","uniformly","at","random","Parameters","--","--","--","--","--","num_splits",":","`","int","`","Number","of","splits","before","sampling",".","seed",":","`","int","`","Seed","for","random","sampling",".","Returns","--","--","--","-","n_splits",":","`","list","`","Indices","of","splits","to","keep","(","subset","of","`","list","(","range","(","num_splits",")",")","`",")","."]
code: def _sample_splits(self, num_splits, seed=48912):
      """Samples up to ``max_splits`` items from list(range(`num_splits`)).
  
      If ``use_most_recent_splits`` is True, highest split indices up to ``max_splits``
      are retained. Otherwise, the following sampling scheme is implemented:
  
          - takes the last 2 splits
          - samples from the rest uniformly at random
  
      Parameters
      ----------
      num_splits : `int`
          Number of splits before sampling.
  
      seed : `int`
          Seed for random sampling.
  
      Returns
      -------
      n_splits : `list`
          Indices of splits to keep (subset of `list(range(num_splits))`).
      """
      split_indices = list(range(num_splits))
      if self.max_splits is not None and num_splits > self.max_splits:
          if self.use_most_recent_splits:
              # keep indices from the end up to max_splits
              keep_split_indices = split_indices[-self.max_splits :]
          else:
              # applies sampling scheme to take up to max_splits
              keep_split_indices = []
              if self.max_splits > 0:  # first takes the last split
                  keep_split_indices.append(split_indices[-1])
              if (
                  self.max_splits > 1
              ):  # then takes the second to last split
                  keep_split_indices.append(split_indices[-2])
              if (
                  self.max_splits > 2
              ):  # then randomly samples the remaining splits
                  random.seed(seed)
                  keep_split_indices += random.sample(
                      split_indices[:-2], self.max_splits - 2
                  )
          split_indices = keep_split_indices
      return split_indices
  
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 6 for calling the RollingTimeSeriesSplit obj's underlying member method code with example usage: obj._sample_splits(num_splits, seed) and returns: split_indices