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: Args:
      reduced_block_df : Spark DataFrame representing the reduced block matrix generated by
          RidgeReduction
      label_df : Pandas DataFrame containing the target labels used in fitting the ridge models
      sample_blocks : Dict containing a mapping of sample_block ID to a list of corresponding sample IDs
      cov_df : Pandas DataFrame containing covariates to be included in every model in the stacking
          ensemble (optional).
      add_intercept: If True, an intercept column (all ones) will be added to the covariates
          (as the first column)
      ridge_reduced: RidgeReduction object containing level 0 reduction data
      alphas : array_like of alpha values used in the ridge regression (optional).
docstr_tok: ["Args",":","reduced_block_df",":","Spark","DataFrame","representing","the","reduced","block","matrix","generated","by","RidgeReduction","label_df",":","Pandas","DataFrame","containing","the","target","labels","used","in","fitting","the","ridge","models","sample_blocks",":","Dict","containing","a","mapping","of","sample_block","ID","to","a","list","of","corresponding","sample","IDs","cov_df",":","Pandas","DataFrame","containing","covariates","to","be","included","in","every","model","in","the","stacking","ensemble","(","optional",")",".","add_intercept",":","If","True",",","an","intercept","column","(","all","ones",")","will","be","added","to","the","covariates","(","as","the","first","column",")","ridge_reduced",":","RidgeReduction","object","containing","level","0","reduction","data","alphas",":","array_like","of","alpha","values","used","in","the","ridge","regression","(","optional",")","."]
code: def __init__(
      self,
      reduced_block_df: DataFrame,
      label_df: pd.DataFrame,
      sample_blocks: Dict[str, List[str]],
      cov_df: pd.DataFrame = pd.DataFrame({}),
      add_intercept: bool = True,
      alphas: List[float] = [],
  ) -> None:
      """
      Args:
          reduced_block_df : Spark DataFrame representing the reduced block matrix generated by
              RidgeReduction
          label_df : Pandas DataFrame containing the target labels used in fitting the ridge models
          sample_blocks : Dict containing a mapping of sample_block ID to a list of corresponding sample IDs
          cov_df : Pandas DataFrame containing covariates to be included in every model in the stacking
              ensemble (optional).
          add_intercept: If True, an intercept column (all ones) will be added to the covariates
              (as the first column)
          ridge_reduced: RidgeReduction object containing level 0 reduction data
          alphas : array_like of alpha values used in the ridge regression (optional).
      """
      self.reduced_block_df = reduced_block_df
      self.sample_blocks = sample_blocks
      self.set_label_df(label_df)
      self.set_cov_df(cov_df, add_intercept)
      self.set_alphas(alphas)
      self.model_df = None
      self.cv_df = None
      self.y_hat_df = None
  
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 1 to create a new RidgeRegression object  with example: obj = RidgeRegression(reduced_block_df, label_df, sample_blocks, cov_df, add_intercept, alphas)