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) or 3rd party model.
  
  >>> # 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",")","or","3rd","party","model",".",">",">",">","#","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 or customized evaluation metric function.
         If string, metric is the evaluation metric name to optimize, e.g. "mse".
         If callable function, it signature should be func(y_true, y_pred), where y_true and
         y_pred are numpy ndarray. The function should return a float value as evaluation
         result.
  :param metric_mode: One of ["min", "max"]. "max" means greater metric value is better.
         You have to specify metric_mode if you use a customized metric function.
         You don't have to specify metric_mode if you use the built-in metric in
         bigdl.orca.automl.metrics.Evaluator.
  :param loss: String or pytorch loss instance or pytorch loss creator function. The
         default loss function for pytorch backend is nn.MSELoss(). If users use
         backend="keras" and 3rd parth model this parameter will be ignored.
  :param optimizer: String or pyTorch optimizer creator function or tf.keras optimizer
         instance. If users use backend="keras" and 3rd parth model, this parameter will
         be ignored.
  :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 bigdl.orca.automl.hp for more
         details. The values defaults to 'auto', which will automatically infer the
         cycle length of each time series and take the mode of them. The search space
         will be automatically set to hp.randint(0.5*cycle_length, 2*cycle_length).
  :param future_seq_len: Int or List. The number of future steps to forecast. The value
         defaults to 1, if `future_seq_len` is a list, we will sample discretely according
         to the input list. 1 means the timestamp just after the observed data.
  :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" or
                "keras" 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","or","customized","evaluation","metric","function",".","If","string",",","metric","is","the","evaluation","metric","name","to","optimize",",","e.g",".","``","mse","''",".","If","callable","function",",","it","signature","should","be","func","(","y_true",",","y_pred",")",",","where","y_true","and","y_pred","are","numpy","ndarray",".","The","function","should","return","a","float","value","as","evaluation","result",".",":","param","metric_mode",":","One","of","[","``","min","''",",","``","max","''","]",".","``","max","''","means","greater","metric","value","is","better",".","You","have","to","specify","metric_mode","if","you","use","a","customized","metric","function",".","You","do","n't","have","to","specify","metric_mode","if","you","use","the","built-in","metric","in","bigdl.orca.automl.metrics.Evaluator",".",":","param","loss",":","String","or","pytorch","loss","instance","or","pytorch","loss","creator","function",".","The","default","loss","function","for","pytorch","backend","is","nn.MSELoss","(",")",".","If","users","use","backend=","''","keras","''","and","3rd","parth","model","this","parameter","will","be","ignored",".",":","param","optimizer",":","String","or","pyTorch","optimizer","creator","function","or","tf.keras","optimizer","instance",".","If","users","use","backend=","''","keras","''","and","3rd","parth","model",",","this","parameter","will","be","ignored",".",":","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","bigdl.orca.automl.hp","for","more","details",".","The","values","defaults","to","'auto","'",",","which","will","automatically","infer","the","cycle","length","of","each","time","series","and","take","the","mode","of","them",".","The","search","space","will","be","automatically","set","to","hp.randint","(","0.5","*","cycle_length",",","2","*","cycle_length",")",".",":","param","future_seq_len",":","Int","or","List",".","The","number","of","future","steps","to","forecast",".","The","value","defaults","to","1",",","if","`","future_seq_len","`","is","a","list",",","we","will","sample","discretely","according","to","the","input","list",".","1","means","the","timestamp","just","after","the","observed","data",".",":","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","''","or","``","keras","''","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",
      metric_mode=None,
      loss=None,
      optimizer="Adam",
      past_seq_len="auto",
      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 or customized evaluation metric function.
             If string, metric is the evaluation metric name to optimize, e.g. "mse".
             If callable function, it signature should be func(y_true, y_pred), where y_true and
             y_pred are numpy ndarray. The function should return a float value as evaluation
             result.
      :param metric_mode: One of ["min", "max"]. "max" means greater metric value is better.
             You have to specify metric_mode if you use a customized metric function.
             You don't have to specify metric_mode if you use the built-in metric in
             bigdl.orca.automl.metrics.Evaluator.
      :param loss: String or pytorch loss instance or pytorch loss creator function. The
             default loss function for pytorch backend is nn.MSELoss(). If users use
             backend="keras" and 3rd parth model this parameter will be ignored.
      :param optimizer: String or pyTorch optimizer creator function or tf.keras optimizer
             instance. If users use backend="keras" and 3rd parth model, this parameter will
             be ignored.
      :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 bigdl.orca.automl.hp for more
             details. The values defaults to 'auto', which will automatically infer the
             cycle length of each time series and take the mode of them. The search space
             will be automatically set to hp.randint(0.5*cycle_length, 2*cycle_length).
      :param future_seq_len: Int or List. The number of future steps to forecast. The value
             defaults to 1, if `future_seq_len` is a list, we will sample discretely according
             to the input list. 1 means the timestamp just after the observed data.
      :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" or
                    "keras" 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}".
      """
      from bigdl.nano.utils.common import invalidInputError
  
      # check backend and set default loss MSE
      if backend == "torch":
          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
          )
  
      self._future_seq_len = (
          future_seq_len  # for support future_seq_len list input.
      )
      invalidInputError(
          isinstance(future_seq_len, int)
          or isinstance(future_seq_len, list),
          f"future_seq_len only support int or List, but found"
          f" {type(future_seq_len)}",
      )
      future_seq_len = (
          future_seq_len
          if isinstance(future_seq_len, int)
          else len(future_seq_len)
      )
  
      # 3rd party model
      if isinstance(model, types.FunctionType):
          from bigdl.orca.automl.auto_estimator import AutoEstimator
  
          if backend == "torch":
              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,
              )
          if backend == "keras":
              self.model = AutoEstimator.from_keras(
                  model_creator=model,
                  logs_dir=logs_dir,
                  resources_per_trial={"cpu": cpus_per_trial},
                  name=name,
              )
          self.metric = metric
          self.metric_mode = metric_mode
          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
  
      # built-in model
      if isinstance(model, str):
          # 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,
                  "metric_mode": metric_mode,
                  "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.backend = backend
      self._scaler = None
      self._scaler_index = None
  
file_path: BigDL/python/chronos/src/bigdl/chronos/autots/autotsestimator.py
imports: import types
  from bigdl.orca.automl.auto_estimator import AutoEstimator
  from bigdl.chronos.data import TSDataset
  import bigdl.orca.automl.hp
  from bigdl.chronos.autots.model import AutoModelFactory
  from bigdl.chronos.autots.utils import recalculate_n_sampling
label_desc: Use image node_id 1 to create a new AutoTSEstimator object  with example: obj = AutoTSEstimator(model, search_space, metric, metric_mode, 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)