class_docstr: Automatically find best weights for the ensembled forecasters.
  
  The AutoEnsembleForecaster finds optimal weights for the ensembled forecasters
  using given method or a meta-model (regressor) .
  The regressor has to be sklearn-like and needs to have either an attribute
  ``feature_importances_`` or ``coef_``, as this is used as weights.
  Regressor can also be a sklearn.Pipeline.
  
  Parameters
  ----------
  forecasters : list of (str, estimator) tuples
      Estimators to apply to the input series.
  method : str, optional, default="feature-importance"
      Strategy used to compute weights. Available choices:
  
      - feature-importance:
          use the ``feature_importances_`` or ``coef_`` from
          given ``regressor`` as optimal weights.
      - inverse-variance:
          use the inverse variance of the forecasting error
          (based on the internal train-test-split) to compute optimal
          weights, a given ``regressor`` will be omitted.
  regressor : sklearn-like regressor, optional, default=None.
      Used to infer optimal weights from coefficients (linear models) or from
      feature importance scores (decision tree-based models). If None, then
      a GradientBoostingRegressor(max_depth=5) is used.
      The regressor can also be a sklearn.Pipeline().
  test_size : int or float, optional, default=None
      Used to do an internal temporal_train_test_split(). The test_size data
      will be the endog data of the regressor and it is the most recent data.
      The exog data of the regressor are the predictions from the temporarily
      trained ensemble models. If None, it will be set to 0.25.
  random_state : int, RandomState instance or None, default=None
      Used to set random_state of the default regressor.
  n_jobs : int or None, optional, default=None
      The number of jobs to run in parallel for fit. None means 1 unless
      in a joblib.parallel_backend context.
      -1 means using all processors.
  
  Attributes
  ----------
  regressor_ : sklearn-like regressor
      Fitted regressor.
  weights_ : np.array
      The weights based on either ``regressor.feature_importances_`` or
      ``regressor.coef_`` values.
  
  See Also
  --------
  EnsembleForecaster
  
  Examples
  --------
  >>> from sktime.forecasting.compose import AutoEnsembleForecaster
  >>> from sktime.forecasting.naive import NaiveForecaster
  >>> from sktime.forecasting.trend import PolynomialTrendForecaster
  >>> from sktime.datasets import load_airline
  >>> y = load_airline()
  >>> forecasters = [
  ...     ("trend", PolynomialTrendForecaster()),
  ...     ("naive", NaiveForecaster()),
  ... ]
  >>> forecaster = AutoEnsembleForecaster(forecasters=forecasters)
  >>> forecaster.fit(y=y, fh=[1,2,3])
  AutoEnsembleForecaster(...)
  >>> y_pred = forecaster.predict()
class_docstr_tok: ["Automatically","find","best","weights","for","the","ensembled","forecasters",".","The","AutoEnsembleForecaster","finds","optimal","weights","for","the","ensembled","forecasters","using","given","method","or","a","meta-model","(","regressor",")",".","The","regressor","has","to","be","sklearn-like","and","needs","to","have","either","an","attribute","``","feature_importances_","``","or","``","coef_","``",",","as","this","is","used","as","weights",".","Regressor","can","also","be","a","sklearn.Pipeline",".","Parameters","--","--","--","--","--","forecasters",":","list","of","(","str",",","estimator",")","tuples","Estimators","to","apply","to","the","input","series",".","method",":","str",",","optional",",","default=","''","feature-importance","''","Strategy","used","to","compute","weights",".","Available","choices",":","-","feature-importance",":","use","the","``","feature_importances_","``","or","``","coef_","``","from","given","``","regressor","``","as","optimal","weights",".","-","inverse-variance",":","use","the","inverse","variance","of","the","forecasting","error","(","based","on","the","internal","train-test-split",")","to","compute","optimal","weights",",","a","given","``","regressor","``","will","be","omitted",".","regressor",":","sklearn-like","regressor",",","optional",",","default=None",".","Used","to","infer","optimal","weights","from","coefficients","(","linear","models",")","or","from","feature","importance","scores","(","decision","tree-based","models",")",".","If","None",",","then","a","GradientBoostingRegressor","(","max_depth=5",")","is","used",".","The","regressor","can","also","be","a","sklearn.Pipeline","(",")",".","test_size",":","int","or","float",",","optional",",","default=None","Used","to","do","an","internal","temporal_train_test_split","(",")",".","The","test_size","data","will","be","the","endog","data","of","the","regressor","and","it","is","the","most","recent","data",".","The","exog","data","of","the","regressor","are","the","predictions","from","the","temporarily","trained","ensemble","models",".","If","None",",","it","will","be","set","to","0.25.","random_state",":","int",",","RandomState","instance","or","None",",","default=None","Used","to","set","random_state","of","the","default","regressor",".","n_jobs",":","int","or","None",",","optional",",","default=None","The","number","of","jobs","to","run","in","parallel","for","fit",".","None","means","1","unless","in","a","joblib.parallel_backend","context",".","-1","means","using","all","processors",".","Attributes","--","--","--","--","--","regressor_",":","sklearn-like","regressor","Fitted","regressor",".","weights_",":","np.array","The","weights","based","on","either","``","regressor.feature_importances_","``","or","``","regressor.coef_","``","values",".","See","Also","--","--","--","--","EnsembleForecaster","Examples","--","--","--","--",">",">",">","from","sktime.forecasting.compose","import","AutoEnsembleForecaster",">",">",">","from","sktime.forecasting.naive","import","NaiveForecaster",">",">",">","from","sktime.forecasting.trend","import","PolynomialTrendForecaster",">",">",">","from","sktime.datasets","import","load_airline",">",">",">","y","=","load_airline","(",")",">",">",">","forecasters","=","[","...","(","``","trend","''",",","PolynomialTrendForecaster","(",")",")",",","...","(","``","naive","''",",","NaiveForecaster","(",")",")",",","...","]",">",">",">","forecaster","=","AutoEnsembleForecaster","(","forecasters=forecasters",")",">",">",">","forecaster.fit","(","y=y",",","fh=","[","1,2,3","]",")","AutoEnsembleForecaster","(","...",")",">",">",">","y_pred","=","forecaster.predict","(",")"]
docstr: Fit to training data.
  
  Parameters
  ----------
  y : pd.Series
      Target time series to which to fit the forecaster.
  fh : int, list or np.array, optional, default=None
      The forecasters horizon with the steps ahead to to predict.
  X : pd.DataFrame, optional, default=None
      Exogenous variables are ignored.
  
  Returns
  -------
  self : returns an instance of self.
docstr_tok: ["Fit","to","training","data",".","Parameters","--","--","--","--","--","y",":","pd.Series","Target","time","series","to","which","to","fit","the","forecaster",".","fh",":","int",",","list","or","np.array",",","optional",",","default=None","The","forecasters","horizon","with","the","steps","ahead","to","to","predict",".","X",":","pd.DataFrame",",","optional",",","default=None","Exogenous","variables","are","ignored",".","Returns","--","--","--","-","self",":","returns","an","instance","of","self","."]
code: def _fit(self, y, X, fh):
      """Fit to training data.
  
      Parameters
      ----------
      y : pd.Series
          Target time series to which to fit the forecaster.
      fh : int, list or np.array, optional, default=None
          The forecasters horizon with the steps ahead to to predict.
      X : pd.DataFrame, optional, default=None
          Exogenous variables are ignored.
  
      Returns
      -------
      self : returns an instance of self.
      """
      _, forecasters = self._check_forecasters()
  
      # get training data for meta-model
      if X is not None:
          y_train, y_test, X_train, X_test = temporal_train_test_split(
              y, X, test_size=self.test_size
          )
      else:
          y_train, y_test = temporal_train_test_split(
              y, test_size=self.test_size
          )
          X_train, X_test = None, None
  
      # fit ensemble models
      fh_test = ForecastingHorizon(y_test.index, is_relative=False)
      self._fit_forecasters(forecasters, y_train, X_train, fh_test)
  
      if self.method == "feature-importance":
          self.regressor_ = check_regressor(
              regressor=self.regressor, random_state=self.random_state
          )
          X_meta = pd.concat(
              self._predict_forecasters(fh_test, X_test), axis=1
          )
          X_meta.columns = pd.RangeIndex(len(X_meta.columns))
  
          # fit meta-model (regressor) on predictions of ensemble models
          # with y_test as endog/target
          self.regressor_.fit(X=X_meta, y=y_test)
  
          # check if regressor is a sklearn.Pipeline
          if isinstance(self.regressor_, Pipeline):
              # extract regressor from pipeline to access its attributes
              self.weights_ = _get_weights(self.regressor_.steps[-1][1])
          else:
              self.weights_ = _get_weights(self.regressor_)
  
      elif self.method == "inverse-variance":
          # get in-sample forecasts
          if self.regressor is not None:
              Warning(
                  f"regressor will not be used because ${self.method} is set."
              )
          inv_var = np.array(
              [
                  1 / np.var(y_test - y_pred_test)
                  for y_pred_test in self._predict_forecasters(
                      fh_test, X_test
                  )
              ]
          )
          # standardize the inverse variance
          self.weights_ = list(inv_var / np.sum(inv_var))
      else:
          raise NotImplementedError(
              f"Given method {self.method} does not exist, "
              f"please provide valid method parameter."
          )
  
      self._fit_forecasters(forecasters, y, X, fh)
      return self
  
imports: import numpy
  import pandas
  from scipy.stats import gmean
  from sklearn.pipeline import Pipeline
  from sktime.forecasting.base import ForecastingHorizon
  from sktime.forecasting.base._meta import _HeterogenousEnsembleForecaster
  from sktime.split import temporal_train_test_split
  from sktime.utils.stats import _weighted_geometric_mean, _weighted_max, _weighted_median, _weighted_min
  from sktime.utils.validation.forecasting import check_regressor
label_desc: Use image node_id 2 for calling the AutoEnsembleForecaster obj's underlying member method code with example usage: obj._fit(y, X, fh) and returns: self