code: def _predict(
      self, ts: Union[pd.Series, pd.DataFrame]
  ) -> Union[pd.Series, pd.DataFrame]:
      if self._fitted == 0:
          raise RuntimeError("The model must be trained first.")
  
      if isinstance(ts, pd.Series):
          if self._fitted == 2:
              raise RuntimeError(
                  "The model was trained by a pandas DataFrame object, "
                  "it can only be applied to a pandas DataFrame object with "
                  "the same column names as the one used for training."
              )
          s = ts.copy()
          if not isinstance(s.index, pd.DatetimeIndex):
              raise TypeError(
                  "Index of the input time series must be a pandas "
                  "DatetimeIndex object."
              )
          predicted = self._predict_core(s)
          # if a Series-to-Series operation, make sure Series name keeps
          if isinstance(predicted, pd.Series):
              predicted.name = ts.name
      elif isinstance(ts, pd.DataFrame):
          df = ts.copy()
          if not isinstance(df.index, pd.DatetimeIndex):
              raise TypeError(
                  "Index of the input time series must be a pandas "
                  "DatetimeIndex object."
              )
          if df.columns.duplicated().any():
              raise ValueError(
                  "Input DataFrame must have unique column names."
              )
          if self._fitted == 1:
              # apply the model to each column
              predicted_all_cols = []
              for col in df.columns:
                  predicted_this_col = self._predict(df[col])
                  if isinstance(predicted_this_col, pd.DataFrame):
                      predicted_this_col = predicted_this_col.rename(
                          columns={
                              col1: "{}_{}".format(col, col1)
                              for col1 in predicted_this_col.columns
                          }
                      )
                  predicted_all_cols.append(predicted_this_col)
              predicted = pd.concat(predicted_all_cols, axis=1)
          else:
              # predict for each column
              if not (set(self._models.keys()) >= set(df.columns)):
                  raise ValueError(
                      "The model was trained by a pandas DataFrame with "
                      "columns {}, but the input DataFrame contains columns "
                      "{} which are unknown to the model.".format(
                          list(set(self._models.keys())),
                          list(
                              set(df.columns) - set(self._models.keys())
                          ),
                      )
                  )
              predicted = pd.concat(
                  [
                      self._models[col]._predict(df[col])
                      for col in df.columns
                  ],
                  axis=1,
              )
      else:
          raise TypeError("Input must be a pandas Series or DataFrame.")
      # make sure index freq is the same (because pandas has a bug that some
      # operation, e.g. concat, may change freq)
      predicted.index.freq = ts.index.freq
      return predicted
  
imports: from abc import ABC, abstractmethod
  from copy import deepcopy
  from typing import Any, Dict, List, Tuple, Union
  import pandas
label_desc: Use image node_id 3 for calling the _TrainableUnivariateModel obj's underlying member method code with example usage: obj._predict(ts) and returns: predicted