class_docstr: Abstract base class for hyper parameter search with cross-validation.
class_docstr_tok: ["Abstract","base","class","for","hyper","parameter","search","with","cross-validation","."]
docstr: Run fit with all sets of parameters.
  
  Parameters
  ----------
  
  X : array-like of shape (n_samples, n_features)
      Training vector, where `n_samples` is the number of samples and
      `n_features` is the number of features.
  
  y : array-like of shape (n_samples, n_output)             or (n_samples,), default=None
      Target relative to X for classification or regression;
      None for unsupervised learning.
  
  groups : array-like of shape (n_samples,), default=None
      Group labels for the samples used while splitting the dataset into
      train/test set. Only used in conjunction with a "Group" :term:`cv`
      instance (e.g., :class:`~sklearn.model_selection.GroupKFold`).
  
  **fit_params : dict of str -> object
      Parameters passed to the `fit` method of the estimator.
  
      If a fit parameter is an array-like whose length is equal to
      `num_samples` then it will be split across CV groups along with `X`
      and `y`. For example, the :term:`sample_weight` parameter is split
      because `len(sample_weights) = len(X)`.
  
  Returns
  -------
  self : object
      Instance of fitted estimator.
docstr_tok: ["Run","fit","with","all","sets","of","parameters",".","Parameters","--","--","--","--","--","X",":","array-like","of","shape","(","n_samples",",","n_features",")","Training","vector",",","where","`","n_samples","`","is","the","number","of","samples","and","`","n_features","`","is","the","number","of","features",".","y",":","array-like","of","shape","(","n_samples",",","n_output",")","or","(","n_samples",",",")",",","default=None","Target","relative","to","X","for","classification","or","regression",";","None","for","unsupervised","learning",".","groups",":","array-like","of","shape","(","n_samples",",",")",",","default=None","Group","labels","for","the","samples","used","while","splitting","the","dataset","into","train\/test","set",".","Only","used","in","conjunction","with","a","``","Group","''",":","term",":","`","cv","`","instance","(","e.g.",",",":","class",":","`","~sklearn.model_selection.GroupKFold","`",")",".","*","*","fit_params",":","dict","of","str","-",">","object","Parameters","passed","to","the","`","fit","`","method","of","the","estimator",".","If","a","fit","parameter","is","an","array-like","whose","length","is","equal","to","`","num_samples","`","then","it","will","be","split","across","CV","groups","along","with","`","X","`","and","`","y","`",".","For","example",",","the",":","term",":","`","sample_weight","`","parameter","is","split","because","`","len","(","sample_weights",")","=","len","(","X",")","`",".","Returns","--","--","--","-","self",":","object","Instance","of","fitted","estimator","."]
code: def fit(self, X, y=None, *, groups=None, **fit_params):
      """Run fit with all sets of parameters.
  
          Parameters
          ----------
  
          X : array-like of shape (n_samples, n_features)
              Training vector, where `n_samples` is the number of samples and
              `n_features` is the number of features.
  
          y : array-like of shape (n_samples, n_output) \
              or (n_samples,), default=None
              Target relative to X for classification or regression;
              None for unsupervised learning.
  
          groups : array-like of shape (n_samples,), default=None
              Group labels for the samples used while splitting the dataset into
              train/test set. Only used in conjunction with a "Group" :term:`cv`
              instance (e.g., :class:`~sklearn.model_selection.GroupKFold`).
  
          **fit_params : dict of str -> object
              Parameters passed to the `fit` method of the estimator.
  
              If a fit parameter is an array-like whose length is equal to
              `num_samples` then it will be split across CV groups along with `X`
              and `y`. For example, the :term:`sample_weight` parameter is split
              because `len(sample_weights) = len(X)`.
  
          Returns
          -------
          self : object
              Instance of fitted estimator.
          """
      estimator = self.estimator
      refit_metric = "score"
  
      if callable(self.scoring):
          scorers = self.scoring
      elif self.scoring is None or isinstance(self.scoring, str):
          scorers = check_scoring(self.estimator, self.scoring)
      else:
          scorers = _check_multimetric_scoring(
              self.estimator, self.scoring
          )
          self._check_refit_for_multimetric(scorers)
          refit_metric = self.refit
  
      X, y, groups = indexable(X, y, groups)
      fit_params = _check_fit_params(X, fit_params)
  
      cv_orig = check_cv(
          self.cv, y, classifier=is_classifier(estimator)
      )
      n_splits = cv_orig.get_n_splits(X, y, groups)
  
      base_estimator = clone(self.estimator)
  
      parallel = Parallel(
          n_jobs=self.n_jobs, pre_dispatch=self.pre_dispatch
      )
  
      fit_and_score_kwargs = dict(
          scorer=scorers,
          fit_params=fit_params,
          return_train_score=self.return_train_score,
          return_n_test_samples=True,
          return_times=True,
          return_parameters=False,
          error_score=self.error_score,
          verbose=self.verbose,
      )
      results = {}
      with parallel:
          all_candidate_params = []
          all_out = []
          all_more_results = defaultdict(list)
  
          def evaluate_candidates(
              candidate_params, cv=None, more_results=None
          ):
              cv = cv or cv_orig
              candidate_params = list(candidate_params)
              n_candidates = len(candidate_params)
  
              if self.verbose > 0:
                  print(
                      "Fitting {0} folds for each of {1} candidates,"
                      " totalling {2} fits".format(
                          n_splits,
                          n_candidates,
                          n_candidates * n_splits,
                      )
                  )
  
              out = parallel(
                  delayed(_fit_and_score)(
                      clone(base_estimator),
                      X,
                      y,
                      train=train,
                      test=test,
                      parameters=parameters,
                      split_progress=(split_idx, n_splits),
                      candidate_progress=(cand_idx, n_candidates),
                      **fit_and_score_kwargs,
                  )
                  for (cand_idx, parameters), (
                      split_idx,
                      (train, test),
                  ) in product(
                      enumerate(candidate_params),
                      enumerate(cv.split(X, y, groups)),
                  )
              )
  
              if len(out) < 1:
                  raise ValueError(
                      "No fits were performed. "
                      "Was the CV iterator empty? "
                      "Were there no candidates?"
                  )
              elif len(out) != n_candidates * n_splits:
                  raise ValueError(
                      "cv.split and cv.get_n_splits returned "
                      "inconsistent results. Expected {} "
                      "splits, got {}".format(
                          n_splits, len(out) // n_candidates
                      )
                  )
  
              _warn_or_raise_about_fit_failures(out, self.error_score)
  
              # For callable self.scoring, the return type is only know after
              # calling. If the return type is a dictionary, the error scores
              # can now be inserted with the correct key. The type checking
              # of out will be done in `_insert_error_scores`.
              if callable(self.scoring):
                  _insert_error_scores(out, self.error_score)
  
              all_candidate_params.extend(candidate_params)
              all_out.extend(out)
  
              if more_results is not None:
                  for key, value in more_results.items():
                      all_more_results[key].extend(value)
  
              nonlocal results
              results = self._format_results(
                  all_candidate_params,
                  n_splits,
                  all_out,
                  all_more_results,
              )
  
              return results
  
          self._run_search(evaluate_candidates)
  
          # multimetric is determined here because in the case of a callable
          # self.scoring the return type is only known after calling
          first_test_score = all_out[0]["test_scores"]
          self.multimetric_ = isinstance(first_test_score, dict)
  
          # check refit_metric now for a callabe scorer that is multimetric
          if callable(self.scoring) and self.multimetric_:
              self._check_refit_for_multimetric(first_test_score)
              refit_metric = self.refit
  
      # For multi-metric evaluation, store the best_index_, best_params_ and
      # best_score_ iff refit is one of the scorer names
      # In single metric evaluation, refit_metric is "score"
      if self.refit or not self.multimetric_:
          self.best_index_ = self._select_best_index(
              self.refit, refit_metric, results
          )
          if not callable(self.refit):
              # With a non-custom callable, we can select the best score
              # based on the best index
              self.best_score_ = results[f"mean_test_{refit_metric}"][
                  self.best_index_
              ]
          self.best_params_ = results["params"][self.best_index_]
  
      if self.refit:
          # here we clone the estimator as well as the parameters, since
          # sometimes the parameters themselves might be estimators, e.g.
          # when we search over different estimators in a pipeline.
          # ref: https://github.com/scikit-learn/scikit-learn/pull/26786
          self.best_estimator_ = clone(base_estimator).set_params(
              **clone(self.best_params_, safe=False)
          )
  
          refit_start_time = time.time()
          if y is not None:
              self.best_estimator_.fit(X, y, **fit_params)
          else:
              self.best_estimator_.fit(X, **fit_params)
          refit_end_time = time.time()
          self.refit_time_ = refit_end_time - refit_start_time
  
          if hasattr(self.best_estimator_, "feature_names_in_"):
              self.feature_names_in_ = (
                  self.best_estimator_.feature_names_in_
              )
  
      # Store the only scorer not as a dict for single metric evaluation
      self.scorer_ = scorers
  
      self.cv_results_ = results
      self.n_splits_ = n_splits
  
      return self
  
imports: import numbers
  import operator
  import time
  import warnings
  from abc import ABCMeta, abstractmethod
  from collections import defaultdict
  from collections.abc import Iterable, Mapping, Sequence
  from functools import partial, reduce
  from itertools import product
  import numpy
  from numpy.ma import MaskedArray
  from scipy.stats import rankdata
  from ..base import BaseEstimator, MetaEstimatorMixin, _fit_context, clone, is_classifier
  from ..exceptions import NotFittedError
  from ..metrics import check_scoring
  from ..metrics._scorer import _check_multimetric_scoring, get_scorer_names
  from ..utils import check_random_state
  from ..utils._param_validation import HasMethods, Interval, StrOptions
  from ..utils._tags import _safe_tags
  from ..utils.metaestimators import available_if
  from ..utils.parallel import Parallel, delayed
  from ..utils.random import sample_without_replacement
  from ..utils.validation import _check_fit_params, check_is_fitted, indexable
  from ._split import check_cv
  from ._validation import _aggregate_score_dicts, _fit_and_score, _insert_error_scores, _normalize_score_results, _warn_or_raise_about_fit_failures
label_desc: Use image node_id 17 for calling the BaseSearchCV obj's underlying member method code with example usage: obj.fit(X, y) and returns: self, results