class_docstr: Implements the cross-validation version of
  `~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression`.
  
  Attributes
  ----------
  l1_index : `list`[`int`, `str`], default None
      The index of columns that are to be penalized with L1 norm.
  l1_alphas : `list`[`float`], default None
      The L1 norm regularization parameters.
  n_l1_alphas : `int`, default 50.
      The number of L1 norm regularization parameters. Will not be used if `l1_alphas` is provided.
  l2_index : `list`[`int`, `str`], default None
      The index of columns that are to be penalized with L2 norm.
  l2_alphas : `list`[`float`], default (0.001, 0.1, 10)
      The L2 norm regularization parameter.
  cv : `int`, cross-validation generator, or iterable, default 5
      Determines the cross-validation splitting strategy. This is the same as the ``cv`` in `sklearn` modules.
      Possible inputs for cv are:
          - None, to use the default 5-fold cross validation,
          - integer, to specify the number of folds.
          - :term:`CV splitter`,
          - An iterable yielding (train, test) splits as arrays of indices.
  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.
  best_model : `~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression`
      The best model selected by cross validation.
  best_mse : `float`
      The best cross-validated test mse.
  l1_alpha_ : `float`
      The best L1 norm regularization parameter.
  l2_alpha_ : `float`
      The best L2 norm regularization parameter.
  intercept_ : `float`
      The fitted intercept.
  coef_ : `numpy.array`
      The fitted coefficients.
class_docstr_tok: ["Implements","the","cross-validation","version","of","`","~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression","`",".","Attributes","--","--","--","--","--","l1_index",":","`","list","`","[","`","int","`",",","`","str","`","]",",","default","None","The","index","of","columns","that","are","to","be","penalized","with","L1","norm",".","l1_alphas",":","`","list","`","[","`","float","`","]",",","default","None","The","L1","norm","regularization","parameters",".","n_l1_alphas",":","`","int","`",",","default","50",".","The","number","of","L1","norm","regularization","parameters",".","Will","not","be","used","if","`","l1_alphas","`","is","provided",".","l2_index",":","`","list","`","[","`","int","`",",","`","str","`","]",",","default","None","The","index","of","columns","that","are","to","be","penalized","with","L2","norm",".","l2_alphas",":","`","list","`","[","`","float","`","]",",","default","(","0.001",",","0.1",",","10",")","The","L2","norm","regularization","parameter",".","cv",":","`","int","`",",","cross-validation","generator",",","or","iterable",",","default","5","Determines","the","cross-validation","splitting","strategy",".","This","is","the","same","as","the","``","cv","``","in","`","sklearn","`","modules",".","Possible","inputs","for","cv","are",":","-","None",",","to","use","the","default","5-fold","cross","validation",",","-","integer",",","to","specify","the","number","of","folds",".","-",":","term",":","`","CV","splitter","`",",","-","An","iterable","yielding","(","train",",","test",")","splits","as","arrays","of","indices",".","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",".","best_model",":","`","~greykite.algo.common.partial_regularize_regression.PartialRegularizeRegression","`","The","best","model","selected","by","cross","validation",".","best_mse",":","`","float","`","The","best","cross-validated","test","mse",".","l1_alpha_",":","`","float","`","The","best","L1","norm","regularization","parameter",".","l2_alpha_",":","`","float","`","The","best","L2","norm","regularization","parameter",".","intercept_",":","`","float","`","The","fitted","intercept",".","coef_",":","`","numpy.array","`","The","fitted","coefficients","."]
docstr: Fits the regression problem with a single L2 norm regularization parameter and
  cross validation over many L1 norm regularization parameters.
  
  The algorithm fits the problem with `sklearn.linear_model.LassoCV` on transformed x and y,
  then estimates the non-penalized and L2 norm penalized coefficients.
  
  Parameters
  ----------
  x : `numpy.array`
      The processed design matrix.
  y : `numpy.array`
      The processed response vector.
  l2_alpha : `float`
      The L2 norm regularization parameter.
  cv : `int`, cross-validation generator, or iterable, default 5
      Determines the cross-validation splitting strategy. This is the same as the ``cv`` in `sklearn` modules.
      Possible inputs for cv are:
          - None, to use the default 5-fold cross validation,
          - integer, to specify the number of folds.
          - :term:`CV splitter`,
          - An iterable yielding (train, test) splits as arrays of indices.
  
  Returns
  -------
  best_l1_alpha : `float`
      The best L1 regularization parameter model.
  best_mse : `float`
      The best mse.
docstr_tok: ["Fits","the","regression","problem","with","a","single","L2","norm","regularization","parameter","and","cross","validation","over","many","L1","norm","regularization","parameters",".","The","algorithm","fits","the","problem","with","`","sklearn.linear_model.LassoCV","`","on","transformed","x","and","y",",","then","estimates","the","non-penalized","and","L2","norm","penalized","coefficients",".","Parameters","--","--","--","--","--","x",":","`","numpy.array","`","The","processed","design","matrix",".","y",":","`","numpy.array","`","The","processed","response","vector",".","l2_alpha",":","`","float","`","The","L2","norm","regularization","parameter",".","cv",":","`","int","`",",","cross-validation","generator",",","or","iterable",",","default","5","Determines","the","cross-validation","splitting","strategy",".","This","is","the","same","as","the","``","cv","``","in","`","sklearn","`","modules",".","Possible","inputs","for","cv","are",":","-","None",",","to","use","the","default","5-fold","cross","validation",",","-","integer",",","to","specify","the","number","of","folds",".","-",":","term",":","`","CV","splitter","`",",","-","An","iterable","yielding","(","train",",","test",")","splits","as","arrays","of","indices",".","Returns","--","--","--","-","best_l1_alpha",":","`","float","`","The","best","L1","regularization","parameter","model",".","best_mse",":","`","float","`","The","best","mse","."]
code: def _fit_analytic(self, x, y, l2_alpha, cv):
      """Fits the regression problem with a single L2 norm regularization parameter and
      cross validation over many L1 norm regularization parameters.
  
      The algorithm fits the problem with `sklearn.linear_model.LassoCV` on transformed x and y,
      then estimates the non-penalized and L2 norm penalized coefficients.
  
      Parameters
      ----------
      x : `numpy.array`
          The processed design matrix.
      y : `numpy.array`
          The processed response vector.
      l2_alpha : `float`
          The L2 norm regularization parameter.
      cv : `int`, cross-validation generator, or iterable, default 5
          Determines the cross-validation splitting strategy. This is the same as the ``cv`` in `sklearn` modules.
          Possible inputs for cv are:
              - None, to use the default 5-fold cross validation,
              - integer, to specify the number of folds.
              - :term:`CV splitter`,
              - An iterable yielding (train, test) splits as arrays of indices.
  
      Returns
      -------
      best_l1_alpha : `float`
          The best L1 regularization parameter model.
      best_mse : `float`
          The best mse.
      """
      mses = (
          np.zeros(self.n_l1_alphas) if self.l1_index else np.zeros(1)
      )
      if self.l1_alphas is not None:
          l1_alphas = self.l1_alphas
      else:
          l1_alphas = self._get_alphas(x, y, l2_alpha)
      for train, test in cv.split(x):
          x_train = x[train]
          x_test = x[test]
          y_train = y[train]
          y_test = y[test]
          lasso_input = self._get_lasso_input(
              x_train, y_train, l2_alpha
          )
          if l1_alphas is not None:
              # Fits all `l1_alphas`.
              path = LassoCV(fit_intercept=False).path(
                  alphas=l1_alphas,
                  X=lasso_input["x_lasso"],
                  y=lasso_input["y_lasso"],
              )
              # Makes predictions and gets the best MSE.
              beta1 = path[1]
          else:
              beta1 = np.array([])
          beta02 = lasso_input["hl02_r"] @ (
              y_train.reshape(-1, 1)
              - (lasso_input["x1"] @ beta1).reshape(
                  y_train.shape[0], -1
              )
          )
          coef = (
              np.zeros([x.shape[1], self.n_l1_alphas])
              if l1_alphas is not None
              else np.zeros([x.shape[1], 1])
          )
          coef[self.non_penalize_index, :] = beta02[
              : lasso_input["x0"].shape[1], :
          ]
          coef[self.l1_index, :] = beta1 if l1_alphas is not None else 0
          coef[self.l2_index] = beta02[lasso_input["x0"].shape[1] :, :]
          y_pred = x_test @ coef
          mses += ((y_test.reshape(-1, 1) - y_pred) ** 2).mean(axis=0)
      best_l1_alpha = (
          l1_alphas[mses.argmin()] if l1_alphas is not None else None
      )
      return best_l1_alpha, np.min(mses)
  
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 5 for calling the PartialRegularizeRegressionCV obj's underlying member method code with example usage: obj._fit_analytic(x, y, l2_alpha, cv) and returns: best_l1_alpha,  np