class_docstr: The Multistage Forecast Estimator class.
  Implements the Multistage forecast method.
  
  The Multistage forecast method allows users to fit multiple stages of
  models with each stage in the following fashions:
  
      (1) subseting: take a subset of data from the end of training data;
      (2) aggregation: aggregate the subset of data into desired frequency;
      (3) training: train a model with the desired estimator and parameters.
  
  Users can just use one stage model to train on a subset/aggregation of the original data,
  or can specify multiple stages, where the later stages will be trained on the fitted
  residuals of the previous stages.
  
  This can significantly speed up the training process if the original data is long
  and in fine granularity.
  
  Notes
  -----
  The following assumptions or special implementations are made in this class:
  
      - The actual ``fit_length``, the length of data where the fitted values are calculated,
        is the longer of ``train_length`` and ``fit_length``. The reason is that there is no
        benefit of calculating a shorter period of fitted values. The fitted values are already
        available during training (in Silverkite) so there is no loss to calculate fitted values
        on a super set of the training data.
      - The estimator sorts the ``model_configs`` according to the ``train_length`` in descending order.
        The corresponding aggregation frequency, aggregation function, fit length,
        estimator and parameters will be sorted accordingly.
        This is to ensure that we have enough data to use from the previous model
        when we fit the next model.
      - When calculating the length of training data, the length of past df, etc,
        the actual length used may include 1 more period to avoid missing timestamps.
        For example, for an AR order of 5, you may see the length of ``past_df`` to be 6;
        or for a train length of "365D", you may see the actual length to be 366.
        This is expected, just to avoid potential missing timestamps after dropping
        incomplete aggregation periods.
      - Since the models in each stage may not fit on the entire training data,
        there could be periods where fitted values are not calculated.
        Leading fitted values in the training period may be NA.
        These values are ignored when computing evaluation metrics.
  
  Attributes
  ----------
  model_configs : `list` [`MultistageForecastModelConfig`]
      A list of model configs for Multistage Forecast estimator,
      representing the stages in the model.
  forecast_horizon : `int`
      The forecast horizon on the original data frequency.
  freq : `str` or None
      The frequency of the original data.
  train_lengths : `list` [`str`] or None
      A list of training data lengths for the models.
  fit_lengths : `list` [`str`] or None
      A list of fitting data lengths for the models.
  agg_funcs : `list` [`str` or Callable] or None
      A list of aggregation functions for the models.
  agg_freqs : `list` [`str`] or None
      A list of aggregation frequencies for the models.
  estimators : `list` [`BaseForecastEstimator`] or None
      A list of estimators used in the models.
  estimator_params : `list` [`dict` or None] or None
      A list of estimator parameters for the estimators.
  train_lengths_in_seconds : `list` [`int`] or None
      The list of training lengths in seconds.
  fit_lengths_in_seconds: : `list` [`int`] or None
      The list of fitting lengths in seconds.
      If the original ``fit_length`` is None or is shorter than the corresponding
      ``train_length``, it will be replaced by the corresponding ``train_length``.
  max_ar_orders : `list` [`int`] or None
      A list of maximum AR orders in the models.
  data_freq_in_seconds : `int` or None
      The data frequency in seconds.
  num_points_per_agg_freqs : `list` [`int`] or None
      Number of data points in each aggregation frequency.
  models : `list` [`BaseForecastEstimator`]
      The list of model instances.
  fit_df : `pandas.DataFrame` or None
      The prediction df.
  train_end : `pandas.Timestamp` or None
      The train end timestamp.
  forecast_horizons : `list` [`int`]
      The list of forecast horizons for all models in terms of the aggregated frequencies.
class_docstr_tok: ["The","Multistage","Forecast","Estimator","class",".","Implements","the","Multistage","forecast","method",".","The","Multistage","forecast","method","allows","users","to","fit","multiple","stages","of","models","with","each","stage","in","the","following","fashions",":","(","1",")","subseting",":","take","a","subset","of","data","from","the","end","of","training","data",";","(","2",")","aggregation",":","aggregate","the","subset","of","data","into","desired","frequency",";","(","3",")","training",":","train","a","model","with","the","desired","estimator","and","parameters",".","Users","can","just","use","one","stage","model","to","train","on","a","subset\/aggregation","of","the","original","data",",","or","can","specify","multiple","stages",",","where","the","later","stages","will","be","trained","on","the","fitted","residuals","of","the","previous","stages",".","This","can","significantly","speed","up","the","training","process","if","the","original","data","is","long","and","in","fine","granularity",".","Notes","--","--","-","The","following","assumptions","or","special","implementations","are","made","in","this","class",":","-","The","actual","``","fit_length","``",",","the","length","of","data","where","the","fitted","values","are","calculated",",","is","the","longer","of","``","train_length","``","and","``","fit_length","``",".","The","reason","is","that","there","is","no","benefit","of","calculating","a","shorter","period","of","fitted","values",".","The","fitted","values","are","already","available","during","training","(","in","Silverkite",")","so","there","is","no","loss","to","calculate","fitted","values","on","a","super","set","of","the","training","data",".","-","The","estimator","sorts","the","``","model_configs","``","according","to","the","``","train_length","``","in","descending","order",".","The","corresponding","aggregation","frequency",",","aggregation","function",",","fit","length",",","estimator","and","parameters","will","be","sorted","accordingly",".","This","is","to","ensure","that","we","have","enough","data","to","use","from","the","previous","model","when","we","fit","the","next","model",".","-","When","calculating","the","length","of","training","data",",","the","length","of","past","df",",","etc",",","the","actual","length","used","may","include","1","more","period","to","avoid","missing","timestamps",".","For","example",",","for","an","AR","order","of","5",",","you","may","see","the","length","of","``","past_df","``","to","be","6",";","or","for","a","train","length","of","``","365D","''",",","you","may","see","the","actual","length","to","be","366",".","This","is","expected",",","just","to","avoid","potential","missing","timestamps","after","dropping","incomplete","aggregation","periods",".","-","Since","the","models","in","each","stage","may","not","fit","on","the","entire","training","data",",","there","could","be","periods","where","fitted","values","are","not","calculated",".","Leading","fitted","values","in","the","training","period","may","be","NA",".","These","values","are","ignored","when","computing","evaluation","metrics",".","Attributes","--","--","--","--","--","model_configs",":","`","list","`","[","`","MultistageForecastModelConfig","`","]","A","list","of","model","configs","for","Multistage","Forecast","estimator",",","representing","the","stages","in","the","model",".","forecast_horizon",":","`","int","`","The","forecast","horizon","on","the","original","data","frequency",".","freq",":","`","str","`","or","None","The","frequency","of","the","original","data",".","train_lengths",":","`","list","`","[","`","str","`","]","or","None","A","list","of","training","data","lengths","for","the","models",".","fit_lengths",":","`","list","`","[","`","str","`","]","or","None","A","list","of","fitting","data","lengths","for","the","models",".","agg_funcs",":","`","list","`","[","`","str","`","or","Callable","]","or","None","A","list","of","aggregation","functions","for","the","models",".","agg_freqs",":","`","list","`","[","`","str","`","]","or","None","A","list","of","aggregation","frequencies","for","the","models",".","estimators",":","`","list","`","[","`","BaseForecastEstimator","`","]","or","None","A","list","of","estimators","used","in","the","models",".","estimator_params",":","`","list","`","[","`","dict","`","or","None","]","or","None","A","list","of","estimator","parameters","for","the","estimators",".","train_lengths_in_seconds",":","`","list","`","[","`","int","`","]","or","None","The","list","of","training","lengths","in","seconds",".","fit_lengths_in_seconds",":",":","`","list","`","[","`","int","`","]","or","None","The","list","of","fitting","lengths","in","seconds",".","If","the","original","``","fit_length","``","is","None","or","is","shorter","than","the","corresponding","``","train_length","``",",","it","will","be","replaced","by","the","corresponding","``","train_length","``",".","max_ar_orders",":","`","list","`","[","`","int","`","]","or","None","A","list","of","maximum","AR","orders","in","the","models",".","data_freq_in_seconds",":","`","int","`","or","None","The","data","frequency","in","seconds",".","num_points_per_agg_freqs",":","`","list","`","[","`","int","`","]","or","None","Number","of","data","points","in","each","aggregation","frequency",".","models",":","`","list","`","[","`","BaseForecastEstimator","`","]","The","list","of","model","instances",".","fit_df",":","`","pandas.DataFrame","`","or","None","The","prediction","df",".","train_end",":","`","pandas.Timestamp","`","or","None","The","train","end","timestamp",".","forecast_horizons",":","`","list","`","[","`","int","`","]","The","list","of","forecast","horizons","for","all","models","in","terms","of","the","aggregated","frequencies","."]
docstr: Gets the column name for a specific stage/frequency.
  The name will be f"{self.time_col_}__{index}__{freq}".
  
  Parameters
  ----------
  index : `int`
      The index for the currently stage of model.
      This is used to distinguish models with the same frequency.
  freq : `str`
      The aggregation frequency.
  
  Returns
  -------
  freq_col_name : `str`
      The time column name for the frequency, f"{self.time_col_}__{index}__{freq}".
docstr_tok: ["Gets","the","column","name","for","a","specific","stage\/frequency",".","The","name","will","be","f","''","{","self.time_col_","}","__","{","index","}","__","{","freq","}","''",".","Parameters","--","--","--","--","--","index",":","`","int","`","The","index","for","the","currently","stage","of","model",".","This","is","used","to","distinguish","models","with","the","same","frequency",".","freq",":","`","str","`","The","aggregation","frequency",".","Returns","--","--","--","-","freq_col_name",":","`","str","`","The","time","column","name","for","the","frequency",",","f","''","{","self.time_col_","}","__","{","index","}","__","{","freq","}","''","."]
code: def _get_freq_col(self, index: int, freq: str):
      """Gets the column name for a specific stage/frequency.
      The name will be f"{self.time_col_}__{index}__{freq}".
  
      Parameters
      ----------
      index : `int`
          The index for the currently stage of model.
          This is used to distinguish models with the same frequency.
      freq : `str`
          The aggregation frequency.
  
      Returns
      -------
      freq_col_name : `str`
          The time column name for the frequency, f"{self.time_col_}__{index}__{freq}".
      """
      return f"{self.time_col_}__{index}__{freq}"
  
imports: from dataclasses import dataclass
  from datetime import timedelta
  from typing import Callable
  from typing import List
  from typing import Optional
  from typing import Type
  from typing import Union
  import pandas
  from dateutil.relativedelta import relativedelta
  from pandas.tseries.frequencies import to_offset
  from sklearn.metrics import mean_squared_error
  from greykite.common import constants
  from greykite.common.aggregation_function_enum import AggregationFunctionEnum
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.time_properties import infer_freq
  from greykite.sklearn.estimator.base_forecast_estimator import BaseForecastEstimator
  from greykite.sklearn.estimator.simple_silverkite_estimator import SimpleSilverkiteEstimator
label_desc: Use image node_id 7 for calling the MultistageForecastEstimator obj's underlying member method code with example usage: obj._get_freq_col(index, freq) and returns: self, str, index, str, freq