code: def rolling_validation_time_series(
      model, df, preds, target, train_size=0, test_size=0, verbose=0
  ):
      """
      This utility uses a Walk Forward or Rolling Period time series cross validation method.
      Initially it will start with a minimum number of observations to train the model.
      It then gradually increases the train size in steps (which it will calculate automatically)
      while fixing the number of test rows the same (though their content will vary).
      Once the train+test series exceeds the number of rows in data set, it stops.
      It does  not use SKLearn's Time Series Split. You need to provide the initial sizes
      of train and test and it will take care of the rest.
      """
      df = df[:]
      index = 0
      X = df[preds].values
      y = df[target].values
      non_df = {}
      # rmse_list = []  # # TODO: Unused (check)
      if train_size == 0:
          train_size = np.int(np.ceil(len(y) / 2))
      if test_size == 0:
          test_size = np.int(np.ceil(len(y) / 4))
      # step_size = np.int(np.ceil(test_size/10))  # TODO: Unused (check)
      n_records = len(X)
      ### This contains the start point of test size for each K-Fold in time series
      test_list = np.floor(
          np.linspace(train_size, n_records - 1, 5)
      ).tolist()
      for i in range(4):
          train_size = np.int(test_list[i])
          test_size = np.int(test_list[i + 1] - test_list[i])
          X_train, X_test = (
              X[:train_size],
              X[train_size : train_size + test_size],
          )
          y_train, y_test = (
              y[:train_size],
              y[train_size : train_size + test_size],
          )
          model.fit(X_train, y_train)
          if i == 0:
              ### Since both start and end points are included, you have to subtract 1 from index in this
              df.loc[: train_size - 1, "predictions"] = y[:train_size]
              df.loc[
                  train_size : train_size + test_size - 1, "predictions"
              ] = model.predict(X_test)
          elif i == 3:
              test_size = np.int(len(X) - train_size)
              X_train, X_test = (
                  X[:train_size],
                  X[train_size : train_size + test_size],
              )
              y_train, y_test = (
                  y[:train_size],
                  y[train_size : train_size + test_size],
              )
              df.loc[
                  train_size : train_size + test_size, "predictions"
              ] = model.predict(X_test)
          else:
              df.loc[
                  train_size : train_size + test_size - 1, "predictions"
              ] = model.predict(X_test)
          if len(y_train) + len(y_test) >= df.shape[0]:
              if verbose:
                  print(
                      "Iteration %d: Observations:%d"
                      % (index + 1, len(X_train) + len(X_test))
                  )
                  print(
                      "    Train Size=%d, Test Size=%d"
                      % (len(y_train), len(y_test))
                  )
              # TODO:
              rmse = print_rmse(y_test, model.predict(X_test))
              norm_rmse = rmse / y_test.std()
              non_df[i] = rmse
              if verbose:
                  print("Normalized RMSE = %0.2f" % norm_rmse)
              non_df = pd.Series(non_df)
              weighted_ave_rmse = np.average(
                  non_df.values, weights=non_df.index, axis=0
              )
              print(
                  "\nWeighted Average of RMSE (%d iterations) = %0.2f\n    Normalized Wtd Aver. RMSE (using std dev) = %0.2f"
                  % (
                      index + 1,
                      weighted_ave_rmse,
                      weighted_ave_rmse / y[:].std(),
                  )
              )
              #############################
              if verbose == 1 or verbose == 2:
                  fig, ax1 = plt.subplots(
                      nrows=1, ncols=1, figsize=(12, 8)
                  )
                  ax1.plot(
                      df[target], label="In-Sample Data", linestyle="-"
                  )
                  ax1.plot(
                      df["predictions"],
                      "g",
                      alpha=0.6,
                      label="Rolling Forecast",
                  )
                  ax1.set_xlabel("Time")
                  ax1.set_ylabel("Values")
                  ax1.legend(loc="best")
              return (
                  weighted_ave_rmse,
                  weighted_ave_rmse / y[:].std(),
                  df,
              )
          else:
              if verbose:
                  print(
                      "Iteration %d: Observations:%d"
                      % (index + 1, len(X_train) + len(X_test))
                  )
                  print(
                      "    Train Size=%d, Test Size=%d"
                      % (len(y_train), len(y_test))
                  )
              # TODO: Check print_rmse is not defined or loaded
              rmse = print_rmse(y_test, model.predict(X_test))
              norm_rmse = rmse / y_test.std()
              non_df[i] = rmse
              if verbose:
                  print("Normalized RMSE = %0.2f" % norm_rmse)
              index += 1
  
file_path: Auto_TS/auto_ts/utils/val.py
imports: import numpy
  import pandas
  import matplotlib.pyplot
  import seaborn
  from sklearn.model_selection import TimeSeriesSplit
  from sklearn.model_selection import GridSearchCV
  import pdb
label_desc: Use image node_id 2 for calling a global function with example usage: rolling_validation_time_series(model, df, preds, target, train_size, test_size, verbose) and returns: weighted_ave_rmse,  unknown,  df