class_docstr: CleanLearning = Machine Learning with cleaned data (even when training on messy, error-ridden data).
  
  Automated and robust learning with noisy labels using any dataset and any regression model.
  For regression tasks, this class trains a ``model`` with error-prone, noisy labels
  as if the model had been instead trained on a dataset with perfect labels.
  It achieves this by estimating which labels are noisy (you might solely use CleanLearning for this estimation)
  and then removing examples estimated to have noisy labels, such that a more robust copy of the same model can be
  trained on the remaining clean data.
  
  Parameters
  ----------
  model :
      Any regression model implementing the `sklearn estimator API <https://scikit-learn.org/stable/developers/develop.html#rolling-your-own-estimator>`_,
      defining the following functions:
  
      - ``model.fit(X, y)``
      - ``model.predict(X)``
      - ``model.score(X, y)``
  
      Default model used is `sklearn.linear_model.LinearRegression
      <https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html>`_.
  
  cv_n_folds :
      This class needs holdout predictions for every data example and if not provided,
      uses cross-validation to compute them. This argument sets the number of cross-validation
      folds used to compute out-of-sample predictions for each example in ``X``. Default is 5.
      Larger values may produce better results, but requires longer to run.
  
  n_boot :
      Number of bootstrap resampling rounds used to estimate the model's epistemic uncertainty.
      Default is 5. Larger values are expected to produce better results but require longer runtimes.
      Set as 0 to skip estimating the epistemic uncertainty and get results faster.
  
  include_aleatoric_uncertainty :
      Specifies if the aleatoric uncertainty should be estimated during label error detection.
      ``True`` by default, which is expected to produce better results but require longer runtimes.
  
  verbose :
      Controls how much output is printed. Set to ``False`` to suppress print statements. Default `False`.
  
  seed :
      Set the default state of the random number generator used to split
      the data. By default, uses ``np.random`` current random state.
class_docstr_tok: ["CleanLearning","=","Machine","Learning","with","cleaned","data","(","even","when","training","on","messy",",","error-ridden","data",")",".","Automated","and","robust","learning","with","noisy","labels","using","any","dataset","and","any","regression","model",".","For","regression","tasks",",","this","class","trains","a","``","model","``","with","error-prone",",","noisy","labels","as","if","the","model","had","been","instead","trained","on","a","dataset","with","perfect","labels",".","It","achieves","this","by","estimating","which","labels","are","noisy","(","you","might","solely","use","CleanLearning","for","this","estimation",")","and","then","removing","examples","estimated","to","have","noisy","labels",",","such","that","a","more","robust","copy","of","the","same","model","can","be","trained","on","the","remaining","clean","data",".","Parameters","--","--","--","--","--","model",":","Any","regression","model","implementing","the","`","sklearn","estimator","API","<","https",":","\/\/scikit-learn.org\/stable\/developers\/develop.html","#","rolling-your-own-estimator",">","`","_",",","defining","the","following","functions",":","-","``","model.fit","(","X",",","y",")","``","-","``","model.predict","(","X",")","``","-","``","model.score","(","X",",","y",")","``","Default","model","used","is","`","sklearn.linear_model.LinearRegression","<","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.linear_model.LinearRegression.html",">","`","_",".","cv_n_folds",":","This","class","needs","holdout","predictions","for","every","data","example","and","if","not","provided",",","uses","cross-validation","to","compute","them",".","This","argument","sets","the","number","of","cross-validation","folds","used","to","compute","out-of-sample","predictions","for","each","example","in","``","X","``",".","Default","is","5",".","Larger","values","may","produce","better","results",",","but","requires","longer","to","run",".","n_boot",":","Number","of","bootstrap","resampling","rounds","used","to","estimate","the","model","'s","epistemic","uncertainty",".","Default","is","5",".","Larger","values","are","expected","to","produce","better","results","but","require","longer","runtimes",".","Set","as","0","to","skip","estimating","the","epistemic","uncertainty","and","get","results","faster",".","include_aleatoric_uncertainty",":","Specifies","if","the","aleatoric","uncertainty","should","be","estimated","during","label","error","detection",".","``","True","``","by","default",",","which","is","expected","to","produce","better","results","but","require","longer","runtimes",".","verbose",":","Controls","how","much","output","is","printed",".","Set","to","``","False","``","to","suppress","print","statements",".","Default","`","False","`",".","seed",":","Set","the","default","state","of","the","random","number","generator","used","to","split","the","data",".","By","default",",","uses","``","np.random","``","current","random","state","."]
docstr: Helper method to get out-of-fold predictions using cross validation.
  This method also allows us to filter out the bottom k percent of label errors before training the cross-validation models
  (both ``sorted_index`` and ``k`` has to be provided for this).
  
  Parameters
  ----------
  X :
      Data features (i.e. training inputs for ML), typically an array of shape ``(N, ...)``, where N is the number of examples.
  
  y :
      An array of shape ``(N,)`` of target values (dependant variables), where some values may be erroneous.
  
  sorted_index :
      Index of each example sorted by their residuals in ascending order.
  
  k :
      The fraction of examples to hold out from the training sets. Usually this is the fraction of examples that are
      deemed to contain errors.
docstr_tok: ["Helper","method","to","get","out-of-fold","predictions","using","cross","validation",".","This","method","also","allows","us","to","filter","out","the","bottom","k","percent","of","label","errors","before","training","the","cross-validation","models","(","both","``","sorted_index","``","and","``","k","``","has","to","be","provided","for","this",")",".","Parameters","--","--","--","--","--","X",":","Data","features","(","i.e",".","training","inputs","for","ML",")",",","typically","an","array","of","shape","``","(","N",",","...",")","``",",","where","N","is","the","number","of","examples",".","y",":","An","array","of","shape","``","(","N",",",")","``","of","target","values","(","dependant","variables",")",",","where","some","values","may","be","erroneous",".","sorted_index",":","Index","of","each","example","sorted","by","their","residuals","in","ascending","order",".","k",":","The","fraction","of","examples","to","hold","out","from","the","training","sets",".","Usually","this","is","the","fraction","of","examples","that","are","deemed","to","contain","errors","."]
code: def _get_cv_predictions(
      self,
      X: np.ndarray,
      y: np.ndarray,
      sorted_index: Optional[np.ndarray] = None,
      k: float = 0,
      *,
      cv_n_folds: Optional[int] = None,
      seed: Optional[int] = None,
      model_kwargs: Optional[dict] = None,
  ) -> np.ndarray:
      """
      Helper method to get out-of-fold predictions using cross validation.
      This method also allows us to filter out the bottom k percent of label errors before training the cross-validation models
      (both ``sorted_index`` and ``k`` has to be provided for this).
  
      Parameters
      ----------
      X :
          Data features (i.e. training inputs for ML), typically an array of shape ``(N, ...)``, where N is the number of examples.
  
      y :
          An array of shape ``(N,)`` of target values (dependant variables), where some values may be erroneous.
  
      sorted_index :
          Index of each example sorted by their residuals in ascending order.
  
      k :
          The fraction of examples to hold out from the training sets. Usually this is the fraction of examples that are
          deemed to contain errors.
  
      """
      # set to default unless specified otherwise
      if cv_n_folds is None:
          cv_n_folds = self.cv_n_folds
  
      if model_kwargs is None:
          model_kwargs = {}
  
      if k < 0 or k > 1:
          raise ValueError("k must be a value between 0 and 1")
      elif k == 0:
          if sorted_index is None:
              sorted_index = np.array(range(len(y)))
          in_sample_idx = sorted_index
      else:
          if sorted_index is None:
              # TODO: better error message
              raise ValueError(
                  "You need to pass in the index sorted by prediction quality to use with k"
              )
          num_to_drop = math.ceil(len(sorted_index) * k)
          in_sample_idx = sorted_index[:-num_to_drop]
          out_of_sample_idx = sorted_index[-num_to_drop:]
  
          X_out_of_sample = X[out_of_sample_idx]
          out_of_sample_predictions = np.zeros(
              shape=[len(out_of_sample_idx), cv_n_folds]
          )
  
      if len(in_sample_idx) < cv_n_folds:
          raise ValueError(
              f"There are too few examples to conduct {cv_n_folds}-fold cross validation. "
              "You can either reduce cv_n_folds for cross validation, or decrease k to exclude less data."
          )
  
      predictions = np.zeros(shape=len(y))
  
      kf = KFold(n_splits=cv_n_folds, shuffle=True, random_state=seed)
  
      for k_split, (cv_train_idx, cv_holdout_idx) in enumerate(
          kf.split(in_sample_idx)
      ):
          try:
              model_copy = sklearn.base.clone(
                  self.model
              )  # fresh untrained copy of the model
          except Exception:
              raise ValueError(
                  "`model` must be clonable via: sklearn.base.clone(model). "
                  "You can either implement instance method `model.get_params()` to produce a fresh untrained copy of this model, "
                  "or you can implement the cross-validation outside of cleanlab "
                  "and pass in the obtained `pred_probs` to skip cleanlab's internal cross-validation"
              )
  
          # map the index to the actual index in the original dataset
          data_idx_train, data_idx_holdout = (
              in_sample_idx[cv_train_idx],
              in_sample_idx[cv_holdout_idx],
          )
  
          (
              X_train_cv,
              X_holdout_cv,
              y_train_cv,
              y_holdout_cv,
          ) = train_val_split(X, y, data_idx_train, data_idx_holdout)
  
          model_copy.fit(X_train_cv, y_train_cv, **model_kwargs)
          predictions_cv = model_copy.predict(X_holdout_cv)
  
          predictions[data_idx_holdout] = predictions_cv
  
          if k != 0:
              out_of_sample_predictions[
                  :, k_split
              ] = model_copy.predict(X_out_of_sample)
  
      if k != 0:
          out_of_sample_predictions_avg = np.mean(
              out_of_sample_predictions, axis=1
          )
          predictions[out_of_sample_idx] = out_of_sample_predictions_avg
  
      return predictions
  
imports: from typing import Optional, Union, Tuple
  import inspect
  import warnings
  import math
  import numpy
  import pandas
  import sklearn.base
  from sklearn.base import BaseEstimator
  from sklearn.model_selection import KFold
  from sklearn.linear_model import LinearRegression
  from sklearn.metrics import r2_score
  from cleanlab.typing import LabelLike
  from cleanlab.internal.constants import TINY_VALUE
  from cleanlab.internal.util import train_val_split, subset_X_y
  from cleanlab.internal.regression_utils import assert_valid_regression_inputs
  from cleanlab.internal.validation import labels_to_array
label_desc: Use image node_id 10 for calling the CleanLearning obj's underlying member method code with example usage: obj._get_cv_predictions(X, y, sorted_index, k) and returns: predictions