class_docstr: Example:
      >>> #The dataset to detect is y
      >>> y = numpy.array(...)
      >>> ad = AEDetector(roll_len=24)
      >>> ad.fit(y)
      >>> anomaly_scores = ad.score()
      >>> anomaly_indexes = ad.anomaly_indexes()
class_docstr_tok: ["Example",":",">",">",">","#","The","dataset","to","detect","is","y",">",">",">","y","=","numpy.array","(","...",")",">",">",">","ad","=","AEDetector","(","roll_len=24",")",">",">",">","ad.fit","(","y",")",">",">",">","anomaly_scores","=","ad.score","(",")",">",">",">","anomaly_indexes","=","ad.anomaly_indexes","(",")"]
docstr: Fit the model.
  
  :param y: the input time series. y must be 1-D numpy array.
docstr_tok: ["Fit","the","model",".",":","param","y",":","the","input","time","series",".","y","must","be","1-D","numpy","array","."]
code: def fit(self, y):
      """
      Fit the model.
  
      :param y: the input time series. y must be 1-D numpy array.
      """
      self.check_data(y)
      self.anomaly_scores_ = np.zeros_like(y)
  
      if self.roll_len != 0:
          # roll the time series to create sub sequences
          y = roll_arr(y, self.roll_len)
          self.check_rolled(y)
      else:
          y = y.reshape(1, -1)
          self.check_rolled(y)
      y = scale_arr(y)
  
      if self.backend == "keras":
          ae_model = create_tf_model(
              self.compress_rate, len(y[0]), lr=self.lr
          )
          ae_model.fit(
              y,
              y,
              batch_size=self.batch_size,
              epochs=self.epochs,
              verbose=self.verbose,
          )
          y_pred = ae_model.predict(y)
      elif self.backend == "torch":
          import torch.optim as optim
          import torch.nn as nn
          import torch
          from torch.utils.data import TensorDataset, DataLoader
  
          ae_model = create_torch_model(self.compress_rate, len(y[0]))
          optimizer = optim.Adadelta(ae_model.parameters(), lr=self.lr)
          criterion = nn.BCELoss()
          y = torch.from_numpy(y).float()
          if y.ndim == 1:
              y = y.reshape(-1, 1)
          train_loader = DataLoader(
              TensorDataset(y, y),
              batch_size=int(self.batch_size),
              shuffle=True,
          )
          for epochs in range(self.epochs):
              for x_batch, y_batch in train_loader:
                  optimizer.zero_grad()
                  yhat = ae_model(x_batch)
                  loss = criterion(yhat, y_batch)
                  loss.backward()
                  optimizer.step()
          y_pred_list = []
          for x_batch, y_batch in train_loader:
              y_pred_list.append(ae_model(x_batch).detach().numpy())
          y_pred = np.concatenate(y_pred_list, axis=0)
      else:
          from bigdl.nano.utils.common import invalidInputError
  
          invalidInputError(
              False, "backend type can only be 'keras' or 'torch'"
          )
      # calculate the recon err for each data point in rolled array
      self.recon_err = abs(y - y_pred)
      # calculate the (aggregated) recon err for each sub sequence
      if self.roll_len != 0:
          self.recon_err_subseq = np.linalg.norm(self.recon_err, axis=1)
  
file_path: BigDL/python/chronos/src/bigdl/chronos/detector/anomaly/ae_detector.py
imports: from bigdl.chronos.detector.anomaly.abstract import AnomalyDetector
  from bigdl.chronos.detector.anomaly.util import roll_arr, scale_arr
  import numpy
label_desc: Use image node_id 4 for calling the AEDetector obj's underlying member method code with example usage: obj.fit(y) without return types