class_docstr: A Trainer for scikit-learn estimator training.
  
  This Trainer runs the ``fit`` method of the given estimator in a
  non-distributed manner on a single Ray Actor.
  
  By default, the ``n_jobs`` (or ``thread_count``) estimator parameters will be set
  to match the number of CPUs assigned to the Ray Actor. This behavior can be
  disabled by setting ``set_estimator_cpus=False``.
  
  If you wish to use GPU-enabled estimators (eg. cuML), make sure to
  set ``"GPU": 1`` in ``scaling_config.trainer_resources``.
  
  The results are reported all at once and not in an iterative fashion.
  No checkpointing is done during training. This may be changed
  in the future.
  
  Example:
  
  .. testcode::
  
      import ray
  
      from ray.train.sklearn import SklearnTrainer
      from sklearn.ensemble import RandomForestRegressor
  
      train_dataset = ray.data.from_items(
          [{"x": x, "y": x + 1} for x in range(32)])
      trainer = SklearnTrainer(
          estimator=RandomForestRegressor(),
          label_column="y",
          scaling_config=ray.train.ScalingConfig(
              trainer_resources={"CPU": 4}
          ),
          datasets={"train": train_dataset}
      )
      result = trainer.fit()
  
  .. testoutput::
      :hide:
  
      ...
  
  Args:
      estimator: A scikit-learn compatible estimator to use.
      datasets: Datasets to use for training and validation. Must include a
          "train" key denoting the training dataset. All non-training datasets will
          be used as separate validation sets, each reporting separate metrics.
      label_column: Name of the label column. A column with this name
          must be present in the training dataset. If None, no validation
          will be performed.
      params: Optional dict of params to be set on the estimator before
          fitting. Useful for hyperparameter tuning.
      scoring: Strategy to evaluate the performance of the model on
          the validation sets and for cross-validation. Same as in
          ``sklearn.model_selection.cross_validation``.
          If ``scoring`` represents a single score, one can use:
  
          - a single string;
          - a callable that returns a single value.
  
          If ``scoring`` represents multiple scores, one can use:
  
          - a list or tuple of unique strings;
          - a callable returning a dictionary where the keys are the metric
            names and the values are the metric scores;
          - a dictionary with metric names as keys and callables a values.
  
      cv: Determines the cross-validation splitting strategy. If specified,
          cross-validation will be run on the train dataset, in addition to
          computing metrics for validation datasets. Same as in
          ``sklearn.model_selection.cross_validation``, with the exception of
          None.
          Possible inputs for ``cv`` are:
  
          - None, to skip cross-validation.
          - int, to specify the number of folds in a ``(Stratified)KFold``,
          - ``CV splitter``,
          - An iterable yielding (train, test) splits as arrays of indices.
  
          For int/None inputs, if the estimator is a classifier and ``y`` is
          either binary or multiclass, ``StratifiedKFold`` is used. In all
          other cases, ``KFold`` is used. These splitters are instantiated
          with ``shuffle=False`` so the splits will be the same across calls.
  
          If you provide a "cv_groups" column in the train dataset, it will be
          used as group labels for the samples used while splitting the dataset into
          train/test set. Only used in conjunction with a "Group" ``cv``
          instance (e.g., ``GroupKFold``). This corresponds to the ``groups``
          argument in ``sklearn.model_selection.cross_validation``.
      return_train_score_cv: Whether to also return train scores during
          cross-validation. Ignored if ``cv`` is None.
      parallelize_cv: If set to True, will parallelize cross-validation
          instead of the estimator. If set to None, will detect if the estimator
          has any parallelism-related params (``n_jobs`` or ``thread_count``)
          and parallelize cross-validation if there are none.
          If False, will not parallelize cross-validation. Cannot be
          set to True if there are any GPUs assigned to the trainer.
          Ignored if ``cv`` is None.
      set_estimator_cpus: If set to True, will automatically set
          the values of all ``n_jobs`` and ``thread_count`` parameters
          in the estimator (including in nested objects) to match
          the number of available CPUs.
      scaling_config: Configuration for how to scale training.
          Only the ``trainer_resources`` key can be provided,
          as the training is not distributed.
      run_config: Configuration for the execution of the training run.
      metadata: Dict that should be made available in `checkpoint.get_metadata()`
          for checkpoints saved from this Trainer. Must be JSON-serializable.
      **fit_params: Additional kwargs passed to ``estimator.fit()``
          method.
class_docstr_tok: ["A","Trainer","for","scikit-learn","estimator","training",".","This","Trainer","runs","the","``","fit","``","method","of","the","given","estimator","in","a","non-distributed","manner","on","a","single","Ray","Actor",".","By","default",",","the","``","n_jobs","``","(","or","``","thread_count","``",")","estimator","parameters","will","be","set","to","match","the","number","of","CPUs","assigned","to","the","Ray","Actor",".","This","behavior","can","be","disabled","by","setting","``","set_estimator_cpus=False","``",".","If","you","wish","to","use","GPU-enabled","estimators","(","eg",".","cuML",")",",","make","sure","to","set","``","``","GPU","''",":","1","``","in","``","scaling_config.trainer_resources","``",".","The","results","are","reported","all","at","once","and","not","in","an","iterative","fashion",".","No","checkpointing","is","done","during","training",".","This","may","be","changed","in","the","future",".","Example",":","..","testcode",":",":","import","ray","from","ray.train.sklearn","import","SklearnTrainer","from","sklearn.ensemble","import","RandomForestRegressor","train_dataset","=","ray.data.from_items","(","[","{","``","x","''",":","x",",","``","y","''",":","x","+","1","}","for","x","in","range","(","32",")","]",")","trainer","=","SklearnTrainer","(","estimator=RandomForestRegressor","(",")",",","label_column=","''","y","''",",","scaling_config=ray.train.ScalingConfig","(","trainer_resources=","{","``","CPU","''",":","4","}",")",",","datasets=","{","``","train","''",":","train_dataset","}",")","result","=","trainer.fit","(",")","..","testoutput",":",":",":","hide",":","...","Args",":","estimator",":","A","scikit-learn","compatible","estimator","to","use",".","datasets",":","Datasets","to","use","for","training","and","validation",".","Must","include","a","``","train","''","key","denoting","the","training","dataset",".","All","non-training","datasets","will","be","used","as","separate","validation","sets",",","each","reporting","separate","metrics",".","label_column",":","Name","of","the","label","column",".","A","column","with","this","name","must","be","present","in","the","training","dataset",".","If","None",",","no","validation","will","be","performed",".","params",":","Optional","dict","of","params","to","be","set","on","the","estimator","before","fitting",".","Useful","for","hyperparameter","tuning",".","scoring",":","Strategy","to","evaluate","the","performance","of","the","model","on","the","validation","sets","and","for","cross-validation",".","Same","as","in","``","sklearn.model_selection.cross_validation","``",".","If","``","scoring","``","represents","a","single","score",",","one","can","use",":","-","a","single","string",";","-","a","callable","that","returns","a","single","value",".","If","``","scoring","``","represents","multiple","scores",",","one","can","use",":","-","a","list","or","tuple","of","unique","strings",";","-","a","callable","returning","a","dictionary","where","the","keys","are","the","metric","names","and","the","values","are","the","metric","scores",";","-","a","dictionary","with","metric","names","as","keys","and","callables","a","values",".","cv",":","Determines","the","cross-validation","splitting","strategy",".","If","specified",",","cross-validation","will","be","run","on","the","train","dataset",",","in","addition","to","computing","metrics","for","validation","datasets",".","Same","as","in","``","sklearn.model_selection.cross_validation","``",",","with","the","exception","of","None",".","Possible","inputs","for","``","cv","``","are",":","-","None",",","to","skip","cross-validation",".","-","int",",","to","specify","the","number","of","folds","in","a","``","(","Stratified",")","KFold","``",",","-","``","CV","splitter","``",",","-","An","iterable","yielding","(","train",",","test",")","splits","as","arrays","of","indices",".","For","int\/None","inputs",",","if","the","estimator","is","a","classifier","and","``","y","``","is","either","binary","or","multiclass",",","``","StratifiedKFold","``","is","used",".","In","all","other","cases",",","``","KFold","``","is","used",".","These","splitters","are","instantiated","with","``","shuffle=False","``","so","the","splits","will","be","the","same","across","calls",".","If","you","provide","a","``","cv_groups","''","column","in","the","train","dataset",",","it","will","be","used","as","group","labels","for","the","samples","used","while","splitting","the","dataset","into","train\/test","set",".","Only","used","in","conjunction","with","a","``","Group","''","``","cv","``","instance","(","e.g.",",","``","GroupKFold","``",")",".","This","corresponds","to","the","``","groups","``","argument","in","``","sklearn.model_selection.cross_validation","``",".","return_train_score_cv",":","Whether","to","also","return","train","scores","during","cross-validation",".","Ignored","if","``","cv","``","is","None",".","parallelize_cv",":","If","set","to","True",",","will","parallelize","cross-validation","instead","of","the","estimator",".","If","set","to","None",",","will","detect","if","the","estimator","has","any","parallelism-related","params","(","``","n_jobs","``","or","``","thread_count","``",")","and","parallelize","cross-validation","if","there","are","none",".","If","False",",","will","not","parallelize","cross-validation",".","Can","not","be","set","to","True","if","there","are","any","GPUs","assigned","to","the","trainer",".","Ignored","if","``","cv","``","is","None",".","set_estimator_cpus",":","If","set","to","True",",","will","automatically","set","the","values","of","all","``","n_jobs","``","and","``","thread_count","``","parameters","in","the","estimator","(","including","in","nested","objects",")","to","match","the","number","of","available","CPUs",".","scaling_config",":","Configuration","for","how","to","scale","training",".","Only","the","``","trainer_resources","``","key","can","be","provided",",","as","the","training","is","not","distributed",".","run_config",":","Configuration","for","the","execution","of","the","training","run",".","metadata",":","Dict","that","should","be","made","available","in","`","checkpoint.get_metadata","(",")","`","for","checkpoints","saved","from","this","Trainer",".","Must","be","JSON-serializable",".","*","*","fit_params",":","Additional","kwargs","passed","to","``","estimator.fit","(",")","``","method","."]
code: def _score_on_validation_sets(
      self,
      estimator: BaseEstimator,
      datasets: Dict[str, Tuple[pd.DataFrame, pd.Series]],
  ) -> Dict[str, Dict[str, Any]]:
      results = defaultdict(dict)
  
      if not datasets:
          return results
  
      if callable(self.scoring):
          scorers = self.scoring
      elif self.scoring is None or isinstance(self.scoring, str):
          scorers = check_scoring(estimator, self.scoring)
      else:
          scorers = _check_multimetric_scoring(estimator, self.scoring)
      for key, X_y_tuple in datasets.items():
          X_test, y_test = X_y_tuple
          start_time = time()
          try:
              test_scores = _score(estimator, X_test, y_test, scorers)
          except Exception:
              if isinstance(scorers, dict):
                  test_scores = {k: np.nan for k in scorers}
              else:
                  test_scores = np.nan
              warnings.warn(
                  f"Scoring on validation set {key} failed. The score(s) for "
                  f"this set will be set to nan. Details: \n"
                  f"{format_exc()}",
                  UserWarning,
              )
          score_time = time() - start_time
          results[key]["score_time"] = score_time
          if not isinstance(test_scores, dict):
              test_scores = {"score": test_scores}
  
          for name in test_scores:
              results[key][f"test_{name}"] = test_scores[name]
      return results
  
imports: import logging
  import os
  import tempfile
  import warnings
  from collections import defaultdict
  from time import time
  from traceback import format_exc
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Optional, Tuple, Union
  import numpy
  import pandas
  from joblib import parallel_backend
  from sklearn.base import BaseEstimator, clone
  from sklearn.metrics import check_scoring
  from sklearn.model_selection import BaseCrossValidator, cross_validate
  from sklearn.model_selection._validation import _check_multimetric_scoring, _score
  import ray.cloudpickle
  from ray import train
  from ray.train import Checkpoint, RunConfig, ScalingConfig
  from ray.train.constants import TRAIN_DATASET_KEY
  from ray.train.sklearn import SklearnCheckpoint
  from ray.train.sklearn._sklearn_utils import _has_cpu_params, _set_cpu_params
  from ray.train.trainer import BaseTrainer, GenDataset
  from ray.util import PublicAPI
  from ray.util.joblib import register_ray
label_desc: Use image node_id 4 for calling the SklearnTrainer obj's underlying member method code with example usage: obj._score_on_validation_sets(estimator, datasets) and returns: results, results