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 that conducts a coarse and fine grained grid search to determine the best value
  of k, the fraction of the dataset that contains issues.
  
  Returns a tuple containing the the best value of k (ie. the one that has the best r squared score),
  and the corrsponding r squared score obtained when dropping k% of the data.
docstr_tok: ["Helper","method","that","conducts","a","coarse","and","fine","grained","grid","search","to","determine","the","best","value","of","k",",","the","fraction","of","the","dataset","that","contains","issues",".","Returns","a","tuple","containing","the","the","best","value","of","k","(","ie",".","the","one","that","has","the","best","r","squared","score",")",",","and","the","corrsponding","r","squared","score","obtained","when","dropping","k","%","of","the","data","."]
code: def _find_best_k(
      self,
      X: np.ndarray,
      y: np.ndarray,
      sorted_index: np.ndarray,
      coarse_search_range: list = [0.01, 0.05, 0.1, 0.15, 0.2],
      fine_search_size: int = 3,
  ) -> Tuple[float, float]:
      """
      Helper method that conducts a coarse and fine grained grid search to determine the best value
      of k, the fraction of the dataset that contains issues.
  
      Returns a tuple containing the the best value of k (ie. the one that has the best r squared score),
      and the corrsponding r squared score obtained when dropping k% of the data.
      """
      if len(coarse_search_range) == 0:
          raise ValueError(
              "coarse_search_range must have at least 1 value of k"
          )
      elif len(coarse_search_range) == 1:
          curr_k = coarse_search_range[0]
          num_examples_kept = math.floor(len(y) * (1 - curr_k))
          if num_examples_kept < self.cv_n_folds:
              raise ValueError(
                  f"There are too few examples to conduct {self.cv_n_folds}-fold cross validation. "
                  "You can either reduce self.cv_n_folds for cross validation, or decrease k to exclude less data."
              )
          predictions = self._get_cv_predictions(
              X=X,
              y=y,
              sorted_index=sorted_index,
              k=curr_k,
          )
          best_r2 = r2_score(y, predictions)
          best_k = coarse_search_range[0]
      else:
          # conduct coarse search
          coarse_search_range = sorted(
              coarse_search_range
          )  # sort to conduct fine search well
          r2_coarse = np.full(len(coarse_search_range), np.NaN)
          for i in range(len(coarse_search_range)):
              curr_k = coarse_search_range[i]
              num_examples_kept = math.floor(len(y) * (1 - curr_k))
              # check if there are too few examples to do cross val
              if num_examples_kept < self.cv_n_folds:
                  r2_coarse[
                      i
                  ] = -1e30  # arbitrary large negative number
              else:
                  predictions = self._get_cv_predictions(
                      X=X,
                      y=y,
                      sorted_index=sorted_index,
                      k=curr_k,
                  )
                  r2_coarse[i] = r2_score(y, predictions)
  
          max_r2_ind = np.argmax(r2_coarse)
  
          # conduct fine search
          if fine_search_size < 0:
              raise ValueError("fine_search_size must at least 0")
          elif fine_search_size == 0:
              best_k = coarse_search_range[np.argmax(r2_coarse)]
              best_r2 = np.max(r2_coarse)
          else:
              fine_search_range = np.array([])
              if max_r2_ind != 0:
                  fine_search_range = np.append(
                      np.linspace(
                          coarse_search_range[max_r2_ind - 1],
                          coarse_search_range[max_r2_ind],
                          fine_search_size + 1,
                          endpoint=False,
                      )[1:],
                      fine_search_range,
                  )
              if max_r2_ind != len(coarse_search_range) - 1:
                  fine_search_range = np.append(
                      fine_search_range,
                      np.linspace(
                          coarse_search_range[max_r2_ind],
                          coarse_search_range[max_r2_ind + 1],
                          fine_search_size + 1,
                          endpoint=False,
                      )[1:],
                  )
  
              r2_fine = np.full(len(fine_search_range), np.NaN)
              for i in range(len(fine_search_range)):
                  curr_k = fine_search_range[i]
                  num_examples_kept = math.floor(len(y) * (1 - curr_k))
                  # check if there are too few examples to do cross val
                  if num_examples_kept < self.cv_n_folds:
                      r2_fine[
                          i
                      ] = -1e30  # arbitrary large negative number
                  else:
                      predictions = self._get_cv_predictions(
                          X=X,
                          y=y,
                          sorted_index=sorted_index,
                          k=curr_k,
                      )
                      r2_fine[i] = r2_score(y, predictions)
  
              # check the max between coarse and fine search
              if max(r2_coarse) > max(r2_fine):
                  best_k = coarse_search_range[np.argmax(r2_coarse)]
                  best_r2 = np.max(r2_coarse)
              else:
                  best_k = fine_search_range[np.argmax(r2_fine)]
                  best_r2 = np.max(r2_fine)
  
      return best_k, best_r2
  
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 11 for calling the CleanLearning obj's underlying member method code with example usage: obj._find_best_k(X, y, sorted_index, coarse_search_range, fine_search_size) and returns: best_k,  best_r2