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: Generates predictions for the target labels in the provided label DataFrame by applying the model resulting from
  the RidgeRegression fit method to the starting reduced block matrix using a leave-one-chromosome-out (LOCO)
  approach (this method caches the model and cross-validation DataFrames in the process for better performance).
  
  Args:
      chromosomes : List of chromosomes for which to generate a prediction (optional). If not provided, the
          chromosomes will be inferred from the block matrix.
  
  Returns:
      Pandas DataFrame containing offset values (y_hat) per chromosome. The rows are indexed by sample ID and
      chromosome; the columns are indexed by label. The column types are float64. The DataFrame is sorted using
      chromosome as the primary sort key, and sample ID as the secondary sort key.
docstr_tok: ["Generates","predictions","for","the","target","labels","in","the","provided","label","DataFrame","by","applying","the","model","resulting","from","the","RidgeRegression","fit","method","to","the","starting","reduced","block","matrix","using","a","leave-one-chromosome-out","(","LOCO",")","approach","(","this","method","caches","the","model","and","cross-validation","DataFrames","in","the","process","for","better","performance",")",".","Args",":","chromosomes",":","List","of","chromosomes","for","which","to","generate","a","prediction","(","optional",")",".","If","not","provided",",","the","chromosomes","will","be","inferred","from","the","block","matrix",".","Returns",":","Pandas","DataFrame","containing","offset","values","(","y_hat",")","per","chromosome",".","The","rows","are","indexed","by","sample","ID","and","chromosome",";","the","columns","are","indexed","by","label",".","The","column","types","are","float64",".","The","DataFrame","is","sorted","using","chromosome","as","the","primary","sort","key",",","and","sample","ID","as","the","secondary","sort","key","."]
code: def transform_loco(self, chromosomes: List[str] = []) -> pd.DataFrame:
      """
      Generates predictions for the target labels in the provided label DataFrame by applying the model resulting from
      the RidgeRegression fit method to the starting reduced block matrix using a leave-one-chromosome-out (LOCO)
      approach (this method caches the model and cross-validation DataFrames in the process for better performance).
  
      Args:
          chromosomes : List of chromosomes for which to generate a prediction (optional). If not provided, the
              chromosomes will be inferred from the block matrix.
  
      Returns:
          Pandas DataFrame containing offset values (y_hat) per chromosome. The rows are indexed by sample ID and
          chromosome; the columns are indexed by label. The column types are float64. The DataFrame is sorted using
          chromosome as the primary sort key, and sample ID as the secondary sort key.
      """
      loco_chromosomes = (
          chromosomes
          if chromosomes
          else infer_chromosomes(self.reduced_block_df)
      )
      loco_chromosomes.sort()
  
      # Cache model and CV DataFrames to avoid re-computing for each chromosome
      self._cache_model_cv_df()
  
      y_hat_df = pd.DataFrame({})
      orig_model_df = self.model_df
      for chromosome in loco_chromosomes:
          print(f"Generating predictions for chromosome {chromosome}.")
          loco_model_df = self.model_df.filter(
              ~f.col("header").rlike(f"^chr_{chromosome}_(alpha|block)")
          )
          self.model_df = loco_model_df
          loco_y_hat_df = self.transform()
          loco_y_hat_df["contigName"] = chromosome
          y_hat_df = y_hat_df.append(loco_y_hat_df)
          self.model_df = orig_model_df
  
      self.y_hat_df = y_hat_df.set_index("contigName", append=True)
      self._unpersist_model_cv_df()
      return self.y_hat_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 14 for calling the RidgeRegression obj's underlying member method code with example usage: obj.transform_loco(chromosomes) and returns: self