class_docstr: The quantile regression based uncertainty model.
  Predicts quantiles as the prediction intervals.
  The quantiles are calculated based on the ``coverage`` parameter.
  For example, a 90% prediction interval is the 0.05 quantile and 0.95 quantile predictions.
  
  There are four scenarios:
  
      - ``is_residual_based = False`` and ``x_mat`` is provided.
        In this case, the method fits two quantile regression models based on the ``value_col`` and ``x_mat``.
        Depending on the forecast model, the generated prediction intervals may not cover the forecasted values.
      - ``is_residual_based = False`` and ``x_mat`` is not provided.
        In this case, a ``x_mat`` is generated based on ``time_col``
        including linear growth and yearly/weekly seasonality.
        Currently we do not support customizing the generation of this feature matrix.
        The method fits two quantile regression models based on ``value_col`` and the generated ``x_mat``.
        Depending on the forecast model, the generated prediction intervals may not cover the forecasted values.
      - ``is_residual_based = True`` and ``x_mat`` is provided.
        In this case, the ``predicted_col`` needs to be provided
        in addition to ``value_col`` to calculate the residuals.
        The method fits two quantile regression models based on the residuals and ``x_mat``.
        The fitted residual quantiles are added to the forecasted values.
      - ``is_residual_based = True`` and ``x_mat`` is not provided.
        In this case, the ``predicted_col`` needs to be provided
        in addition to ``value_col`` to calculate the residuals.
        In this case, a ``x_mat`` is generated based on ``time_col``
        including linear growth and yearly/weekly seasonality.
        Currently we do not support customizing the generation of this feature matrix.
        The method fits two quantile regression models based on residuals and the generated ``x_mat``.
        The fitted residual quantiles are added to the forecasted values.
  
  If ``x_mat`` is not provided, ``time_col`` must be provided to build the feature matrix.
  
  If ``is_residual_based = False``, then ``value_col`` must be provided to train the model.
  If ``is_residual_based = True``, then both ``value_col`` and ``predicted_col`` must be provided.
  In this case, the method also tries to find ``cst.PREDICTED_COL`` in the training data
  too if ``predicted_col`` is not provided.
  
  Attributes
  ----------
  uncertainty_dict : `dict` [`str`, any]
      The uncertainty model specification. It should have the following keys:
  
              "uncertainty_method": a string that is in
                  `~greykite.sklearn.uncertainty.uncertainty_methods.UncertaintyMethodEnum`.
              "params": a dictionary that includes any additional parameters needed by the uncertainty method.
                        Expected keys include: "value_col", "predicted_col", "is_residual_based"
                        and "quantiles".
  
  UNCERTAINTY_METHOD : `str`
      The name for the uncertainty method.
  REQUIRED_PARAMS : `list` [`str`]
      A list of required parameters for the method.
  coverage : `float`
      The coverage of the uncertainty intervals.
      Will be used to calculate the quantiles.
  time_col : `str`
      The column name for timestamps in ``train_df`` and ``fut_df``.
  value_col : `str` or None
      The column name for values in ``train_df`` and ``fut_df``.
  predicted_col : `str` or None
      The column name for predicted values in ``train_df`` and ``fut_df``.
  residual_col : `str` or None
      The column name for residuals in ``train_df``.
  quantiles : `list` [`float`] or None
      A list of quantiles to be fitted.
      This is also derived from the ``coverage`` parameter.
  is_residual_based : `bool` or None
      Whether to fit the original values or residuals.
  models : `list` [`QuantileRegression`] or None
      A list of trained quantile regression models.
  x_mat : `pandas.DataFrame` or None
      The feature matrix used to fit the model.
  build_x_mat : `bool` or None
      Whether the feature matrix is built. If False, it is provided.
  distribution_col : `str` or None
      The column name for the column used as response in fitting the quantile regression models.
  offset_col : `str` or None
      The column name for the column used to offset the predicted intervals.
docstr: Fits the uncertainty model.
  
  Parameters
  ----------
  train_df : `pandas.DataFrame`
      The data used to fit the uncertainty model.
      Must have the following columns:
  
          value_col: this is required
          time_col: if ``x_mat`` is not provided.
  
      If ``is_residual_based = True``, ``train_df`` must include predicted values
      to calculate residuals. The predicted value column is ``predicted_col``
      if specified in ``uncertainty_dict``, default ``cst.PREDICTED_COL`` if not.
  
  x_mat : `pandas.DataFrame` or None, default None
      The feature matrix used to train the quantile regression model.
      Must have the same length as ``train_df``.
      If not provided, a feature matrix will be automatically generated to include
      linear growth and yearly/weekly seasonality.
  
  Returns
  -------
  self
docstr_tok: ["Fits","the","uncertainty","model",".","Parameters","--","--","--","--","--","train_df",":","`","pandas.DataFrame","`","The","data","used","to","fit","the","uncertainty","model",".","Must","have","the","following","columns",":","value_col",":","this","is","required","time_col",":","if","``","x_mat","``","is","not","provided",".","If","``","is_residual_based","=","True","``",",","``","train_df","``","must","include","predicted","values","to","calculate","residuals",".","The","predicted","value","column","is","``","predicted_col","``","if","specified","in","``","uncertainty_dict","``",",","default","``","cst.PREDICTED_COL","``","if","not",".","x_mat",":","`","pandas.DataFrame","`","or","None",",","default","None","The","feature","matrix","used","to","train","the","quantile","regression","model",".","Must","have","the","same","length","as","``","train_df","``",".","If","not","provided",",","a","feature","matrix","will","be","automatically","generated","to","include","linear","growth","and","yearly\/weekly","seasonality",".","Returns","--","--","--","-","self"]
code: def fit(
      self, train_df: pd.DataFrame, x_mat: Optional[pd.DataFrame] = None
  ) -> QuantileRegressionUncertaintyModel:
      """Fits the uncertainty model.
  
      Parameters
      ----------
      train_df : `pandas.DataFrame`
          The data used to fit the uncertainty model.
          Must have the following columns:
  
              value_col: this is required
              time_col: if ``x_mat`` is not provided.
  
          If ``is_residual_based = True``, ``train_df`` must include predicted values
          to calculate residuals. The predicted value column is ``predicted_col``
          if specified in ``uncertainty_dict``, default ``cst.PREDICTED_COL`` if not.
  
      x_mat : `pandas.DataFrame` or None, default None
          The feature matrix used to train the quantile regression model.
          Must have the same length as ``train_df``.
          If not provided, a feature matrix will be automatically generated to include
          linear growth and yearly/weekly seasonality.
  
      Returns
      -------
      self
      """
      super().fit(train_df=train_df)
      self.x_mat = x_mat
      self._check_input()
  
      # Builds the feature matrix if needed.
      if self.x_mat is None:
          self.x_mat = self._build_quantile_regression_features(
              training_phase=True
          )
      else:
          if len(train_df) != len(x_mat):
              raise UncertaintyError(
                  f"The size of `train_df` {len(train_df)} must be the same "
                  f"as the size of `x_mat` {len(x_mat)}."
              )
  
      # Trains the quantile regression model.
      self.models = [
          QuantileRegression(quantile=quantile, alpha=0).fit(
              self.x_mat, self.train_df[self.distribution_col]
          )
          for quantile in self.quantiles
      ]
  
      return self
  
imports: from __future__ import annotations
  from typing import Dict
  from typing import List
  from typing import Optional
  import pandas
  from sklearn.exceptions import NotFittedError
  from greykite.algo.common.l1_quantile_regression import QuantileRegression
  from greykite.algo.forecast.silverkite.forecast_silverkite import SilverkiteForecast
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_fourier_feature_col_names
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_silverkite_uncertainty_dict
  from greykite.common import constants
  from greykite.common.features.timeseries_features import fourier_series_multi_fcn
  from greykite.common.features.timeseries_features import get_default_origin_for_time_vars
  from greykite.sklearn.uncertainty.base_uncertainty_model import BaseUncertaintyModel
  from greykite.sklearn.uncertainty.exceptions import UncertaintyError
label_desc: Use image node_id 4 for calling the QuantileRegressionUncertaintyModel obj's underlying member method code with example usage: obj.fit(train_df, x_mat) and returns: self