class_docstr: Automated TimeSeries Estimator for time series forecasting task, which supports
  TSDataset and customized data creator as data input on built-in model (only
  "lstm", "tcn", "seq2seq" for now) and 3rd party model.
  
  Only backend="torch" is supported for now. Customized data creator has not been
  fully supported by TSPipeline.
  
  >>> # Here is a use case example:
  >>> # prepare train/valid/test tsdataset
  >>> autoest = AutoTSEstimator(model="lstm",
  >>>                           search_space=search_space,
  >>>                           past_seq_len=6,
  >>>                           future_seq_len=1)
  >>> tsppl = autoest.fit(data=tsdata_train,
  >>>                     validation_data=tsdata_valid)
  >>> tsppl.predict(tsdata_test)
  >>> tsppl.save("my_tsppl")
class_docstr_tok: ["Automated","TimeSeries","Estimator","for","time","series","forecasting","task",",","which","supports","TSDataset","and","customized","data","creator","as","data","input","on","built-in","model","(","only","''","lstm","''",",","``","tcn","''",",","``","seq2seq","''","for","now",")","and","3rd","party","model",".","Only","backend=","''","torch","''","is","supported","for","now",".","Customized","data","creator","has","not","been","fully","supported","by","TSPipeline",".",">",">",">","#","Here","is","a","use","case","example",":",">",">",">","#","prepare","train\/valid\/test","tsdataset",">",">",">","autoest","=","AutoTSEstimator","(","model=","''","lstm","''",",",">",">",">","search_space=search_space",",",">",">",">","past_seq_len=6",",",">",">",">","future_seq_len=1",")",">",">",">","tsppl","=","autoest.fit","(","data=tsdata_train",",",">",">",">","validation_data=tsdata_valid",")",">",">",">","tsppl.predict","(","tsdata_test",")",">",">",">","tsppl.save","(","``","my_tsppl","''",")"]
docstr: AutoTSEstimator trains a model for time series forecasting.
  Users can choose one of the built-in models, or pass in a customized pytorch or keras model
  for tuning using AutoML.
  
  :param model: a string or a model creation function.
         A string indicates a built-in model, currently "lstm", "tcn", "seq2seq" are
         supported.
         A model creation function indicates a 3rd party model, the function should take a
         config param and return a torch.nn.Module (backend="torch") / tf model
         (backend="keras").
         If you use chronos.data.TSDataset as data input, the 3rd party
         should have 3 dim input (num_sample, past_seq_len, input_feature_num) and 3 dim
         output (num_sample, future_seq_len, output_feature_num) and use the same key
         in the model creation function. If you use a customized data creator, the output of
         data creator should fit the input of model creation function.
  :param search_space: str or dict. hyper parameter configurations. For str, you can choose
         from "minimal", "normal", or "large", each represents a default search_space for
         our built-in model with different computing requirement. For dict, Read the API docs
         for each auto model. Some common hyper parameter can be explicitly set in named
         parameter. search_space should contain those parameters other than the keyword
         arguments in this constructor in its key. If a 3rd parth model is used, then you
         must set search_space to a dict.
  :param metric: String. The evaluation metric name to optimize. e.g. "mse"
  :param loss: String or pytorch/tf.keras loss instance or pytorch loss creator function. The
         default loss function for pytorch backend is nn.MSELoss().
  :param optimizer: String or pyTorch optimizer creator function or
         tf.keras optimizer instance.
  :param past_seq_len: Int or or hp sampling function. The number of historical steps (i.e.
         lookback) used for forecasting. For hp sampling, see zoo.orca.automl.hp for more
         details. The values defaults to 2.
  :param future_seq_len: Int. The number of future steps to forecast. The value defaults
         to 1.
  :param input_feature_num: Int. The number of features in the input. The value is ignored if
         you use chronos.data.TSDataset as input data type.
  :param output_target_num: Int. The number of targets in the output. The value is ignored if
         you use chronos.data.TSDataset as input data type.
  :param selected_features: String. "all" and "auto" are supported for now. For "all",
         all features that are generated are used for each trial. For "auto", a subset
         is sampled randomly from all features for each trial. The parameter is ignored
         if not using chronos.data.TSDataset as input data type. The value defaults
         to "auto".
  :param backend: The backend of the auto model. We only support backend as "torch" for now.
  :param logs_dir: Local directory to save logs and results.
         It defaults to "/tmp/autots_estimator"
  :param cpus_per_trial: Int. Number of cpus for each trial. It defaults to 1.
  :param name: name of the autots estimator. It defaults to "autots_estimator".
  :param remote_dir: String. Remote directory to sync training results and checkpoints. It
         defaults to None and doesn't take effects while running in local. While running in
         cluster, it defaults to "hdfs:///tmp/{name}".
docstr_tok: ["AutoTSEstimator","trains","a","model","for","time","series","forecasting",".","Users","can","choose","one","of","the","built-in","models",",","or","pass","in","a","customized","pytorch","or","keras","model","for","tuning","using","AutoML",".",":","param","model",":","a","string","or","a","model","creation","function",".","A","string","indicates","a","built-in","model",",","currently","``","lstm","''",",","``","tcn","''",",","``","seq2seq","''","are","supported",".","A","model","creation","function","indicates","a","3rd","party","model",",","the","function","should","take","a","config","param","and","return","a","torch.nn.Module","(","backend=","''","torch","''",")","\/","tf","model","(","backend=","''","keras","''",")",".","If","you","use","chronos.data.TSDataset","as","data","input",",","the","3rd","party","should","have","3","dim","input","(","num_sample",",","past_seq_len",",","input_feature_num",")","and","3","dim","output","(","num_sample",",","future_seq_len",",","output_feature_num",")","and","use","the","same","key","in","the","model","creation","function",".","If","you","use","a","customized","data","creator",",","the","output","of","data","creator","should","fit","the","input","of","model","creation","function",".",":","param","search_space",":","str","or","dict",".","hyper","parameter","configurations",".","For","str",",","you","can","choose","from","``","minimal","''",",","``","normal","''",",","or","``","large","''",",","each","represents","a","default","search_space","for","our","built-in","model","with","different","computing","requirement",".","For","dict",",","Read","the","API","docs","for","each","auto","model",".","Some","common","hyper","parameter","can","be","explicitly","set","in","named","parameter",".","search_space","should","contain","those","parameters","other","than","the","keyword","arguments","in","this","constructor","in","its","key",".","If","a","3rd","parth","model","is","used",",","then","you","must","set","search_space","to","a","dict",".",":","param","metric",":","String",".","The","evaluation","metric","name","to","optimize",".","e.g",".","``","mse","''",":","param","loss",":","String","or","pytorch\/tf.keras","loss","instance","or","pytorch","loss","creator","function",".","The","default","loss","function","for","pytorch","backend","is","nn.MSELoss","(",")",".",":","param","optimizer",":","String","or","pyTorch","optimizer","creator","function","or","tf.keras","optimizer","instance",".",":","param","past_seq_len",":","Int","or","or","hp","sampling","function",".","The","number","of","historical","steps","(","i.e",".","lookback",")","used","for","forecasting",".","For","hp","sampling",",","see","zoo.orca.automl.hp","for","more","details",".","The","values","defaults","to","2.",":","param","future_seq_len",":","Int",".","The","number","of","future","steps","to","forecast",".","The","value","defaults","to","1.",":","param","input_feature_num",":","Int",".","The","number","of","features","in","the","input",".","The","value","is","ignored","if","you","use","chronos.data.TSDataset","as","input","data","type",".",":","param","output_target_num",":","Int",".","The","number","of","targets","in","the","output",".","The","value","is","ignored","if","you","use","chronos.data.TSDataset","as","input","data","type",".",":","param","selected_features",":","String",".","``","all","''","and","``","auto","''","are","supported","for","now",".","For","``","all","''",",","all","features","that","are","generated","are","used","for","each","trial",".","For","``","auto","''",",","a","subset","is","sampled","randomly","from","all","features","for","each","trial",".","The","parameter","is","ignored","if","not","using","chronos.data.TSDataset","as","input","data","type",".","The","value","defaults","to","``","auto","''",".",":","param","backend",":","The","backend","of","the","auto","model",".","We","only","support","backend","as","``","torch","''","for","now",".",":","param","logs_dir",":","Local","directory","to","save","logs","and","results",".","It","defaults","to","``","\/tmp\/autots_estimator","''",":","param","cpus_per_trial",":","Int",".","Number","of","cpus","for","each","trial",".","It","defaults","to","1.",":","param","name",":","name","of","the","autots","estimator",".","It","defaults","to","``","autots_estimator","''",".",":","param","remote_dir",":","String",".","Remote","directory","to","sync","training","results","and","checkpoints",".","It","defaults","to","None","and","does","n't","take","effects","while","running","in","local",".","While","running","in","cluster",",","it","defaults","to","``","hdfs",":","\/\/\/tmp\/","{","name","}","''","."]
code: def __init__(
      self,
      model="lstm",
      search_space=dict(),
      metric="mse",
      loss=None,
      optimizer="Adam",
      past_seq_len=2,
      future_seq_len=1,
      input_feature_num=None,
      output_target_num=None,
      selected_features="auto",
      backend="torch",
      logs_dir="/tmp/autots_estimator",
      cpus_per_trial=1,
      name="autots_estimator",
      remote_dir=None,
  ):
      """
      AutoTSEstimator trains a model for time series forecasting.
      Users can choose one of the built-in models, or pass in a customized pytorch or keras model
      for tuning using AutoML.
  
      :param model: a string or a model creation function.
             A string indicates a built-in model, currently "lstm", "tcn", "seq2seq" are
             supported.
             A model creation function indicates a 3rd party model, the function should take a
             config param and return a torch.nn.Module (backend="torch") / tf model
             (backend="keras").
             If you use chronos.data.TSDataset as data input, the 3rd party
             should have 3 dim input (num_sample, past_seq_len, input_feature_num) and 3 dim
             output (num_sample, future_seq_len, output_feature_num) and use the same key
             in the model creation function. If you use a customized data creator, the output of
             data creator should fit the input of model creation function.
      :param search_space: str or dict. hyper parameter configurations. For str, you can choose
             from "minimal", "normal", or "large", each represents a default search_space for
             our built-in model with different computing requirement. For dict, Read the API docs
             for each auto model. Some common hyper parameter can be explicitly set in named
             parameter. search_space should contain those parameters other than the keyword
             arguments in this constructor in its key. If a 3rd parth model is used, then you
             must set search_space to a dict.
      :param metric: String. The evaluation metric name to optimize. e.g. "mse"
      :param loss: String or pytorch/tf.keras loss instance or pytorch loss creator function. The
             default loss function for pytorch backend is nn.MSELoss().
      :param optimizer: String or pyTorch optimizer creator function or
             tf.keras optimizer instance.
      :param past_seq_len: Int or or hp sampling function. The number of historical steps (i.e.
             lookback) used for forecasting. For hp sampling, see zoo.orca.automl.hp for more
             details. The values defaults to 2.
      :param future_seq_len: Int. The number of future steps to forecast. The value defaults
             to 1.
      :param input_feature_num: Int. The number of features in the input. The value is ignored if
             you use chronos.data.TSDataset as input data type.
      :param output_target_num: Int. The number of targets in the output. The value is ignored if
             you use chronos.data.TSDataset as input data type.
      :param selected_features: String. "all" and "auto" are supported for now. For "all",
             all features that are generated are used for each trial. For "auto", a subset
             is sampled randomly from all features for each trial. The parameter is ignored
             if not using chronos.data.TSDataset as input data type. The value defaults
             to "auto".
      :param backend: The backend of the auto model. We only support backend as "torch" for now.
      :param logs_dir: Local directory to save logs and results.
             It defaults to "/tmp/autots_estimator"
      :param cpus_per_trial: Int. Number of cpus for each trial. It defaults to 1.
      :param name: name of the autots estimator. It defaults to "autots_estimator".
      :param remote_dir: String. Remote directory to sync training results and checkpoints. It
             defaults to None and doesn't take effects while running in local. While running in
             cluster, it defaults to "hdfs:///tmp/{name}".
      """
      # check backend and set default loss
      if backend != "torch":
          raise ValueError(
              f"We only support backend as torch. Got {backend}"
          )
      else:
          import torch
  
          if loss is None:
              loss = torch.nn.MSELoss()
  
      if isinstance(search_space, str):
          search_space = AutoModelFactory.get_default_search_space(
              model, search_space
          )
  
      if isinstance(model, types.FunctionType) and backend == "torch":
          # pytorch 3rd party model
          from zoo.orca.automl.auto_estimator import AutoEstimator
  
          self.model = AutoEstimator.from_torch(
              model_creator=model,
              optimizer=optimizer,
              loss=loss,
              logs_dir=logs_dir,
              resources_per_trial={"cpu": cpus_per_trial},
              name=name,
          )
          self.metric = metric
          search_space.update(
              {
                  "past_seq_len": past_seq_len,
                  "future_seq_len": future_seq_len,
                  "input_feature_num": input_feature_num,
                  "output_feature_num": output_target_num,
              }
          )
          self.search_space = search_space
  
      if isinstance(model, str):
          # built-in model
          # update auto model common search space
          search_space.update(
              {
                  "past_seq_len": past_seq_len,
                  "future_seq_len": future_seq_len,
                  "input_feature_num": input_feature_num,
                  "output_target_num": output_target_num,
                  "loss": loss,
                  "metric": metric,
                  "optimizer": optimizer,
                  "backend": backend,
                  "logs_dir": logs_dir,
                  "cpus_per_trial": cpus_per_trial,
                  "name": name,
              }
          )
  
          # create auto model from name
          self.model = AutoModelFactory.create_auto_model(
              name=model, search_space=search_space
          )
  
      # save selected features setting for data creator generation
      self.selected_features = selected_features
      self._scaler = None
      self._scaler_index = None
  
file_path: analytics-zoo/pyzoo/zoo/chronos/autots/autotsestimator.py
imports: import types
  from zoo.orca.automl.auto_estimator import AutoEstimator
  from zoo.chronos.data import TSDataset
  import zoo.orca.automl.hp
  from zoo.chronos.autots.model import AutoModelFactory
  from zoo.chronos.autots.tspipeline import TSPipeline
label_desc: Use image node_id 1 to create a new AutoTSEstimator object  with example: obj = AutoTSEstimator(model, search_space, metric, loss, optimizer, past_seq_len, future_seq_len, input_feature_num, output_target_num, selected_features, backend, logs_dir, cpus_per_trial, name, remote_dir)