class_docstr: The RidgeRegression class is used to fit ridge models against one or more labels optimized over a provided list of
  ridge alpha parameters.  It is similar in function to RidgeReduction except that whereas RidgeReduction attempts to
  reduce a starting matrix X to a block matrix of smaller dimension, RidgeRegression is intended to find an optimal
  model of the form Y_hat ~ XB, where Y_hat is a matrix of one or more predicted labels and B is a matrix of
  coefficients.  The optimal ridge alpha value is chosen for each label by maximizing the average out of fold r2
  score.
class_docstr_tok: ["The","RidgeRegression","class","is","used","to","fit","ridge","models","against","one","or","more","labels","optimized","over","a","provided","list","of","ridge","alpha","parameters",".","It","is","similar","in","function","to","RidgeReduction","except","that","whereas","RidgeReduction","attempts","to","reduce","a","starting","matrix","X","to","a","block","matrix","of","smaller","dimension",",","RidgeRegression","is","intended","to","find","an","optimal","model","of","the","form","Y_hat","~","XB",",","where","Y_hat","is","a","matrix","of","one","or","more","predicted","labels","and","B","is","a","matrix","of","coefficients",".","The","optimal","ridge","alpha","value","is","chosen","for","each","label","by","maximizing","the","average","out","of","fold","r2","score","."]
docstr: Fits a ridge regression model, represented by a Spark DataFrame containing coefficients for each of the ridge
  alpha parameters, for each block in the starting reduced 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","ridge","regression","model",",","represented","by","a","Spark","DataFrame","containing","coefficients","for","each","of","the","ridge","alpha","parameters",",","for","each","block","in","the","starting","reduced","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 ridge regression model, represented by a Spark DataFrame containing coefficients for each of the ridge
      alpha parameters, for each block in the starting reduced 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"]
      reduce_key_pattern = ["header_block", "header", "label"]
      metric = "r2"
  
      map_udf = pandas_udf(
          lambda key, pdf: map_normal_eqn(
              key,
              map_key_pattern,
              pdf,
              self._std_label_df,
              self.sample_blocks,
              self._std_cov_df,
          ),
          normal_eqn_struct,
          PandasUDFType.GROUPED_MAP,
      )
      reduce_udf = pandas_udf(
          lambda key, pdf: reduce_normal_eqn(
              key, reduce_key_pattern, pdf
          ),
          normal_eqn_struct,
          PandasUDFType.GROUPED_MAP,
      )
      model_udf = pandas_udf(
          lambda key, pdf: solve_normal_eqn(
              key,
              map_key_pattern,
              pdf,
              self._std_label_df,
              self._alphas,
              self._std_cov_df,
          ),
          model_struct,
          PandasUDFType.GROUPED_MAP,
      )
      score_udf = pandas_udf(
          lambda key, pdf: score_models(
              key,
              map_key_pattern,
              pdf,
              self._std_label_df,
              self.sample_blocks,
              self._alphas,
              self._std_cov_df,
              pd.DataFrame({}),
              metric,
          ),
          cv_struct,
          PandasUDFType.GROUPED_MAP,
      )
  
      self.model_df = (
          self.reduced_block_df.groupBy(map_key_pattern)
          .apply(map_udf)
          .groupBy(reduce_key_pattern)
          .apply(reduce_udf)
          .groupBy(map_key_pattern)
          .apply(model_udf)
      )
  
      self.cv_df = cross_validation(
          self.reduced_block_df,
          self.model_df,
          score_udf,
          map_key_pattern,
          self._alphas,
          metric,
      )
  
      record_hls_event("wgrRidgeRegressionFit")
  
      return self.model_df, self.cv_df
  
imports: from .ridge_udfs import *
  from .ridge_reduction import RidgeReduction
  from .model_functions import _prepare_labels_and_warn, _prepare_covariates, _check_model, _check_cv
  from nptyping import Float, NDArray
  import pandas
  from pyspark.sql import DataFrame, Row
  from pyspark.sql.functions import pandas_udf, PandasUDFType
  import pyspark.sql.functions
  from typeguard import typechecked
  from typing import Any, Dict, List, Union
  from glow.logging import record_hls_event
  import warnings
label_desc: Use image node_id 12 for calling the RidgeRegression obj's underlying member method code with example usage: obj.fit() and returns: self,  self