code: def get_intercept_col_from_design_mat(
      x_mat: pd.DataFrame,
  ) -> Optional[str]:
      """Gets the explicit or implicit intercept column name from `patsy` design matrix.
  
      By default, `patsy` will make the design matrix always full rank.
      It will always include an intercept term unless we specify "-1" or "+0".
      However, if there are categorical variables, even we specify "-1" or "+0",
      it will include an implicit intercept by adding all levels of a categorical
      variable into the design matrix.
  
      The logic in patsy is that when intercept is excluded,
      always the first categorical variable in the formula string will have all levels.
      The levels are ordered in alphabetical order.
      In this case, we will search for the first categorical variable
      and remove its first level.
  
      Parameters
      ----------
      x_mat : `pandas.DataFrame`
          The design matrix built by `patsy`.
          Must have attribute ``design_info``.
  
      Returns
      -------
      name : `str` or None
          The column name of explicit or implicit intercept in ``x_mat``.
      """
      design_info = getattr(x_mat, "design_info", None)
      name = None
      if design_info is not None:
          terms = design_info.terms
          # Checks if intercept is in the design matrix.
          if patsy.desc.Term([]) in terms:
              name = patsy.desc.Term([]).name()  # Name is "Intercept".
          else:
              # Intercept is not in design matrix,
              # finds the implicit intercept.
              # `patsy` orders categorical variables first,
              # and the first categorical variable has all levels.
              # We remove the first level.
              for _, idx_slice in design_info.term_name_slices.items():
                  # We only need to iterate the first element.
                  if idx_slice.stop - idx_slice.start > 1:
                      # Sets name to the first column only when the term has
                      # more than 1 columns (ignores no-categorical case).
                      name = list(x_mat.columns)[idx_slice.start]
                  break
      return name
  
imports: import random
  import re
  import traceback
  import warnings
  from typing import Dict
  from typing import List
  from typing import Optional
  import matplotlib
  import numpy
  import pandas
  import patsy
  import scipy
  import statsmodels.api
  from pandas.plotting import register_matplotlib_converters
  from sklearn.ensemble import GradientBoostingRegressor
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.linear_model import ElasticNetCV
  from sklearn.linear_model import LarsCV
  from sklearn.linear_model import LassoCV
  from sklearn.linear_model import LassoLarsCV
  from sklearn.linear_model import RidgeCV
  from sklearn.linear_model import SGDRegressor
  from greykite.algo.common.l1_quantile_regression import QuantileRegression
  from greykite.algo.uncertainty.conditional.conf_interval import conf_interval
  from greykite.algo.uncertainty.conditional.conf_interval import predict_ci
  from greykite.common.constants import RESIDUAL_COL
  from greykite.common.constants import R2_null_model_score
  from greykite.common.evaluation import calc_pred_err
  from greykite.common.evaluation import r2_null_model_score
  from greykite.common.features.normalize import normalize_df
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import group_strs_with_regex_patterns
  from greykite.common.viz.timeseries_plotting import plot_multivariate
  import matplotlib.pyplot
label_desc: Use image node_id 1 for calling a global function with example usage: get_intercept_col_from_design_mat(x_mat) and returns: name