class_docstr: Base class for hyper parameter search with cross-validation.
class_docstr_tok: ["Base","class","for","hyper","parameter","search","with","cross-validation","."]
docstr: Actual fitting,  performing the search over parameters.
code: def _fit(self, X, y, parameter_iterable):
      """Actual fitting,  performing the search over parameters."""
  
      estimator = self.estimator
      cv = self.cv
      self.scorer_ = check_scoring(self.estimator, scoring=self.scoring)
  
      n_samples = _num_samples(X)
      X, y = indexable(X, y)
  
      if y is not None:
          if len(y) != n_samples:
              raise ValueError(
                  "Target variable (y) has a different number "
                  "of samples (%i) than data (X: %i samples)"
                  % (len(y), n_samples)
              )
      cv = check_cv(cv, X, y, classifier=is_classifier(estimator))
  
      if self.verbose > 0:
          if isinstance(parameter_iterable, Sized):
              n_candidates = len(parameter_iterable)
              print(
                  "Fitting {0} folds for each of {1} candidates, totalling"
                  " {2} fits".format(
                      len(cv), n_candidates, n_candidates * len(cv)
                  )
              )
  
      base_estimator = clone(self.estimator)
  
      pre_dispatch = self.pre_dispatch
  
      out = Parallel(
          n_jobs=self.n_jobs,
          verbose=self.verbose,
          pre_dispatch=pre_dispatch,
      )(
          delayed(_fit_and_score)(
              clone(base_estimator),
              X,
              y,
              self.scorer_,
              train,
              test,
              self.verbose,
              parameters,
              self.fit_params,
              return_parameters=True,
              error_score=self.error_score,
          )
          for parameters in parameter_iterable
          for train, test in cv
      )
  
      # Out is a list of triplet: score, estimator, n_test_samples
      n_fits = len(out)
      n_folds = len(cv)
  
      scores = list()
      grid_scores = list()
      for grid_start in range(0, n_fits, n_folds):
          n_test_samples = 0
          score = 0
          all_scores = []
          for this_score, this_n_test_samples, _, parameters in out[
              grid_start : grid_start + n_folds
          ]:
              all_scores.append(this_score)
              if self.iid:
                  this_score *= this_n_test_samples
                  n_test_samples += this_n_test_samples
              score += this_score
          if self.iid:
              score /= float(n_test_samples)
          else:
              score /= float(n_folds)
          scores.append((score, parameters))
          # TODO: shall we also store the test_fold_sizes?
          grid_scores.append(
              _CVScoreTuple(parameters, score, np.array(all_scores))
          )
      # Store the computed scores
      self.grid_scores_ = grid_scores
  
      # Find the best parameters by comparing on the mean validation score:
      # note that `sorted` is deterministic in the way it breaks ties
      best = sorted(
          grid_scores,
          key=lambda x: x.mean_validation_score,
          reverse=True,
      )[0]
      self.best_params_ = best.parameters
      self.best_score_ = best.mean_validation_score
  
      if self.refit:
          # fit the best estimator using the entire dataset
          # clone first to work around broken estimators
          best_estimator = clone(base_estimator).set_params(
              **best.parameters
          )
          if y is not None:
              best_estimator.fit(X, y, **self.fit_params)
          else:
              best_estimator.fit(X, **self.fit_params)
          self.best_estimator_ = best_estimator
      return self
  
imports: from __future__ import print_function
  from abc import ABCMeta, abstractmethod
  from collections import Mapping, namedtuple, Sized
  from functools import partial, reduce
  from itertools import product
  import operator
  import warnings
  import numpy
  from .base import BaseEstimator, is_classifier, clone
  from .base import MetaEstimatorMixin
  from .cross_validation import check_cv
  from .cross_validation import _fit_and_score
  from .externals.joblib import Parallel, delayed
  from .externals import six
  from .utils import check_random_state
  from .utils.random import sample_without_replacement
  from .utils.validation import _num_samples, indexable
  from .utils.metaestimators import if_delegate_has_method
  from .metrics.scorer import check_scoring
  from .exceptions import ChangedBehaviorWarning
label_desc: Use image node_id 10 for calling the BaseSearchCV obj's underlying member method code with example usage: obj._fit(X, y, parameter_iterable) and returns: self