docstr: Predict the results
docstr_tok: ["Predict","the","results"]
code: def predict(
      self,
      testdata,
      model: str = "",
      simple: bool = False,
      time_interval: str = "",
      saved_model: str = "",
  ):
      """
      Predict the results
      """
  
      if isinstance(testdata, pd.Series) or isinstance(
          testdata, pd.DataFrame
      ):
          # During training, we internally converted a column datetime index to the dataframe date time index
          # We need to do the same while predicing for consistence
          if (
              (model == "ML")
              or self.get_best_model_name() == "ML"
              or (
                  model == "best" and self.get_best_model_name() == "ML"
              )
          ):
              print(
                  "Predicting using test dataframe shape = %s for ML model"
                  % (testdata.shape,)
              )
          else:
              print(
                  "Predicting using test dataframe as input for %s model"
                  % self.get_best_model_name()
              )
      elif type(testdata) == dask.dataframe.core.DataFrame:
          # During training, we internally converted a column datetime index to the dataframe date time index
          # We need to do the same while predicing for consistence
          if (
              (model == "ML")
              or self.get_best_model_name() == "ML"
              or (
                  model == "best" and self.get_best_model_name() == "ML"
              )
          ):
              ### Now do the predictions using the final model asked to be predicted ###
              print(
                  "Predicting using test dask data frame as input for ML model"
              )
          else:
              print(
                  "Cannot predicting using dask dataframe as input for %s model. Returning"
                  % self.get_best_model_name()
              )
              return
      elif isinstance(testdata, int):
          #### if testdata is an Integer, then it appears to be a forecast period, then use it that way
          ### only certain stats-based models can use forecast period
          if (model == "ML") or (
              model == "best" and self.get_best_model_name() == "ML"
          ):
              print(
                  "Error in input: You must give a test dataframe for ML models"
              )
          else:
              print(
                  "Predicting using forecast period=%s as input for %s model"
                  % (testdata, self.get_best_model_name())
              )
  
      ##### This is where we load the model to predict ###########
      if isinstance(model, str):
          if model == "":
              bestmodel = self.get_best_model_build()
          elif model.lower() == "best":
              bestmodel = self.get_best_model_build()
          else:
              if saved_model:
                  ### if a saved_model is specified, just use that model as given and use it ###
                  print(
                      "Make sure the given saved_model has already been trained on this data. Otherwise, it will give errors."
                  )
                  self.ml_dict[model]["model"] = copy.deepcopy(
                      saved_model
                  )
              bestmodel = self.get_model_build(model)
              if self.get_model_build(model) is not None:
                  bestmodel = self.get_model_build(model)
              else:
                  print(
                      f"(Error) Model of type '{model}' does not exist. Check inputs and try again."
                  )
                  return None
          self.model = bestmodel
      else:
          ### if no model is specified, just use the best model ###
          bestmodel = self.get_best_model_build()
          self.model = bestmodel
      ##### Now make predictions using model given ######
      try:
          if isinstance(testdata, pd.Series) or isinstance(
              testdata, pd.DataFrame
          ):
              # During training, we internally converted a column datetime index to the dataframe date time index
              # We need to do the same while predicing for consistence
              if (
                  (model.lower() == "ml")
                  or self.get_best_model_name().lower() == "ml"
                  or (
                      model.lower() == "best"
                      and self.get_best_model_name().lower() == "ml"
                  )
              ):
                  ### Now do the predictions using the final model asked to be predicted ###
                  predictions = bestmodel.predict(
                      testdata,
                      simple=simple,
                      time_interval=time_interval,
                  )
              elif (
                  model.lower() == "prophet"
                  or self.get_best_model_name() == "Prophet"
              ):
                  predictions = bestmodel.predict(
                      testdata, simple=simple
                  )
              elif self.get_best_model_name().lower() == "var":
                  predictions = bestmodel.predict(
                      testdata, simple=simple
                  )
              else:
                  predictions = bestmodel.predict(
                      testdata, simple=simple
                  )
          elif type(testdata) == dask.dataframe.core.DataFrame:
              # During training, we internally converted a column datetime index to the dataframe date time index
              # We need to do the same while predicing for consistence
              if (
                  (model == "ML")
                  or self.get_best_model_name() == "ML"
                  or (
                      model == "best"
                      and self.get_best_model_name() == "ML"
                  )
              ):
                  ### Now do the predictions using the final model asked to be predicted ###
                  predictions = bestmodel.predict(
                      testdata,
                      simple=simple,
                      time_interval=time_interval,
                  )
              else:
                  print(
                      "Dask dataframes are not accepted as input for non-ML models. Please change your input and try again."
                  )
                  predictions = np.array()
                  return predictions
          elif isinstance(testdata, int):
              #### if testdata is an Integer, then it appears to be a forecast period, then use it that way
              ### only certain stats-based models can use forecast period
              if (model == "ML") or (
                  model == "best" and self.get_best_model_name() == "ML"
              ):
                  print(
                      f"{model} is an ML-based model, hence it cannot be used with a forecast period"
                  )
                  predictions = None
              else:
                  predictions = bestmodel.predict(
                      testdata, simple=simple
                  )
          else:
              ### if there is no testdata, at least they must give forecast_period
              if testdata is None:
                  print(
                      "If test_data is None, then forecast_period must be given"
                  )
                  return
      except:
          print(
              "Model is erroring during prediction. Check inputs and try again."
          )
          return
      return predictions
  
imports: import warnings
  from typing import List, Dict, Optional, Tuple, Union
  from datetime import datetime
  import copy
  from collections import defaultdict
  import operator
  from time import time
  import pdb
  import pandas
  import numpy
  import dask
  import dask.dataframe
  from sklearn.exceptions import DataConversionWarning
  import seaborn
  import seaborn
  import matplotlib.pyplot
  from .models import BuildBase, BuildArima, BuildAutoSarimax, BuildVAR, BuildML
  from .models.build_prophet import BuildProphet
  from .utils import colorful, load_ts_data, convert_timeseries_dataframe_to_supervised, time_series_plot, print_static_rmse, print_dynamic_rmse, quick_ts_plot, test_stationarity, print_ts_model_stats
  from .__version__ import __version__
label_desc: Use image node_id 9 for calling the auto_timeseries obj's underlying member method code with example usage: obj.predict(testdata, model, simple, time_interval, saved_model) and returns: predictions, None, predictions