docstr: Forecasts values for `n` time steps after the end of the series.
  
  Parameters
  ----------
  n : int
      Forecast horizon - the number of time steps after the end of the series for which to produce predictions.
  series : TimeSeries or list of TimeSeries, optional
      Optionally, one or several input `TimeSeries`, representing the history of the target series whose future
      is to be predicted. If specified, the method returns the forecasts of these series. Otherwise, the method
      returns the forecast of the (single) training series.
  past_covariates : TimeSeries or list of TimeSeries, optional
      Optionally, the past-observed covariates series needed as inputs for the model.
      They must match the covariates used for training in terms of dimension and type.
  future_covariates : TimeSeries or list of TimeSeries, optional
      Optionally, the future-known covariates series needed as inputs for the model.
      They must match the covariates used for training in terms of dimension and type.
  num_samples : int, default: 1
      Number of times a prediction is sampled from a probabilistic model. Should be set to 1
      for deterministic models.
  verbose
      Optionally, whether to print progress.
  predict_likelihood_parameters
      If set to `True`, the model predict the parameters of its Likelihood parameters instead of the target. Only
      supported for probabilistic models with a likelihood, `num_samples = 1` and `n<=output_chunk_length`.
      Default: ``False``
  **kwargs : dict, optional
      Additional keyword arguments passed to the `predict` method of the model. Only works with
      univariate target series.
  show_warnings
      Optionally, control whether warnings are shown. Not effective for all models.
docstr_tok: ["Forecasts","values","for","`","n","`","time","steps","after","the","end","of","the","series",".","Parameters","--","--","--","--","--","n",":","int","Forecast","horizon","-","the","number","of","time","steps","after","the","end","of","the","series","for","which","to","produce","predictions",".","series",":","TimeSeries","or","list","of","TimeSeries",",","optional","Optionally",",","one","or","several","input","`","TimeSeries","`",",","representing","the","history","of","the","target","series","whose","future","is","to","be","predicted",".","If","specified",",","the","method","returns","the","forecasts","of","these","series",".","Otherwise",",","the","method","returns","the","forecast","of","the","(","single",")","training","series",".","past_covariates",":","TimeSeries","or","list","of","TimeSeries",",","optional","Optionally",",","the","past-observed","covariates","series","needed","as","inputs","for","the","model",".","They","must","match","the","covariates","used","for","training","in","terms","of","dimension","and","type",".","future_covariates",":","TimeSeries","or","list","of","TimeSeries",",","optional","Optionally",",","the","future-known","covariates","series","needed","as","inputs","for","the","model",".","They","must","match","the","covariates","used","for","training","in","terms","of","dimension","and","type",".","num_samples",":","int",",","default",":","1","Number","of","times","a","prediction","is","sampled","from","a","probabilistic","model",".","Should","be","set","to","1","for","deterministic","models",".","verbose","Optionally",",","whether","to","print","progress",".","predict_likelihood_parameters","If","set","to","`","True","`",",","the","model","predict","the","parameters","of","its","Likelihood","parameters","instead","of","the","target",".","Only","supported","for","probabilistic","models","with","a","likelihood",",","`","num_samples","=","1","`","and","`","n","<","=output_chunk_length","`",".","Default",":","``","False","``","*","*","kwargs",":","dict",",","optional","Additional","keyword","arguments","passed","to","the","`","predict","`","method","of","the","model",".","Only","works","with","univariate","target","series",".","show_warnings","Optionally",",","control","whether","warnings","are","shown",".","Not","effective","for","all","models","."]
code: def predict(
      self,
      n: int,
      series: Optional[Union[TimeSeries, Sequence[TimeSeries]]] = None,
      past_covariates: Optional[
          Union[TimeSeries, Sequence[TimeSeries]]
      ] = None,
      future_covariates: Optional[
          Union[TimeSeries, Sequence[TimeSeries]]
      ] = None,
      num_samples: int = 1,
      verbose: bool = False,
      predict_likelihood_parameters: bool = False,
      show_warnings: bool = True,
      **kwargs,
  ) -> Union[TimeSeries, Sequence[TimeSeries]]:
      """Forecasts values for `n` time steps after the end of the series.
  
      Parameters
      ----------
      n : int
          Forecast horizon - the number of time steps after the end of the series for which to produce predictions.
      series : TimeSeries or list of TimeSeries, optional
          Optionally, one or several input `TimeSeries`, representing the history of the target series whose future
          is to be predicted. If specified, the method returns the forecasts of these series. Otherwise, the method
          returns the forecast of the (single) training series.
      past_covariates : TimeSeries or list of TimeSeries, optional
          Optionally, the past-observed covariates series needed as inputs for the model.
          They must match the covariates used for training in terms of dimension and type.
      future_covariates : TimeSeries or list of TimeSeries, optional
          Optionally, the future-known covariates series needed as inputs for the model.
          They must match the covariates used for training in terms of dimension and type.
      num_samples : int, default: 1
          Number of times a prediction is sampled from a probabilistic model. Should be set to 1
          for deterministic models.
      verbose
          Optionally, whether to print progress.
      predict_likelihood_parameters
          If set to `True`, the model predict the parameters of its Likelihood parameters instead of the target. Only
          supported for probabilistic models with a likelihood, `num_samples = 1` and `n<=output_chunk_length`.
          Default: ``False``
      **kwargs : dict, optional
          Additional keyword arguments passed to the `predict` method of the model. Only works with
          univariate target series.
      show_warnings
          Optionally, control whether warnings are shown. Not effective for all models.
      """
      if series is None:
          # then there must be a single TS, and that was saved in super().fit as self.training_series
          if self.training_series is None:
              raise_log(
                  ValueError(
                      "Input `series` must be provided. This is the result either from fitting on multiple series, "
                      "or from not having fit the model yet."
                  ),
                  logger,
              )
          series = self.training_series
  
      called_with_single_series = (
          True if isinstance(series, TimeSeries) else False
      )
  
      # guarantee that all inputs are either list of TimeSeries or None
      series = series2seq(series)
  
      if (
          past_covariates is None
          and self.past_covariate_series is not None
      ):
          past_covariates = [self.past_covariate_series] * len(series)
      if (
          future_covariates is None
          and self.future_covariate_series is not None
      ):
          future_covariates = [self.future_covariate_series] * len(
              series
          )
      past_covariates = series2seq(past_covariates)
      future_covariates = series2seq(future_covariates)
  
      self._verify_static_covariates(series[0].static_covariates)
  
      # encoders are set when calling fit(), but not when calling fit_from_dataset()
      # when covariates are loaded from model, they already contain the encodings: this is not a problem as the
      # encoders regenerate the encodings
      if self.encoders.encoding_available:
          (
              past_covariates,
              future_covariates,
          ) = self.generate_predict_encodings(
              n=n,
              series=series,
              past_covariates=past_covariates,
              future_covariates=future_covariates,
          )
      super().predict(
          n,
          series,
          past_covariates,
          future_covariates,
          num_samples,
          verbose,
          predict_likelihood_parameters,
          show_warnings,
      )
  
      # check that the input sizes of the target series and covariates match
      pred_input_dim = {
          "target": series[0].width,
          "past": past_covariates[0].width if past_covariates else None,
          "future": future_covariates[0].width
          if future_covariates
          else None,
      }
      raise_if_not(
          pred_input_dim == self.input_dim,
          f"The number of components of the target series and the covariates provided for prediction doesn't "
          f"match the number of components of the target series and the covariates this model has been "
          f"trained on.\n"
          f"Provided number of components for prediction: {pred_input_dim}\n"
          f"Provided number of components for training: {self.input_dim}",
      )
  
      # prediction preprocessing
      covariates = {
          "past": (past_covariates, self.lags.get("past")),
          "future": (future_covariates, self.lags.get("future")),
      }
  
      # prepare one_shot shift and step
      if self.multi_models:
          shift = 0
          step = self.output_chunk_length
      else:
          shift = self.output_chunk_length - 1
          step = 1
  
      # dictionary containing covariate data over time span required for prediction
      covariate_matrices = {}
      # dictionary containing covariate lags relative to minimum covariate lag
      relative_cov_lags = {}
      for cov_type, (covs, lags) in covariates.items():
          if covs is None:
              continue
  
          relative_cov_lags[cov_type] = np.array(lags) - lags[0]
          covariate_matrices[cov_type] = []
          for idx, (ts, cov) in enumerate(zip(series, covs)):
              # how many steps to go back from end of target series for start of covariates
              steps_back = -(min(lags) + 1) + shift
              lags_diff = max(lags) - min(lags) + 1
              # over how many steps the covariates range
              n_steps = (
                  lags_diff
                  + max(0, n - self.output_chunk_length)
                  + shift
              )
  
              # calculate first and last required covariate time steps
              start_ts = ts.end_time() - ts.freq * steps_back
              end_ts = start_ts + ts.freq * (n_steps - 1)
  
              # check for sufficient covariate data
              if not (
                  cov.start_time() <= start_ts
                  and cov.end_time() >= end_ts
              ):
                  raise_log(
                      ValueError(
                          f"The corresponding {cov_type}_covariate of the series at index {idx} isn't sufficiently "
                          f"long. Given horizon `n={n}`, `min(lags_{cov_type}_covariates)={lags[0]}`, "
                          f"`max(lags_{cov_type}_covariates)={lags[-1]}` and "
                          f"`output_chunk_length={self.output_chunk_length}`, the {cov_type}_covariate has to range "
                          f"from {start_ts} until {end_ts} (inclusive), but it ranges only from {cov.start_time()} "
                          f"until {cov.end_time()}."
                      ),
                      logger=logger,
                  )
  
              # use slice() instead of [] as for integer-indexed series [] does not act on time index
              # for range indexes, we make the end timestamp inclusive here
              end_ts = (
                  end_ts + ts.freq if ts.has_range_index else end_ts
              )
              covariate_matrices[cov_type].append(
                  cov.slice(start_ts, end_ts).values(copy=False)
              )
  
          covariate_matrices[cov_type] = np.stack(
              covariate_matrices[cov_type]
          )
  
      series_matrix = None
      if "target" in self.lags:
          series_matrix = np.stack(
              [
                  ts.values(copy=False)[
                      self.lags["target"][0] - shift :, :
                  ]
                  for ts in series
              ]
          )
  
      # repeat series_matrix to shape (num_samples * num_series, n_lags, n_components)
      # [series 0 sample 0, series 0 sample 1, ..., series n sample k]
      series_matrix = np.repeat(series_matrix, num_samples, axis=0)
  
      # same for covariate matrices
      for cov_type, data in covariate_matrices.items():
          covariate_matrices[cov_type] = np.repeat(
              data, num_samples, axis=0
          )
      # prediction
      predictions = []
      last_step_shift = 0
  
      # t_pred indicates the number of time steps after the first prediction
      for t_pred in range(0, n, step):
          # in case of autoregressive forecast `(t_pred > 0)` and if `n` is not a round multiple of `step`,
          # we have to step back `step` from `n` in the last iteration
          if 0 < n - t_pred < step and t_pred > 0:
              last_step_shift = t_pred - (n - step)
              t_pred = n - step
  
          np_X = []
          # retrieve target lags
          if "target" in self.lags:
              if predictions:
                  series_matrix = np.concatenate(
                      [series_matrix, predictions[-1]], axis=1
                  )
              # component-wise lags
              if "target" in self.component_lags:
                  tmp_X = [
                      series_matrix[
                          :,
                          [
                              lag - (shift + last_step_shift)
                              for lag in comp_lags
                          ],
                          comp_i,
                      ]
                      for comp_i, (comp, comp_lags) in enumerate(
                          self.component_lags["target"].items()
                      )
                  ]
                  # values are grouped by component
                  np_X.append(
                      np.concatenate(tmp_X, axis=1).reshape(
                          len(series) * num_samples, -1
                      )
                  )
              else:
                  # values are grouped by lags
                  np_X.append(
                      series_matrix[
                          :,
                          [
                              lag - (shift + last_step_shift)
                              for lag in self.lags["target"]
                          ],
                      ].reshape(len(series) * num_samples, -1)
                  )
          # retrieve covariate lags, enforce order (dict only preserves insertion order for python 3.6+)
          for cov_type in ["past", "future"]:
              if cov_type in covariate_matrices:
                  # component-wise lags
                  if cov_type in self.component_lags:
                      tmp_X = [
                          covariate_matrices[cov_type][
                              :,
                              np.array(comp_lags)
                              - self.lags[cov_type][0]
                              + t_pred,
                              comp_i,
                          ]
                          for comp_i, (comp, comp_lags) in enumerate(
                              self.component_lags[cov_type].items()
                          )
                      ]
                      np_X.append(
                          np.concatenate(tmp_X, axis=1).reshape(
                              len(series) * num_samples, -1
                          )
                      )
                  else:
                      np_X.append(
                          covariate_matrices[cov_type][
                              :, relative_cov_lags[cov_type] + t_pred
                          ].reshape(len(series) * num_samples, -1)
                      )
  
          # concatenate retrieved lags
          X = np.concatenate(np_X, axis=1)
          # Need to split up `X` into three equally-sized sub-blocks
          # corresponding to each timeseries in `series`, so that
          # static covariates can be added to each block; valid since
          # each block contains same number of observations:
          X_blocks = np.split(X, len(series), axis=0)
          X_blocks, _ = add_static_covariates_to_lagged_data(
              X_blocks,
              series,
              uses_static_covariates=self.uses_static_covariates,
              last_shape=self._static_covariates_shape,
          )
          X = np.concatenate(X_blocks, axis=0)
  
          # X has shape (n_series * n_samples, n_regression_features)
          prediction = self._predict_and_sample(
              X, num_samples, predict_likelihood_parameters, **kwargs
          )
          # prediction shape (n_series * n_samples, output_chunk_length, n_components)
          # append prediction to final predictions
          predictions.append(prediction[:, last_step_shift:])
  
      # concatenate and use first n points as prediction
      predictions = np.concatenate(predictions, axis=1)[:, :n]
  
      # bring into correct shape: (n_series, output_chunk_length, n_components, n_samples)
      predictions = np.moveaxis(
          predictions.reshape(len(series), num_samples, n, -1), 1, -1
      )
  
      # build time series from the predicted values starting after end of series
      predictions = [
          self._build_forecast_series(
              points_preds=row,
              input_series=input_tgt,
              custom_components=self._likelihood_components_names(
                  input_tgt
              )
              if predict_likelihood_parameters
              else None,
              with_static_covs=False
              if predict_likelihood_parameters
              else True,
              with_hierarchy=False
              if predict_likelihood_parameters
              else True,
          )
          for idx_ts, (row, input_tgt) in enumerate(
              zip(predictions, series)
          )
      ]
  
      return (
          predictions[0] if called_with_single_series else predictions
      )
  
imports: from collections import OrderedDict
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import numpy
  import pandas
  from sklearn.linear_model import LinearRegression
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
  from darts.models.forecasting.forecasting_model import GlobalForecastingModel
  from darts.timeseries import TimeSeries
  from darts.utils.data.tabularization import add_static_covariates_to_lagged_data, create_lagged_component_names, create_lagged_training_data
  from darts.utils.historical_forecasts import _check_optimizable_historical_forecasts_global_models, _optimized_historical_forecasts_all_points, _optimized_historical_forecasts_last_points_only, _process_historical_forecast_input
  from darts.utils.multioutput import MultiOutputRegressor
  from darts.utils.utils import _check_quantiles, get_single_series, seq2series, series2seq
label_desc: Use image node_id 14 for calling the RegressionModel obj's underlying member method code with example usage: obj.predict(n, series, past_covariates, future_covariates, num_samples, verbose, predict_likelihood_parameters, show_warnings) and returns: unknown