docstr: Fit the underlying filtering model (if applicable) and the fittable scorers, if any.
  
  Train the filter (if not already fitted and `allow_filter_training` is set to True)
  and the scorer(s) on the given time series.
  
  The filter model will be applied to the given series, and the results will be used
  to train the scorer(s).
  
  Parameters
  ----------
  series
      The (sequence of) series to be trained on.
  allow_model_training
      Boolean value that indicates if the filtering model needs to be fitted on the given series.
      If set to False, the model needs to be already fitted.
      Default: False
  filter_fit_kwargs
      Parameters to be passed on to the filtering model ``fit()`` method.
  
  Returns
  -------
  self
      Fitted model
docstr_tok: ["Fit","the","underlying","filtering","model","(","if","applicable",")","and","the","fittable","scorers",",","if","any",".","Train","the","filter","(","if","not","already","fitted","and","`","allow_filter_training","`","is","set","to","True",")","and","the","scorer","(","s",")","on","the","given","time","series",".","The","filter","model","will","be","applied","to","the","given","series",",","and","the","results","will","be","used","to","train","the","scorer","(","s",")",".","Parameters","--","--","--","--","--","series","The","(","sequence","of",")","series","to","be","trained","on",".","allow_model_training","Boolean","value","that","indicates","if","the","filtering","model","needs","to","be","fitted","on","the","given","series",".","If","set","to","False",",","the","model","needs","to","be","already","fitted",".","Default",":","False","filter_fit_kwargs","Parameters","to","be","passed","on","to","the","filtering","model","``","fit","(",")","``","method",".","Returns","--","--","--","-","self","Fitted","model"]
code: def fit(
      self,
      series: Union[TimeSeries, Sequence[TimeSeries]],
      allow_model_training: bool = False,
      **filter_fit_kwargs,
  ):
      """Fit the underlying filtering model (if applicable) and the fittable scorers, if any.
  
      Train the filter (if not already fitted and `allow_filter_training` is set to True)
      and the scorer(s) on the given time series.
  
      The filter model will be applied to the given series, and the results will be used
      to train the scorer(s).
  
      Parameters
      ----------
      series
          The (sequence of) series to be trained on.
      allow_model_training
          Boolean value that indicates if the filtering model needs to be fitted on the given series.
          If set to False, the model needs to be already fitted.
          Default: False
      filter_fit_kwargs
          Parameters to be passed on to the filtering model ``fit()`` method.
  
      Returns
      -------
      self
          Fitted model
      """
      # TODO: add support for covariates (see eg. Kalman Filter)
  
      raise_if_not(
          type(allow_model_training) is bool,
          f"`allow_filter_training` must be Boolean, found type: {type(allow_model_training)}.",
      )
  
      # checks if model does not need training and all scorer(s) are not fittable
      if not allow_model_training and not self.scorers_are_trainable:
          logger.warning(
              f"The filtering model {self.model.__class__.__name__} is not required to be trained"
              + " because the parameter `allow_filter_training` is set to False, and no scorer"
              + " fittable. The ``.fit()`` function has no effect."
          )
          return
  
      list_series = _to_list(series)
  
      raise_if_not(
          all([isinstance(s, TimeSeries) for s in list_series]),
          "all input `series` must be of type Timeseries.",
      )
  
      if allow_model_training:
          # fit filtering model
          if hasattr(self.filter, "fit"):
              # TODO: check if filter is already fitted (for now fit it regardless -> only Kalman)
              raise_if_not(
                  len(list_series) == 1,
                  f"Filter model {self.model.__class__.__name__} can only be fitted on a"
                  + " single time series, but multiple are provided.",
              )
  
              self.filter.fit(list_series[0], **filter_fit_kwargs)
          else:
              raise ValueError(
                  "`allow_filter_training` was set to True, but the filter"
                  + f" {self.model.__class__.__name__} has no fit() method."
              )
      else:
          # TODO: check if Kalman is fitted or not
          # if not raise error "fit filter before, or set `allow_filter_training` to TRUE"
          pass
  
      if self.scorers_are_trainable:
          list_pred = [
              self.filter.filter(series) for series in list_series
          ]
  
      # fit the scorers
      for scorer in self.scorers:
          if hasattr(scorer, "fit"):
              scorer.fit_from_prediction(list_series, list_pred)
  
      return self
  
file_path: darts/darts/ad/anomaly_model/filtering_am.py
imports: from typing import Dict, Sequence, Union
  from darts.ad.anomaly_model.anomaly_model import AnomalyModel
  from darts.ad.scorers.scorers import AnomalyScorer
  from darts.ad.utils import _assert_same_length, _to_list
  from darts.logging import get_logger, raise_if_not
  from darts.models.filtering.filtering_model import FilteringModel
  from darts.timeseries import TimeSeries
label_desc: Use image node_id 2 for calling the FilteringAnomalyModel obj's underlying member method code with example usage: obj.fit(series, allow_model_training) and returns: self