class_docstr: Class to implement a partially regularized regression.
  
  A partially regularized regression is defined as
  
      beta_0, beta_1, beta_2 = argmin ||y - X_0beta_0 - X_1beta_1 - X_2beta_2||_2^2 + a_1 * ||beta_1||_1 + a_2 * ||beta_2||_2^2
  
  This regression formulation allows user to specify which regressor to have what type of regularization.
  For example, in automatic changepoint detection, "ct1" should not be penalized, yearly seasonality can have light L2 norm regularization,
  while the changepoint regressors need L1 norm regularization to be sparse.
  
  Attributes
  ----------
  l1_index : `list`[`int`, `str`], default None
      The index of columns that are to be penalized with L1 norm.
  l1_alpha : `float`, default 0.001
      The L1 norm regularization parameter.
  l2_index : `list`[`int`, `str`], default None
      The index of columns that are to be penalized with L2 norm.
  l2_alpha : `float`, default 0.001
      The L2 norm regularization parameter.
  has_constant : `list`[`int`]
      A list of detected constant column indices by `intercept_checker`.
  constant_index : `list`[`int`]
      A list of constant column indices after preprocessing.
  non_penalize_index : `list`[`int`]
      A list of column indices whose corresponding regressors are not to be penalized.
  intercept_ : `float`
      The fitted intercept.
  coef_ : `numpy.array`
      The fitted coefficients.
class_docstr_tok: ["Class","to","implement","a","partially","regularized","regression",".","A","partially","regularized","regression","is","defined","as","beta_0",",","beta_1",",","beta_2","=","argmin","||y","-","X_0beta_0","-","X_1beta_1","-","X_2beta_2||_2^2","+","a_1","*","||beta_1||_1","+","a_2","*","||beta_2||_2^2","This","regression","formulation","allows","user","to","specify","which","regressor","to","have","what","type","of","regularization",".","For","example",",","in","automatic","changepoint","detection",",","``","ct1","''","should","not","be","penalized",",","yearly","seasonality","can","have","light","L2","norm","regularization",",","while","the","changepoint","regressors","need","L1","norm","regularization","to","be","sparse",".","Attributes","--","--","--","--","--","l1_index",":","`","list","`","[","`","int","`",",","`","str","`","]",",","default","None","The","index","of","columns","that","are","to","be","penalized","with","L1","norm",".","l1_alpha",":","`","float","`",",","default","0.001","The","L1","norm","regularization","parameter",".","l2_index",":","`","list","`","[","`","int","`",",","`","str","`","]",",","default","None","The","index","of","columns","that","are","to","be","penalized","with","L2","norm",".","l2_alpha",":","`","float","`",",","default","0.001","The","L2","norm","regularization","parameter",".","has_constant",":","`","list","`","[","`","int","`","]","A","list","of","detected","constant","column","indices","by","`","intercept_checker","`",".","constant_index",":","`","list","`","[","`","int","`","]","A","list","of","constant","column","indices","after","preprocessing",".","non_penalize_index",":","`","list","`","[","`","int","`","]","A","list","of","column","indices","whose","corresponding","regressors","are","not","to","be","penalized",".","intercept_",":","`","float","`","The","fitted","intercept",".","coef_",":","`","numpy.array","`","The","fitted","coefficients","."]
docstr: Fits the partial regularized regression.
  
  Parameters
  ----------
  x : `numpy.array` or `pandas.DataFrame`
      The design matrix.
  y : `numpy.array`, `pandas.DataFrame` or `pandas.Series`
      The response vector.
  
  Returns
  -------
  self : `~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression`
      The current class instance.
docstr_tok: ["Fits","the","partial","regularized","regression",".","Parameters","--","--","--","--","--","x",":","`","numpy.array","`","or","`","pandas.DataFrame","`","The","design","matrix",".","y",":","`","numpy.array","`",",","`","pandas.DataFrame","`","or","`","pandas.Series","`","The","response","vector",".","Returns","--","--","--","-","self",":","`","~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression","`","The","current","class","instance","."]
code: def fit(self, x, y):
      """Fits the partial regularized regression.
  
      Parameters
      ----------
      x : `numpy.array` or `pandas.DataFrame`
          The design matrix.
      y : `numpy.array`, `pandas.DataFrame` or `pandas.Series`
          The response vector.
  
      Returns
      -------
      self : `~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression`
          The current class instance.
      """
      # Checks if the config matches a special case.
      # Because we already checked there's no overlapping in `l1_index` and `l2_index`,
      # so we have the following 3 cases:
      #   - `l1_index` includes all columns of x: this is the same as the Lasso.
      #   - `l2_index` includes all columns of x: this is the same as the Ridge.
      #   - Both `l1_index` and `l2_index` are None: this is the same as the LinearRegression.
      if self.l1_index is not None and len(self.l1_index) == x.shape[1]:
          model = Lasso(alpha=self.l1_alpha).fit(x, y)
          self.intercept_ = model.intercept_
          self.coef_ = model.coef_
          return self
      if self.l2_index is not None and len(self.l2_index) == x.shape[1]:
          model = Ridge(alpha=self.l2_alpha).fit(x, y)
          self.intercept_ = model.intercept_
          self.coef_ = model.coef_
          return self
      if self.l1_index is None and self.l2_index is None:
          model = LinearRegression().fit(x, y)
          self.intercept_ = model.intercept_
          self.coef_ = model.coef_
          return self
      # In the above three cases, we have one type of regularization on all columns of x.
      # The cases below will be a mix of at least two regularizations.
      # We'll handle this with the core algorithm in `self._fit_analytic`.
      x, y = self._check_input(x, y)
      lasso_input = self._get_lasso_input(x, y, self.l2_alpha)
      # Fits the lasso part.
      if lasso_input["x_lasso"].shape[1] > 0:
          lasso = Lasso(alpha=self.l1_alpha, fit_intercept=False).fit(
              X=lasso_input["x_lasso"], y=lasso_input["y_lasso"]
          )
          beta1 = lasso.coef_
      else:
          beta1 = np.array([])
      # Computes the L2 and non-penalize part.
      beta02 = lasso_input["hl02_r"] @ (y - lasso_input["x1"] @ beta1)
      coef = np.zeros(x.shape[1])
      coef[self.non_penalize_index] = beta02[
          : lasso_input["x0"].shape[1]
      ]
      coef[self.l1_index] = beta1
      coef[self.l2_index] = beta02[lasso_input["x0"].shape[1] :]
      # Extracts the intercept and coefficients.
      if not self.has_constant:
          self.intercept_ = coef[-1]
          self.coef_ = coef[:-1]
      else:
          self.intercept_ = np.sum(coef[self.constant_index])
          self.coef_ = coef
          self.coef_[self.constant_index] = 0
      return self
  
imports: from typing import Union
  import numpy
  import pandas
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.linear_model import Lasso
  from sklearn.linear_model import LassoCV
  from sklearn.linear_model import LinearRegression
  from sklearn.linear_model import Ridge
  from sklearn.linear_model import RidgeCV
  from sklearn.linear_model._coordinate_descent import _alpha_grid
  from sklearn.model_selection import check_cv
  from greykite.common.python_utils import ignore_warnings
label_desc: Use image node_id 2 for calling the PartialRegularizeRegression obj's underlying member method code with example usage: obj.fit(x, y) and returns: self, self, self, self