class_docstr: The lag based estimator, using lagged observations with aggregation functions
  to forecast the future. This estimator includes the common week-over-week estimation method.
  
  The algorithm support specifying the following:
  
      lag_unit : the unit to calculate lagged values. One of the values in
          `~greykite.sklearn.estimator.lag_based_estimator.LagUnitEnum`.
      lags : a list of lags indicating which lagged ``lag_unit`` data are used in prediction.
          For example, [1, 2] indicating using the past two ``lag_unit`` same time data.
      agg_func : the aggregation function used over the lagged observations.
      agg_func_params : extra parameters used for ``agg_func``.
  
  
  When certain lags are not available, extra data will be extrapolated.
  When predicting into the future and future data is not available,
  predicted values will be used.
  
  Parameters
  ----------
  freq : `str` or None, default None
      The data frequency, used to validate lags.
  lag_unit : `str`, default "week"
      The unit to calculate lagged observations.
      Available options are in `~greykite.sklearn.estimator.lag_based_estimator.LagUnitEnum`.
  lags : `list` [`int`] or None, default None
      The lags in ``lag_unit``'s. [1, 2] indicates using the past two ``lag_unit`` same time values.
      If not provided, the default is to use lag 1 observation only.
  agg_func : `str` or callable, default "mean"
      The aggregation functions used over lagged observations.
  agg_func_params : `dict` or None, default None
      Extra parameters used for ``agg_func``.
  uncertainty_dict: `dict` or None, default None
      How to fit the uncertainty model.
      See `~greykite.sklearn.uncertainty.uncertainty_methods.UncertaintyMethodEnum`.
      If not provided but ``coverage`` is given, this falls back to
      `~greykite.sklearn.uncertainty.simple_conditional_residuals_model.SimpleConditionalResidualsModel`.
  past_df : `pandas.DataFrame` or None, default None
      The past data used to append to the training data.
      If not provided the past data needed will be interpolated.
  series_na_fill_func : `callable` or None, default `lambda s: s.bfill().ffill()`
      The function to fill NAs when they exist.
  
  Attributes
  ----------
  df : `pandas.DataFrame` or None
      The fitted and interpolated training data.
  uncertainty_model : any or None
      The trained uncertainty model.
  max_lag_order : `int` or None
      The maximum lag order.
  min_lag_order : `int` or None
      The minimum lag order.
  train_start : `pandas.Timestamp` or None
      The training start timestamp.
  train_end : `pandas.Timestamp` or None
      The training end timestamp.
class_docstr_tok: ["The","lag","based","estimator",",","using","lagged","observations","with","aggregation","functions","to","forecast","the","future",".","This","estimator","includes","the","common","week-over-week","estimation","method",".","The","algorithm","support","specifying","the","following",":","lag_unit",":","the","unit","to","calculate","lagged","values",".","One","of","the","values","in","`","~greykite.sklearn.estimator.lag_based_estimator.LagUnitEnum","`",".","lags",":","a","list","of","lags","indicating","which","lagged","``","lag_unit","``","data","are","used","in","prediction",".","For","example",",","[","1",",","2","]","indicating","using","the","past","two","``","lag_unit","``","same","time","data",".","agg_func",":","the","aggregation","function","used","over","the","lagged","observations",".","agg_func_params",":","extra","parameters","used","for","``","agg_func","``",".","When","certain","lags","are","not","available",",","extra","data","will","be","extrapolated",".","When","predicting","into","the","future","and","future","data","is","not","available",",","predicted","values","will","be","used",".","Parameters","--","--","--","--","--","freq",":","`","str","`","or","None",",","default","None","The","data","frequency",",","used","to","validate","lags",".","lag_unit",":","`","str","`",",","default","``","week","''","The","unit","to","calculate","lagged","observations",".","Available","options","are","in","`","~greykite.sklearn.estimator.lag_based_estimator.LagUnitEnum","`",".","lags",":","`","list","`","[","`","int","`","]","or","None",",","default","None","The","lags","in","``","lag_unit","``","'s",".","[","1",",","2","]","indicates","using","the","past","two","``","lag_unit","``","same","time","values",".","If","not","provided",",","the","default","is","to","use","lag","1","observation","only",".","agg_func",":","`","str","`","or","callable",",","default","``","mean","''","The","aggregation","functions","used","over","lagged","observations",".","agg_func_params",":","`","dict","`","or","None",",","default","None","Extra","parameters","used","for","``","agg_func","``",".","uncertainty_dict",":","`","dict","`","or","None",",","default","None","How","to","fit","the","uncertainty","model",".","See","`","~greykite.sklearn.uncertainty.uncertainty_methods.UncertaintyMethodEnum","`",".","If","not","provided","but","``","coverage","``","is","given",",","this","falls","back","to","`","~greykite.sklearn.uncertainty.simple_conditional_residuals_model.SimpleConditionalResidualsModel","`",".","past_df",":","`","pandas.DataFrame","`","or","None",",","default","None","The","past","data","used","to","append","to","the","training","data",".","If","not","provided","the","past","data","needed","will","be","interpolated",".","series_na_fill_func",":","`","callable","`","or","None",",","default","`","lambda","s",":","s.bfill","(",")",".ffill","(",")","`","The","function","to","fill","NAs","when","they","exist",".","Attributes","--","--","--","--","--","df",":","`","pandas.DataFrame","`","or","None","The","fitted","and","interpolated","training","data",".","uncertainty_model",":","any","or","None","The","trained","uncertainty","model",".","max_lag_order",":","`","int","`","or","None","The","maximum","lag","order",".","min_lag_order",":","`","int","`","or","None","The","minimum","lag","order",".","train_start",":","`","pandas.Timestamp","`","or","None","The","training","start","timestamp",".","train_end",":","`","pandas.Timestamp","`","or","None","The","training","end","timestamp","."]
docstr: Gets the lag based predictions.
  
  Parameters
  ----------
  fut_df : `pandas.DataFrame`
      The input data that contains ``self.time_col_`` as the prediction periods.
  
  Returns
  -------
  predictions: `pandas.DataFrame`
      Forecasted values for the dates in ``fut_df``. Columns:
  
          - ``TIME_COL``: dates
          - ``PREDICTED_COL``: predictions
          - ``PREDICTED_LOWER_COL``: lower bound of predictions, optional
          - ``PREDICTED_UPPER_COL``: upper bound of predictions, optional
  
      ``PREDICTED_LOWER_COL`` and ``PREDICTED_UPPER_COL`` are present
      if ``self.coverage`` is not None.
docstr_tok: ["Gets","the","lag","based","predictions",".","Parameters","--","--","--","--","--","fut_df",":","`","pandas.DataFrame","`","The","input","data","that","contains","``","self.time_col_","``","as","the","prediction","periods",".","Returns","--","--","--","-","predictions",":","`","pandas.DataFrame","`","Forecasted","values","for","the","dates","in","``","fut_df","``",".","Columns",":","-","``","TIME_COL","``",":","dates","-","``","PREDICTED_COL","``",":","predictions","-","``","PREDICTED_LOWER_COL","``",":","lower","bound","of","predictions",",","optional","-","``","PREDICTED_UPPER_COL","``",":","upper","bound","of","predictions",",","optional","``","PREDICTED_LOWER_COL","``","and","``","PREDICTED_UPPER_COL","``","are","present","if","``","self.coverage","``","is","not","None","."]
code: def _get_predictions(self, fut_df: pd.DataFrame):
      """Gets the lag based predictions.
  
      Parameters
      ----------
      fut_df : `pandas.DataFrame`
          The input data that contains ``self.time_col_`` as the prediction periods.
  
      Returns
      -------
      predictions: `pandas.DataFrame`
          Forecasted values for the dates in ``fut_df``. Columns:
  
              - ``TIME_COL``: dates
              - ``PREDICTED_COL``: predictions
              - ``PREDICTED_LOWER_COL``: lower bound of predictions, optional
              - ``PREDICTED_UPPER_COL``: upper bound of predictions, optional
  
          ``PREDICTED_LOWER_COL`` and ``PREDICTED_UPPER_COL`` are present
          if ``self.coverage`` is not None.
      """
      # Gets the full df from the earliest timestamp during training to the
      # last timestamp in prediction.
      pred_df = fut_df[[self.time_col_]].copy()
      pred_df[self.time_col_] = pd.to_datetime(pred_df[self.time_col_])
      pred_df = pred_df.sort_values(by=self.time_col_).reset_index(
          drop=True
      )
      if pred_df[self.time_col_].iloc[0] < self.train_start:
          # Does not predict before the training period.
          raise ValueError(
              "The lag based estimator does not support hindcasting."
          )
      if pred_df[self.time_col_].iloc[-1] > self.train_end:
          df_end_timestamp = pd.DataFrame(
              {
                  self.time_col_: [pred_df[self.time_col_].iloc[-1]],
                  self.value_col_: [np.nan],
              }
          )
          # Fills the timestamps using frequency, in case the prediction df has wrong frequencies.
          df = pd.concat(
              [self.df, df_end_timestamp], axis=0
          ).reset_index(drop=True)
          df = fill_missing_dates(
              df=df, time_col=self.time_col_, freq=self.freq
          )[0]
      else:
          df = self.df.copy()
  
      # Gets the predicted values.
      df[cst.PREDICTED_COL] = np.nan
      # Gets the number of prediction rounds in case lag is not enough for forecast horizon.
      n_rounds = self._get_n_rounds(pred_df=pred_df)
      for _ in range(n_rounds):
          # The past timestamps needed in lags.
          # Uses time-based calculations to avoid messing up daylight saving times.
          past_timestamps = [
              df[self.time_col_].apply(
                  lambda x: x - self.lag_unit_delta * lag
              )
              for lag in self.lags
          ]
          # Gets the available past values.
          available_past = [
              df[df[self.time_col_].isin(timestamps)][
                  self.value_col_
              ].combine_first(
                  df[df[self.time_col_].isin(timestamps)][
                      cst.PREDICTED_COL
                  ]
              )
              for timestamps in past_timestamps
          ]
          # Fills NAs for the earliest unavailable timestamps to match the lengths.
          available_past = [
              pd.concat(
                  [pd.Series([np.nan] * (len(df) - len(past))), past],
                  axis=0,
              ).reset_index(drop=True)
              for past in available_past
          ]
          # Makes a dataframe.
          available_past = pd.concat(available_past, axis=1)
          # Applies aggregation function for prediction.
          pred = self.agg_func_wrapper(
              available_past, axis=1, **self.agg_func_params
          )
          # Writes to ``df``.
          df[cst.PREDICTED_COL] = pred
      # Gets the predictions during the input periods.
      pred_df = df[
          df[self.time_col_].isin(pred_df[self.time_col_])
      ].reset_index(drop=True)
      if len(pred_df) < len(fut_df):
          log_message(
              message=f"Some timestamps in the provided time periods for prediction do not match the "
              f"training frequency. Returning the matched timestamps.",
              level=LoggingLevelEnum.WARNING,
          )
      return pred_df
  
imports: from enum import Enum
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  import pandas
  from dateutil.relativedelta import relativedelta
  from sklearn.metrics import mean_squared_error
  from greykite.common import constants
  from greykite.common.aggregation_function_enum import AggregationFunctionEnum
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.time_properties import fill_missing_dates
  from greykite.common.time_properties import infer_freq
  from greykite.sklearn.estimator.base_forecast_estimator import BaseForecastEstimator
label_desc: Use image node_id 6 for calling the LagBasedEstimator obj's underlying member method code with example usage: obj._get_predictions(fut_df) and returns: pred_df