class_docstr: The LogisticRidgeRegression class is used to fit logistic ridge regression models against one or more labels optimized over a
  provided list of ridge alpha parameters. The optimal ridge alpha value is chosen for each label by minimizing the
  average out of fold log_loss scores.
docstr: Fits a logistic regression model, represented by a Spark DataFrame containing coefficients for each of the ridge
  alpha parameters, for each block in the reduced block matrix, for each label in the target labels, as well as a
  Spark DataFrame containing the optimal ridge alpha value for each label.
  
  Returns:
      Two Spark DataFrames, one containing the model resulting from the fitting routine and one containing the
      results of the cross validation procedure.
docstr_tok: ["Fits","a","logistic","regression","model",",","represented","by","a","Spark","DataFrame","containing","coefficients","for","each","of","the","ridge","alpha","parameters",",","for","each","block","in","the","reduced","block","matrix",",","for","each","label","in","the","target","labels",",","as","well","as","a","Spark","DataFrame","containing","the","optimal","ridge","alpha","value","for","each","label",".","Returns",":","Two","Spark","DataFrames",",","one","containing","the","model","resulting","from","the","fitting","routine","and","one","containing","the","results","of","the","cross","validation","procedure","."]
code: def fit(self) -> (DataFrame, DataFrame):
      """
      Fits a logistic regression model, represented by a Spark DataFrame containing coefficients for each of the ridge
      alpha parameters, for each block in the reduced block matrix, for each label in the target labels, as well as a
      Spark DataFrame containing the optimal ridge alpha value for each label.
  
      Returns:
          Two Spark DataFrames, one containing the model resulting from the fitting routine and one containing the
          results of the cross validation procedure.
      """
      map_key_pattern = ["sample_block", "label", "alpha_name"]
      reduce_key_pattern = [
          "header_block",
          "header",
          "label",
          "alpha_name",
      ]
      model_key_pattern = ["sample_block", "label", "alpha_name"]
      score_key_pattern = ["sample_block", "label"]
      metric = "log_loss"
  
      maskdf = pd.DataFrame(
          data=np.where(np.isnan(self._label_df), False, True),
          columns=self._label_df.columns,
          index=self._label_df.index,
      )
  
      beta_cov_dict = {}
  
      for label in self._label_df:
          if self._std_cov_df.empty:
              beta_cov_dict[label] = np.array([])
          else:
              row_mask = slice_label_rows(
                  maskdf,
                  label,
                  list(self._label_df.index),
                  np.array([]),
              ).ravel()
  
              cov_mat = slice_label_rows(
                  self._std_cov_df,
                  "all",
                  list(self._label_df.index),
                  row_mask,
              )
              y = slice_label_rows(
                  self._label_df,
                  label,
                  list(self._label_df.index),
                  row_mask,
              ).ravel()
              fit_result = constrained_logistic_fit(
                  cov_mat,
                  y,
                  np.zeros(cov_mat.shape[1]),
                  guess=np.array([]),
                  n_cov=0,
              )
              beta_cov_dict[label] = fit_result.x
  
      map_udf = pandas_udf(
          lambda key, pdf: map_irls_eqn(
              key,
              map_key_pattern,
              pdf,
              self._label_df,
              self.sample_blocks,
              self._std_cov_df,
              beta_cov_dict,
              maskdf,
              self._alphas,
          ),
          irls_eqn_struct,
          PandasUDFType.GROUPED_MAP,
      )
  
      reduce_udf = pandas_udf(
          lambda key, pdf: reduce_irls_eqn(
              key, reduce_key_pattern, pdf
          ),
          irls_eqn_struct,
          PandasUDFType.GROUPED_MAP,
      )
  
      model_udf = pandas_udf(
          lambda key, pdf: solve_irls_eqn(
              key,
              model_key_pattern,
              pdf,
              self._label_df,
              self._alphas,
              self._std_cov_df,
          ),
          model_struct,
          PandasUDFType.GROUPED_MAP,
      )
  
      score_udf = pandas_udf(
          lambda key, pdf: score_models(
              key,
              score_key_pattern,
              pdf,
              self._label_df,
              self.sample_blocks,
              self._alphas,
              self._std_cov_df,
              maskdf,
              metric,
          ),
          cv_struct,
          PandasUDFType.GROUPED_MAP,
      )
  
      self.model_df = (
          self.reduced_block_df.drop("alpha")
          .withColumn(
              "alpha_name",
              f.explode(
                  f.array([f.lit(n) for n in self._alphas.keys()])
              ),
          )
          .groupBy(map_key_pattern)
          .apply(map_udf)
          .groupBy(reduce_key_pattern)
          .apply(reduce_udf)
          .groupBy(model_key_pattern)
          .apply(model_udf)
          .withColumn(
              "alpha_label_coef",
              f.expr(
                  "struct(alphas[0] AS alpha, labels[0] AS label, coefficients[0] AS coefficient)"
              ),
          )
          .withColumn("alpha_label_coef_label", f.expr("labels[0]"))
          .groupBy(
              "header_block",
              "sample_block",
              "header",
              "sort_key",
              "alpha_label_coef_label",
          )
          .agg(
              f.sort_array(f.collect_list("alpha_label_coef")).alias(
                  "alphas_labels_coefs"
              )
          )
          .selectExpr(
              "*",
              "alphas_labels_coefs.alpha AS alphas",
              "alphas_labels_coefs.label AS labels",
              "alphas_labels_coefs.coefficient AS coefficients",
          )
          .drop("alphas_labels_coefs", "label")
      )
  
      self.cv_df = cross_validation(
          self.reduced_block_df,
          self.model_df,
          score_udf,
          score_key_pattern,
          self._alphas,
          metric,
      )
  
      record_hls_event("wgrLogisticRegressionFit")
  
      return self.model_df, self.cv_df
  
imports: from .logistic_udfs import *
  from .ridge_reduction import RidgeReduction
  from .model_functions import _prepare_labels_and_warn, _prepare_covariates, _check_model, _check_cv, _is_binary
  from nptyping import Float, NDArray
  import pandas
  from pyspark.sql import DataFrame
  from pyspark.sql.functions import pandas_udf, PandasUDFType
  import pyspark.sql.functions
  from typeguard import typechecked
  from typing import Any, Dict, List
  import warnings
  from glow.logging import record_hls_event
label_desc: Use image node_id 12 for calling the LogisticRidgeRegression obj's underlying member method code with example usage: obj.fit() and returns: self,  self