docstr: Fit(Train) the forecaster.
  
  :param data: The data support following formats:
  
         | 1. A numpy ndarray tuple (x, y):
         | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
         | should be the same as past_seq_len and input_feature_num.
         | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
         | should be the same as future_seq_len and output_feature_num.
         |
         | 2. A tf.data.Dataset:
         | A TFDataset instance which contains x and y with same shape as the tuple.
         | x's shape is (num_samples, lookback, feature_dim),
         | y's shape is (num_samples, horizon, target_dim).
         | If set distributed to True, we do not recommend using tf.data.Dataset,
         | please replace with tsdataset or numpy.ndarray.
         |
         | 3. A bigdl.chronos.data.tsdataset.TSDataset instance.
         | Forecaster will automatically process the TSDataset.
         | By default, TSDataset will be transformed to a tfdataset,
         | Users may call `roll` on the TSDataset before calling `fit`
         | Then the training speed will be faster but will consume more memory.
  
  :params epochs: Number of epochs you want to train. The value defaults to 1.
  :params batch_size: Number of batch size you want to train. The value defaults to 32.
          Do not specify the batch_size, if your data in the form of tf.data datasets.
docstr_tok: ["Fit","(","Train",")","the","forecaster",".",":","param","data",":","The","data","support","following","formats",":","|","1",".","A","numpy","ndarray","tuple","(","x",",","y",")",":","|","x","'s","shape","is","(","num_samples",",","lookback",",","feature_dim",")","where","lookback","and","feature_dim","|","should","be","the","same","as","past_seq_len","and","input_feature_num",".","|","y","'s","shape","is","(","num_samples",",","horizon",",","target_dim",")",",","where","horizon","and","target_dim","|","should","be","the","same","as","future_seq_len","and","output_feature_num",".","|","|","2",".","A","tf.data.Dataset",":","|","A","TFDataset","instance","which","contains","x","and","y","with","same","shape","as","the","tuple",".","|","x","'s","shape","is","(","num_samples",",","lookback",",","feature_dim",")",",","|","y","'s","shape","is","(","num_samples",",","horizon",",","target_dim",")",".","|","If","set","distributed","to","True",",","we","do","not","recommend","using","tf.data.Dataset",",","|","please","replace","with","tsdataset","or","numpy.ndarray",".","|","|","3",".","A","bigdl.chronos.data.tsdataset.TSDataset","instance",".","|","Forecaster","will","automatically","process","the","TSDataset",".","|","By","default",",","TSDataset","will","be","transformed","to","a","tfdataset",",","|","Users","may","call","`","roll","`","on","the","TSDataset","before","calling","`","fit","`","|","Then","the","training","speed","will","be","faster","but","will","consume","more","memory",".",":","params","epochs",":","Number","of","epochs","you","want","to","train",".","The","value","defaults","to","1.",":","params","batch_size",":","Number","of","batch","size","you","want","to","train",".","The","value","defaults","to","32",".","Do","not","specify","the","batch_size",",","if","your","data","in","the","form","of","tf.data","datasets","."]
code: def fit(self, data, epochs=1, batch_size=32):
      """
      Fit(Train) the forecaster.
  
      :param data: The data support following formats:
  
             | 1. A numpy ndarray tuple (x, y):
             | x's shape is (num_samples, lookback, feature_dim) where lookback and feature_dim
             | should be the same as past_seq_len and input_feature_num.
             | y's shape is (num_samples, horizon, target_dim), where horizon and target_dim
             | should be the same as future_seq_len and output_feature_num.
             |
             | 2. A tf.data.Dataset:
             | A TFDataset instance which contains x and y with same shape as the tuple.
             | x's shape is (num_samples, lookback, feature_dim),
             | y's shape is (num_samples, horizon, target_dim).
             | If set distributed to True, we do not recommend using tf.data.Dataset,
             | please replace with tsdataset or numpy.ndarray.
             |
             | 3. A bigdl.chronos.data.tsdataset.TSDataset instance.
             | Forecaster will automatically process the TSDataset.
             | By default, TSDataset will be transformed to a tfdataset,
             | Users may call `roll` on the TSDataset before calling `fit`
             | Then the training speed will be faster but will consume more memory.
  
      :params epochs: Number of epochs you want to train. The value defaults to 1.
      :params batch_size: Number of batch size you want to train. The value defaults to 32.
              Do not specify the batch_size, if your data in the form of tf.data datasets.
      """
      if isinstance(data, TSDataset):
          if data.lookback is None:
              data.roll(
                  lookback=self.model_config["past_seq_len"],
                  horizon=self.model_config["future_seq_len"],
              )
  
      if self.distributed:
          if isinstance(data, tuple):
              data = np_to_data_creator(data, shuffle=True)
          if isinstance(data, TSDataset):
              data = tsdata_to_data_creator(data, shuffle=True)
          from bigdl.nano.utils.common import invalidInputError
  
          invalidInputError(
              not isinstance(data, tf.data.Dataset),
              "tf.data.Dataset is not supported, "
              "please replace with numpy.ndarray or TSDataset instance.",
          )
          # for cluster mode
          from bigdl.orca.common import OrcaContext
  
          sc = OrcaContext.get_spark_context().getConf()
          num_nodes = (
              1
              if sc.get("spark.master").startswith("local")
              else int(sc.get("spark.executor.instances"))
          )
          if batch_size % self.workers_per_node != 0:
              from bigdl.nano.utils.common import invalidInputError
  
              invalidInputError(
                  False,
                  "Please make sure that batch_size can be divisible by "
                  "the product of worker_per_node and num_nodes, "
                  f"but 'batch_size' is {batch_size}, 'workers_per_node' "
                  f"is {self.workers_per_node}, 'num_nodes' is {num_nodes}",
              )
          batch_size //= self.workers_per_node * num_nodes
          self.internal.fit(data, epochs=epochs, batch_size=batch_size)
      else:
          if isinstance(data, tuple):
              self.internal.fit(
                  x=data[0],
                  y=data[1],
                  epochs=epochs,
                  batch_size=batch_size,
              )
          else:
              if isinstance(data, TSDataset):
                  data = data.to_tf_dataset(
                      shuffle=True, batch_size=batch_size
                  )
              self.internal.fit(data, epochs=epochs)
      self.fitted = True
  
imports: import warnings
  import keras
  import tensorflow
  import numpy
  from bigdl.chronos.forecaster.abstract import Forecaster
  from bigdl.chronos.data import TSDataset
  from bigdl.chronos.metric.forecast_metrics import Evaluator
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.chronos.forecaster.tf.utils import np_to_data_creator, tsdata_to_data_creator, np_to_xshards, xshard_to_np, np_to_tfdataset
label_desc: Use image node_id 2 for calling the BaseTF2Forecaster obj's underlying member method code with example usage: obj.fit(data, epochs, batch_size) without return types