class_docstr: Parallelization is based predominantly on [1]. Also similar to [2]
  
  Ref:
  [1] https://github.com/scikit-learn/scikit-learn/blob/0.24.1/sklearn/model_selection/_search.py#L795
  [2] https://github.com/scikit-optimize/scikit-optimize/blob/v0.8.1/skopt/searchcv.py#L410
class_docstr_tok: ["Parallelization","is","based","predominantly","on","[","1","]",".","Also","similar","to","[","2","]","Ref",":","[","1","]","https",":","\/\/github.com\/scikit-learn\/scikit-learn\/blob\/0.24.1\/sklearn\/model_selection\/_search.py","#","L795","[","2","]","https",":","\/\/github.com\/scikit-optimize\/scikit-optimize\/blob\/v0.8.1\/skopt\/searchcv.py","#","L410"]
docstr: Run fit with all sets of parameters.
  
  Parameters
  ----------
  y : pd.Series
      Target variable values that need to be used for forecasting. This should be the
      untransformed (original) values. Transformation will happen in the fitting process.
  X : Optional[Union[pd.Series, pd.DataFrame]]
      Exogenous Variable values to be used for forecasting. This should be the
      untransformed (original) values. Transformation will happen in the fitting process,
      by default None
  additional_scorer_kwargs: Dict[str, Any]
      Additional scorer kwargs such as {`sp`:12} required by metrics like MASE
  **fit_params: Dict[str, Any]
      Parameters passed to the ``fit`` method of the estimator
  
  Returns
  -------
  BaseGridSearch
      Grid Search Object returned to allow chaining
  
  Raises
  ------
  ValueError
      When any of the following is True
      (1) Metric can not be found
      (2) No candidate provided in search
      (3) CV Iterator is empty
docstr_tok: ["Run","fit","with","all","sets","of","parameters",".","Parameters","--","--","--","--","--","y",":","pd.Series","Target","variable","values","that","need","to","be","used","for","forecasting",".","This","should","be","the","untransformed","(","original",")","values",".","Transformation","will","happen","in","the","fitting","process",".","X",":","Optional","[","Union","[","pd.Series",",","pd.DataFrame","]","]","Exogenous","Variable","values","to","be","used","for","forecasting",".","This","should","be","the","untransformed","(","original",")","values",".","Transformation","will","happen","in","the","fitting","process",",","by","default","None","additional_scorer_kwargs",":","Dict","[","str",",","Any","]","Additional","scorer","kwargs","such","as","{","`","sp","`",":12","}","required","by","metrics","like","MASE","*","*","fit_params",":","Dict","[","str",",","Any","]","Parameters","passed","to","the","``","fit","``","method","of","the","estimator","Returns","--","--","--","-","BaseGridSearch","Grid","Search","Object","returned","to","allow","chaining","Raises","--","--","--","ValueError","When","any","of","the","following","is","True","(","1",")","Metric","can","not","be","found","(","2",")","No","candidate","provided","in","search","(","3",")","CV","Iterator","is","empty"]
code: def fit(
      self,
      y: pd.Series,
      X: Optional[pd.DataFrame] = None,
      additional_scorer_kwargs: Optional[Dict[str, Any]] = None,
      **fit_params,
  ) -> "BaseGridSearch":
      """Run fit with all sets of parameters.
  
      Parameters
      ----------
      y : pd.Series
          Target variable values that need to be used for forecasting. This should be the
          untransformed (original) values. Transformation will happen in the fitting process.
      X : Optional[Union[pd.Series, pd.DataFrame]]
          Exogenous Variable values to be used for forecasting. This should be the
          untransformed (original) values. Transformation will happen in the fitting process,
          by default None
      additional_scorer_kwargs: Dict[str, Any]
          Additional scorer kwargs such as {`sp`:12} required by metrics like MASE
      **fit_params: Dict[str, Any]
          Parameters passed to the ``fit`` method of the estimator
  
      Returns
      -------
      BaseGridSearch
          Grid Search Object returned to allow chaining
  
      Raises
      ------
      ValueError
          When any of the following is True
          (1) Metric can not be found
          (2) No candidate provided in search
          (3) CV Iterator is empty
      """
      if additional_scorer_kwargs is None:
          additional_scorer_kwargs = {}
  
      y, X = check_y_X(y, X)
  
      # validate cross-validator
      cv = check_cv(self.cv)
      base_pipeline = clone(self.pipeline)
  
      # This checker is sktime specific and only support 1 metric
      # Removing for now since we can have multiple metrics
      # TODO: Add back later if it supports multiple metrics
      # scoring = check_scoring(self.scoring)
      # Multiple metrics supported
      scorers = (
          self.scoring
      )  # Dict[str, Union[str, scorer]]  Not metrics container
      scorers = _get_metrics_dict(scorers)
      refit_metric = self.refit_metric
      if refit_metric not in list(scorers.keys()):
          raise ValueError(
              f"Refit Metric: '{refit_metric}' is not available. ",
              f"Available Values are: {list(scorers.keys())}",
          )
  
      results = {}
      all_candidate_params = []
      all_out = []
  
      def evaluate_candidates(candidate_params):
          candidate_params = list(candidate_params)
          n_candidates = len(candidate_params)
          n_splits = cv.get_n_splits(y)
  
          if self.verbose > 0:
              print(
                  f"Fitting {n_splits} folds for each of {n_candidates} "
                  f"candidates, totalling {n_candidates * n_splits} fits"
              )
  
          parallel = Parallel(
              n_jobs=self.n_jobs,
              verbose=self.verbose,
              pre_dispatch=self.pre_dispatch,
          )
          out = parallel(
              delayed(_fit_and_score)(
                  pipeline=clone(base_pipeline),
                  y=y,
                  X=X,
                  scoring=scorers,
                  train=train,
                  test=test,
                  parameters=parameters,
                  fit_params=fit_params,
                  return_train_score=self.return_train_score,
                  alpha=self.alpha,
                  coverage=self.coverage,
                  error_score=self.error_score,
                  **additional_scorer_kwargs,
              )
              for parameters in candidate_params
              for train, test in get_folds(cv, y)
          )
  
          if len(out) < 1:
              raise ValueError(
                  "No fits were performed. "
                  "Was the CV iterator empty? "
                  "Were there no candidates?"
              )
  
          all_candidate_params.extend(candidate_params)
          all_out.extend(out)
  
          nonlocal results
          results = self._format_results(
              all_candidate_params, scorers, all_out, n_splits
          )
          return results
  
      self._run_search(evaluate_candidates)
  
      self.best_index_ = results["rank_test_%s" % refit_metric].argmin()
      self.best_score_ = results["mean_test_%s" % refit_metric][
          self.best_index_
      ]
      self.best_params_ = results["params"][self.best_index_]
  
      self.best_pipeline_ = clone(base_pipeline).set_params(
          **self.best_params_
      )
  
      if self.refit:
          refit_start_time = time.time()
          self.best_pipeline_.fit(y, X, **fit_params)
          self.refit_time_ = time.time() - refit_start_time
  
      # Store the only scorer not as a dict for single metric evaluation
      self.scorer_ = scorers
  
      self.cv_results_ = results
      self.n_splits_ = cv.get_n_splits(y)
  
      self._is_fitted = True
      return self
  
imports: import time
  import warnings
  from collections import defaultdict
  from functools import partial
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union
  import numpy
  import pandas
  from joblib import Parallel, delayed
  from scipy.stats import rankdata
  from sklearn.base import clone
  from sklearn.metrics._scorer import _PredictScorer
  from sklearn.model_selection import ParameterGrid, ParameterSampler, check_cv
  from sklearn.model_selection._validation import _aggregate_score_dicts
  from sktime.forecasting.compose import ForecastingPipeline
  from sktime.forecasting.model_selection import ExpandingWindowSplitter, SlidingWindowSplitter
  from sktime.utils.validation.forecasting import check_y_X
  from pycaret.internal.logging import get_logger
  from pycaret.utils.generic import _get_metrics_dict, get_function_params
  from pycaret.utils.time_series.forecasting import get_predictions_with_intervals, update_additional_scorer_kwargs
  from pycaret.utils.time_series.forecasting.pipeline import _get_imputed_data
label_desc: Use image node_id 2 for calling the BaseGridSearch obj's underlying member method code with example usage: obj.fit(y, X, additional_scorer_kwargs) and returns: self, results