class_docstr: Implementation of the classic local statistical model ETS (Error, Trend, Seasonal) for forecasting.
class_docstr_tok: ["Implementation","of","the","classic","local","statistical","model","ETS","(","Error",",","Trend",",","Seasonal",")","for","forecasting","."]
code: def _forecast(
      self,
      time_stamps: Union[int, List[int]],
      time_series_prev: pd.DataFrame = None,
      return_prev=False,
  ) -> Tuple[pd.DataFrame, pd.DataFrame]:
      # If there is a time_series_prev, use it to set the ETS model's state, and then obtain its forecast
      time_stamps = to_pd_datetime(time_stamps)
      if time_series_prev is None:
          last_val = self._last_val
          model = self.model
          start = self._n_train
      else:
          time_series_prev = time_series_prev.iloc[
              :, self.target_seq_index
          ]
          val_prev = pd.Series(
              time_series_prev[-self._max_lookback :].values
          )
          last_val = val_prev.iloc[-1]
          start = len(val_prev)
  
          # the default setting of refit=False is fast and conducts exponential smoothing with given parameters,
          # while the setting of refit=True is slow and refits the model on time_series_prev.
          model = self._instantiate_model(val_prev)
          with warnings.catch_warnings():
              warnings.simplefilter("ignore")
              if (
                  self.config.refit
                  and len(time_series_prev) > self._max_lookback
              ):
                  model = model.fit(
                      start_params=self.model.params, disp=False
                  )
              else:
                  model = model.smooth(params=self.model.params)
  
      # Run forecasting.
      forecast_result = model.get_prediction(
          start=start, end=start + len(time_stamps) - 1
      )
      forecast = np.asarray(forecast_result.predicted_mean)
      err = np.sqrt(np.asarray(forecast_result.var_pred_mean))
  
      # If return_prev is True, return the forecast and error of last train window instead of time_series_prev
      if time_series_prev is not None and return_prev:
          m = len(time_series_prev) - len(val_prev)
          err_prev = np.concatenate(
              (np.zeros(m), model.standardized_forecasts_error.values)
          )
          forecast = np.concatenate(
              (
                  time_series_prev.values[:m],
                  model.fittedvalues.values,
                  forecast,
              )
          )
          err = np.concatenate((err_prev, err))
          time_stamps = to_pd_datetime(
              np.concatenate((time_series_prev.index, time_stamps))
          )
  
      # Check for NaN's
      if any(np.isnan(forecast)):
          logger.warning(
              "Trained ETS is producing NaN forecast. Use the last training point as the prediction."
          )
          forecast[np.isnan(forecast)] = last_val
      if err is not None and any(np.isnan(err)):
          err[np.isnan(err)] = 0
  
      # Return the forecast & its standard error
      name = self.target_name
      forecast = pd.DataFrame(
          forecast, index=time_stamps, columns=[name]
      )
      if err is not None:
          err = pd.DataFrame(
              err, index=time_stamps, columns=[f"{name}_err"]
          )
      return forecast, err
  
imports: import logging
  from typing import List, Tuple, Union
  import warnings
  import numpy
  import pandas
  from statsmodels.tsa.exponential_smoothing.ets import ETSModel
  from merlion.models.automl.seasonality import SeasonalityModel
  from merlion.models.forecast.base import ForecasterBase, ForecasterConfig
  from merlion.transform.resample import TemporalResample
  from merlion.utils import UnivariateTimeSeries, to_pd_datetime
label_desc: Use image node_id 12 for calling the ETS obj's underlying member method code with example usage: obj._forecast(time_stamps, time_series_prev, return_prev) and returns: forecast,  err