class_docstr: Base adapter class for StatsForecast models.
class_docstr_tok: ["Base","adapter","class","for","StatsForecast","models","."]
code: def _predict_in_or_out_of_sample(
      self, fh, fh_type, X=None, levels=None
  ):
      maximum_forecast_horizon = fh.to_relative(self.cutoff)[-1]
  
      absolute_horizons = fh.to_absolute_index(self.cutoff)
      horizon_positions = fh.to_indexer(self.cutoff)
  
      level_arguments = (
          None if levels is None else [100 * level for level in levels]
      )
  
      if fh_type == "in-sample":
          predict_method = self._forecaster.predict_in_sample
          # Before v1.5.0 (from statsforecast) not all foreasters
          # have a "level" keyword argument in `predict_in_sample`
          level_kw = (
              {"level": level_arguments}
              if self._support_pred_int_in_sample
              else {}
          )
          predictions = predict_method(**level_kw)
          point_predictions = predictions["fitted"]
      elif fh_type == "out-of-sample":
          predict_method = self._forecaster.predict
          # Before v1.5.0 (from statsforecast) not all foreasters
          # have a "level" keyword argument in `predict`
          level_kw = (
              {"level": level_arguments}
              if self._support_pred_int
              else {}
          )
          predictions = predict_method(
              maximum_forecast_horizon, X=X, **level_kw
          )
          point_predictions = predictions["mean"]
  
      if isinstance(point_predictions, pandas.Series):
          point_predictions = point_predictions.to_numpy()
  
      final_point_predictions = pandas.Series(
          point_predictions[horizon_positions], index=absolute_horizons
      )
  
      if levels is None:
          return final_point_predictions
  
      var_names = self._get_varnames()
      var_name = var_names[0]
  
      interval_predictions_indices = pandas.MultiIndex.from_product(
          [var_names, levels, ["lower", "upper"]]
      )
      interval_predictions = pandas.DataFrame(
          index=absolute_horizons, columns=interval_predictions_indices
      )
  
      if fh_type == "out-of-sample":
          column_prefix = ""
      elif fh_type == "in-sample":
          column_prefix = "fitted-"
  
      for level, level_argument in zip(levels, level_arguments):
          lower_interval_predictions = predictions[
              f"{column_prefix}lo-{level_argument}"
          ]
          if isinstance(lower_interval_predictions, pandas.Series):
              lower_interval_predictions = (
                  lower_interval_predictions.to_numpy()
              )
  
          upper_interval_predictions = predictions[
              f"{column_prefix}hi-{level_argument}"
          ]
          if isinstance(upper_interval_predictions, pandas.Series):
              upper_interval_predictions = (
                  upper_interval_predictions.to_numpy()
              )
  
          interval_predictions[
              (var_name, level, "lower")
          ] = lower_interval_predictions[horizon_positions]
          interval_predictions[
              (var_name, level, "upper")
          ] = upper_interval_predictions[horizon_positions]
  
      return interval_predictions
  
imports: from inspect import signature
  from typing import Dict
  from warnings import warn
  import pandas
  from sktime.forecasting.base import BaseForecaster
label_desc: Use image node_id 9 for calling the _GeneralisedStatsForecastAdapter obj's underlying member method code with example usage: obj._predict_in_or_out_of_sample(fh, fh_type, X, levels) and returns: interval_predictions, final_point_predictions