class_docstr: The simple conditional residuals uncertainty model.
  For more details, see `~greykite.algo.uncertainty.conditional.conf_interval`.
  
  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.
  
  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`
      The column name for values in ``train_df`` and ``fut_df``.
  distribution_col : `str` or None
      The column name for the column used to fit the distribution in ``train_df`` and ``fut_df``.
  residual_col : `str` or None
      The column name for residuals in ``train_df``.
  conditional_cols : `list` [`str`]
      The conditional columns when calculating the standard errors of the residuals.
  offset_col : `str` or None
      The column name for the column used to offset predicted intervals.
  is_residual_based : `bool` or None
      Whether to fit the original values or residuals.
class_docstr_tok: ["The","simple","conditional","residuals","uncertainty","model",".","For","more","details",",","see","`","~greykite.algo.uncertainty.conditional.conf_interval","`",".","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",".","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","`","The","column","name","for","values","in","``","train_df","``","and","``","fut_df","``",".","distribution_col",":","`","str","`","or","None","The","column","name","for","the","column","used","to","fit","the","distribution","in","``","train_df","``","and","``","fut_df","``",".","residual_col",":","`","str","`","or","None","The","column","name","for","residuals","in","``","train_df","``",".","conditional_cols",":","`","list","`","[","`","str","`","]","The","conditional","columns","when","calculating","the","standard","errors","of","the","residuals",".","offset_col",":","`","str","`","or","None","The","column","name","for","the","column","used","to","offset","predicted","intervals",".","is_residual_based",":","`","bool","`","or","None","Whether","to","fit","the","original","values","or","residuals","."]
docstr: Checks that necessary input are provided in ``self.uncertainty_dict`` and ``self.train_df``.
  This check only raises
  `~greykite.sklearn.uncertainty.exceptions.UncertaintyError`.
docstr_tok: ["Checks","that","necessary","input","are","provided","in","``","self.uncertainty_dict","``","and","``","self.train_df","``",".","This","check","only","raises","`","~greykite.sklearn.uncertainty.exceptions.UncertaintyError","`","."]
code: def _check_input(self):
      """Checks that necessary input are provided in ``self.uncertainty_dict`` and ``self.train_df``.
      This check only raises
      `~greykite.sklearn.uncertainty.exceptions.UncertaintyError`.
      """
      super()._check_input()
  
      # Gets whether it's residual based. If not provided, the default is residual based.
      self.is_residual_based = self.params.get(
          "is_residual_based", True
      )
      if not self.is_residual_based:
          raise UncertaintyError(
              f"'is_residual_based' must be True when "
              f"the uncertainty method is {self.UNCERTAINTY_METHOD}."
          )
  
      # Checks value column.
      self.value_col = self.params.get("value_col")
      if self.value_col not in self.train_df:
          raise UncertaintyError(
              f"`value_col` {self.value_col} not found in `train_df`."
          )
  
      # Checks columns needed when ``is_residual_based = True``.
      # If residual based, ``predicted_col`` must be provided.
      # Also looks for ``cst.PREDICTED_COL`` if the above is not provided.
      self.distribution_col = self.value_col
      if self.is_residual_based:
          # Tries to get predicted column from parameters and set ``offset_col``.
          self.predicted_col = self.params.get("predicted_col")
          if self.predicted_col is None:
              self.predicted_col = cst.PREDICTED_COL
          self.offset_col = self.predicted_col
  
          # Creates ``residual_col`` with ``value_col`` and ``predicted_col``.
          self.residual_col = cst.RESIDUAL_COL
          self.train_df[cst.RESIDUAL_COL] = (
              self.train_df[self.value_col]
              - self.train_df[self.predicted_col]
          )
          self.distribution_col = self.residual_col
  
      self.params["distribution_col"] = self.distribution_col
      self.params["offset_col"] = self.offset_col
  
      # Gets the valid parameters for ``conf_interval``.
      valid_params = [
          "distribution_col",
          "offset_col",
          "conditional_cols",
          "quantiles",
          "quantile_estimation_method",
          "sample_size_thresh",
          "small_sample_size_method",
          "small_sample_size_quantile",
          "min_admissible_value",
          "max_admissible_value",
      ]
      self.params = {
          k: v for k, v in self.params.items() if k in valid_params
      }
  
      # Tries to build conditional features based on time column.
      if (
          self.time_col is not None
          and self.time_col in self.train_df.columns
      ):
          self.train_df = add_time_features_df(
              df=self.train_df,
              time_col=self.time_col,
              conti_year_origin=0,  # this only affects the ``ct`` columns, which are not expected as conditional cols
          )
      elif cst.TIME_COL in self.train_df.columns:
          self.train_df = add_time_features_df(
              df=self.train_df,
              time_col=cst.TIME_COL,
              conti_year_origin=0,  # this only affects the ``ct`` columns, which are not expected as conditional cols
          )
      # Checks conditional columns.
      self.conditional_cols = self.params.get("conditional_cols")
      if isinstance(self.conditional_cols, str):
          self.conditional_cols = [self.conditional_cols]
      if self.conditional_cols is not None:
          if not isinstance(self.conditional_cols, list) or any(
              [
                  not isinstance(col, str)
                  for col in self.conditional_cols
              ]
          ):
              raise UncertaintyError(
                  f"`conditional_cols` {self.conditional_cols} must be a list of strings."
              )
          cols_not_in_df = [
              col
              for col in self.conditional_cols
              if col not in self.train_df.columns
          ]
          if cols_not_in_df:
              raise UncertaintyError(
                  f"The following conditional columns are not found in `train_df`: {cols_not_in_df}."
              )
  
      if self.coverage is None:
          self.coverage = self.DEFAULT_COVERAGE
      # If ``self.coverage`` is given and ``quantiles`` is not given in ``params``,
      # the coverage is used to calculate quantiles.
      uncertainty_dict = get_silverkite_uncertainty_dict(
          uncertainty=self.uncertainty_dict, coverage=self.coverage
      )
      self.quantiles = uncertainty_dict["params"]["quantiles"]
      self.params["quantiles"] = self.quantiles
  
file_path: greykite/greykite/sklearn/uncertainty/simple_conditional_residuals_model.py
imports: from typing import Dict
  from typing import List
  from typing import Optional
  import pandas
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_silverkite_uncertainty_dict
  from greykite.algo.uncertainty.conditional.conf_interval import conf_interval
  from greykite.algo.uncertainty.conditional.conf_interval import predict_ci
  from greykite.common import constants
  from greykite.common.features.timeseries_features import add_time_features_df
  from greykite.sklearn.uncertainty.base_uncertainty_model import BaseUncertaintyModel
  from greykite.sklearn.uncertainty.exceptions import UncertaintyError
label_desc: Use image node_id 2 for calling the SimpleConditionalResidualsModel obj's underlying member method code with example usage: obj._check_input() without return types