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: Train regression ``model`` with error-prone, noisy labels as if the model had been instead trained
  on a dataset with the correct labels. ``fit`` achieves this by first training ``model`` via
  cross-validation on the noisy data, using the resulting predicted probabilities to identify label issues,
  pruning the data with label issues, and finally training ``model`` on the remaining clean data.
  
  Parameters
  ----------
  X :
      Data features (i.e. covariates, independent variables), typically an array of shape ``(N, ...)``,
      where N is the number of examples (sample-size).
      Your ``model`` must be able to ``fit()`` and ``predict()`` data of this format.
  
  y :
      An array of shape ``(N,)`` of noisy labels (i.e. target/response/dependant variable), where some values may be erroneous.
  
  label_issues :
      Optional already-identified label issues in the dataset (if previously estimated).
      Specify this to avoid re-estimating the label issues if already done.
      If ``pd.DataFrame``, must be formatted as the one returned by:
      :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>` or
      :py:meth:`self.get_label_issues <cleanlab.regression.learn.CleanLearning.get_label_issues>`. The DataFrame must
      have a column named ``is_label_issue``.
  
      If ``np.ndarray``, the input must be a boolean mask of length ``N`` where examples that have label issues
      have the value ``True``, and the rest of the examples have the value ``False``.
  
  sample_weight :
      Optional array of weights with shape ``(N,)`` that are assigned to individual samples. Specifies how to weight the examples in
      the loss function while training.
  
  find_label_issues_kwargs:
      Optional keyword arguments to pass into :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`.
  
  model_kwargs :
      Optional keyword arguments to pass into model's ``fit()`` method.
  
  model_final_kwargs :
      Optional extra keyword arguments to pass into the final model's ``fit()`` on the cleaned data,
      but not the ``fit()`` in each fold of cross-validation on the noisy data.
      The final ``fit()`` will also receive the arguments in `clf_kwargs`, but these may be overwritten
      by values in `clf_final_kwargs`. This can be useful for training differently in the final ``fit()``
      than during cross-validation.
  
  Returns
  -------
  self : CleanLearning
      Fitted estimator that has all the same methods as any sklearn estimator.
  
      After calling ``self.fit()``, this estimator also stores extra attributes such as:
  
      - ``self.label_issues_df``: a ``pd.DataFrame`` containing label quality scores, boolean flags
          indicating which examples have label issues, and predicted label values for each example.
          Accessible via :py:meth:`self.get_label_issues <cleanlab.regression.learn.CleanLearning.get_label_issues>`,
          of similar format as the one returned by :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`.
          See documentation of :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`
          for column descriptions.
      - ``self.label_issues_mask``: a ``np.ndarray`` boolean mask indicating if a particular
          example has been identified to have issues.
docstr_tok: ["Train","regression","``","model","``","with","error-prone",",","noisy","labels","as","if","the","model","had","been","instead","trained","on","a","dataset","with","the","correct","labels",".","``","fit","``","achieves","this","by","first","training","``","model","``","via","cross-validation","on","the","noisy","data",",","using","the","resulting","predicted","probabilities","to","identify","label","issues",",","pruning","the","data","with","label","issues",",","and","finally","training","``","model","``","on","the","remaining","clean","data",".","Parameters","--","--","--","--","--","X",":","Data","features","(","i.e",".","covariates",",","independent","variables",")",",","typically","an","array","of","shape","``","(","N",",","...",")","``",",","where","N","is","the","number","of","examples","(","sample-size",")",".","Your","``","model","``","must","be","able","to","``","fit","(",")","``","and","``","predict","(",")","``","data","of","this","format",".","y",":","An","array","of","shape","``","(","N",",",")","``","of","noisy","labels","(","i.e",".","target\/response\/dependant","variable",")",",","where","some","values","may","be","erroneous",".","label_issues",":","Optional","already-identified","label","issues","in","the","dataset","(","if","previously","estimated",")",".","Specify","this","to","avoid","re-estimating","the","label","issues","if","already","done",".","If","``","pd.DataFrame","``",",","must","be","formatted","as","the","one","returned","by",":",":","py",":","meth",":","`","self.find_label_issues","<","cleanlab.regression.learn.CleanLearning.find_label_issues",">","`","or",":","py",":","meth",":","`","self.get_label_issues","<","cleanlab.regression.learn.CleanLearning.get_label_issues",">","`",".","The","DataFrame","must","have","a","column","named","``","is_label_issue","``",".","If","``","np.ndarray","``",",","the","input","must","be","a","boolean","mask","of","length","``","N","``","where","examples","that","have","label","issues","have","the","value","``","True","``",",","and","the","rest","of","the","examples","have","the","value","``","False","``",".","sample_weight",":","Optional","array","of","weights","with","shape","``","(","N",",",")","``","that","are","assigned","to","individual","samples",".","Specifies","how","to","weight","the","examples","in","the","loss","function","while","training",".","find_label_issues_kwargs",":","Optional","keyword","arguments","to","pass","into",":","py",":","meth",":","`","self.find_label_issues","<","cleanlab.regression.learn.CleanLearning.find_label_issues",">","`",".","model_kwargs",":","Optional","keyword","arguments","to","pass","into","model","'s","``","fit","(",")","``","method",".","model_final_kwargs",":","Optional","extra","keyword","arguments","to","pass","into","the","final","model","'s","``","fit","(",")","``","on","the","cleaned","data",",","but","not","the","``","fit","(",")","``","in","each","fold","of","cross-validation","on","the","noisy","data",".","The","final","``","fit","(",")","``","will","also","receive","the","arguments","in","`","clf_kwargs","`",",","but","these","may","be","overwritten","by","values","in","`","clf_final_kwargs","`",".","This","can","be","useful","for","training","differently","in","the","final","``","fit","(",")","``","than","during","cross-validation",".","Returns","--","--","--","-","self",":","CleanLearning","Fitted","estimator","that","has","all","the","same","methods","as","any","sklearn","estimator",".","After","calling","``","self.fit","(",")","``",",","this","estimator","also","stores","extra","attributes","such","as",":","-","``","self.label_issues_df","``",":","a","``","pd.DataFrame","``","containing","label","quality","scores",",","boolean","flags","indicating","which","examples","have","label","issues",",","and","predicted","label","values","for","each","example",".","Accessible","via",":","py",":","meth",":","`","self.get_label_issues","<","cleanlab.regression.learn.CleanLearning.get_label_issues",">","`",",","of","similar","format","as","the","one","returned","by",":","py",":","meth",":","`","self.find_label_issues","<","cleanlab.regression.learn.CleanLearning.find_label_issues",">","`",".","See","documentation","of",":","py",":","meth",":","`","self.find_label_issues","<","cleanlab.regression.learn.CleanLearning.find_label_issues",">","`","for","column","descriptions",".","-","``","self.label_issues_mask","``",":","a","``","np.ndarray","``","boolean","mask","indicating","if","a","particular","example","has","been","identified","to","have","issues","."]
code: def fit(
      self,
      X: Union[np.ndarray, pd.DataFrame],
      y: LabelLike,
      *,
      label_issues: Optional[Union[pd.DataFrame, np.ndarray]] = None,
      sample_weight: Optional[np.ndarray] = None,
      find_label_issues_kwargs: Optional[dict] = None,
      model_kwargs: Optional[dict] = None,
      model_final_kwargs: Optional[dict] = None,
  ) -> BaseEstimator:
      """
      Train regression ``model`` with error-prone, noisy labels as if the model had been instead trained
      on a dataset with the correct labels. ``fit`` achieves this by first training ``model`` via
      cross-validation on the noisy data, using the resulting predicted probabilities to identify label issues,
      pruning the data with label issues, and finally training ``model`` on the remaining clean data.
  
      Parameters
      ----------
      X :
          Data features (i.e. covariates, independent variables), typically an array of shape ``(N, ...)``,
          where N is the number of examples (sample-size).
          Your ``model`` must be able to ``fit()`` and ``predict()`` data of this format.
  
      y :
          An array of shape ``(N,)`` of noisy labels (i.e. target/response/dependant variable), where some values may be erroneous.
  
      label_issues :
          Optional already-identified label issues in the dataset (if previously estimated).
          Specify this to avoid re-estimating the label issues if already done.
          If ``pd.DataFrame``, must be formatted as the one returned by:
          :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>` or
          :py:meth:`self.get_label_issues <cleanlab.regression.learn.CleanLearning.get_label_issues>`. The DataFrame must
          have a column named ``is_label_issue``.
  
          If ``np.ndarray``, the input must be a boolean mask of length ``N`` where examples that have label issues
          have the value ``True``, and the rest of the examples have the value ``False``.
  
      sample_weight :
          Optional array of weights with shape ``(N,)`` that are assigned to individual samples. Specifies how to weight the examples in
          the loss function while training.
  
      find_label_issues_kwargs:
          Optional keyword arguments to pass into :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`.
  
      model_kwargs :
          Optional keyword arguments to pass into model's ``fit()`` method.
  
      model_final_kwargs :
          Optional extra keyword arguments to pass into the final model's ``fit()`` on the cleaned data,
          but not the ``fit()`` in each fold of cross-validation on the noisy data.
          The final ``fit()`` will also receive the arguments in `clf_kwargs`, but these may be overwritten
          by values in `clf_final_kwargs`. This can be useful for training differently in the final ``fit()``
          than during cross-validation.
  
      Returns
      -------
      self : CleanLearning
          Fitted estimator that has all the same methods as any sklearn estimator.
  
          After calling ``self.fit()``, this estimator also stores extra attributes such as:
  
          - ``self.label_issues_df``: a ``pd.DataFrame`` containing label quality scores, boolean flags
              indicating which examples have label issues, and predicted label values for each example.
              Accessible via :py:meth:`self.get_label_issues <cleanlab.regression.learn.CleanLearning.get_label_issues>`,
              of similar format as the one returned by :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`.
              See documentation of :py:meth:`self.find_label_issues <cleanlab.regression.learn.CleanLearning.find_label_issues>`
              for column descriptions.
          - ``self.label_issues_mask``: a ``np.ndarray`` boolean mask indicating if a particular
              example has been identified to have issues.
      """
      assert_valid_regression_inputs(X, y)
  
      if find_label_issues_kwargs is None:
          find_label_issues_kwargs = {}
      if model_kwargs is None:
          model_kwargs = {}
      if model_final_kwargs is None:
          model_final_kwargs = {}
      model_final_kwargs = {**model_kwargs, **model_final_kwargs}
  
      if (
          "sample_weight" in model_kwargs
          or "sample_weight" in model_final_kwargs
      ):
          raise ValueError(
              "sample_weight should be provided directly in fit() rather than in model_kwargs or model_final_kwargs"
          )
  
      if sample_weight is not None:
          if (
              "sample_weight"
              not in inspect.signature(self.model.fit).parameters
          ):
              raise ValueError(
                  "sample_weight must be a supported fit() argument for your model in order to be specified here"
              )
          if len(sample_weight) != len(X):
              raise ValueError(
                  "sample_weight must be a 1D array that has the same length as y."
              )
  
      if label_issues is None:
          if self.label_issues_df is not None and self.verbose:
              print(
                  "If you already ran self.find_label_issues() and don't want to recompute, you "
                  "should pass the label_issues in as a parameter to this function next time."
              )
  
          label_issues = self.find_label_issues(
              X,
              y,
              model_kwargs=model_kwargs,
              **find_label_issues_kwargs,
          )
      else:
          if self.verbose:
              print(
                  "Using provided label_issues instead of finding label issues."
              )
              if self.label_issues_df is not None:
                  print(
                      "These will overwrite self.label_issues_df and will be returned by "
                      "`self.get_label_issues()`. "
                  )
  
      self.label_issues_df = self._process_label_issues_arg(
          label_issues, y
      )
      self.label_issues_mask = self.label_issues_df[
          "is_label_issue"
      ].to_numpy()
  
      X_mask = np.invert(self.label_issues_mask)
      X_cleaned, y_cleaned = subset_X_y(X, y, X_mask)
      if self.verbose:
          print(
              f"Pruning {np.sum(self.label_issues_mask)} examples with label issues ..."
          )
          print(f"Remaining clean data has {len(y_cleaned)} examples.")
  
      if sample_weight is not None:
          model_final_kwargs["sample_weight"] = sample_weight[X_mask]
          if self.verbose:
              print(
                  "Fitting final model on the clean data with custom sample_weight ..."
              )
      else:
          if self.verbose:
              print("Fitting final model on the clean data ...")
  
      self.model.fit(X_cleaned, y_cleaned, **model_final_kwargs)
  
      if self.verbose:
          print(
              "Label issues stored in label_issues_df DataFrame accessible via: self.get_label_issues(). "
              "Call self.save_space() to delete this potentially large DataFrame attribute."
          )
      return self
  
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 2 for calling the CleanLearning obj's underlying member method code with example usage: obj.fit(X, y) and returns: self