parameters: (self, X, y, sample_weight=None)
return_statement: return self
docstring: Fit the estimators.
  
          Parameters
          ----------
          X : {array-like, sparse matrix} of shape (n_samples, n_features)
              Training vectors, where `n_samples` is the number of samples and
              `n_features` is the number of features.
  
          y : array-like of shape (n_samples,)
              Target values.
  
          sample_weight : array-like of shape (n_samples,) or None
              Sample weights. If None, then samples are equally weighted.
              Note that this is supported only if all underlying estimators
              support sample weights.
  
          Returns
          -------
          self : object
docstring_summary: Fit the estimators.
docstring_tokens: Fit the estimators .
function: def fit(self, X, y, sample_weight=None):
          """Fit the estimators.
  
          Parameters
          ----------
          X : {array-like, sparse matrix} of shape (n_samples, n_features)
              Training vectors, where `n_samples` is the number of samples and
              `n_features` is the number of features.
  
          y : array-like of shape (n_samples,)
              Target values.
  
          sample_weight : array-like of shape (n_samples,) or None
              Sample weights. If None, then samples are equally weighted.
              Note that this is supported only if all underlying estimators
              support sample weights.
  
          Returns
          -------
          self : object
          """
          # all_estimators contains all estimators, the one to be fitted and the
          # 'drop' string.
          names, all_estimators = self._validate_estimators()
          self._validate_final_estimator()
  
          stack_method = [self.stack_method] * len(all_estimators)
  
          # Fit the base estimators on the whole training data. Those
          # base estimators will be used in transform, predict, and
          # predict_proba. They are exposed publicly.
          self.estimators_ = Parallel(n_jobs=self.n_jobs)(
              delayed(_parallel_fit_estimator)(clone(est), X, y, sample_weight)
              for est in all_estimators if est != 'drop'
          )
  
          self.named_estimators_ = Bunch()
          est_fitted_idx = 0
          for name_est, org_est in zip(names, all_estimators):
              if org_est != 'drop':
                  self.named_estimators_[name_est] = self.estimators_[
                      est_fitted_idx]
                  est_fitted_idx += 1
              else:
                  self.named_estimators_[name_est] = 'drop'
  
          # To train the meta-classifier using the most data as possible, we use
          # a cross-validation to obtain the output of the stacked estimators.
  
          # To ensure that the data provided to each estimator are the same, we
          # need to set the random state of the cv if there is one and we need to
          # take a copy.
          cv = check_cv(self.cv, y=y, classifier=is_classifier(self))
          if hasattr(cv, 'random_state') and cv.random_state is None:
              cv.random_state = np.random.RandomState()
  
          self.stack_method_ = [
              self._method_name(name, est, meth)
              for name, est, meth in zip(names, all_estimators, stack_method)
          ]
  
          predictions = Parallel(n_jobs=self.n_jobs)(
              delayed(cross_val_predict)(clone(est), X, y, cv=deepcopy(cv),
                                         method=meth, n_jobs=self.n_jobs,
                                         verbose=self.verbose)
              for est, meth in zip(all_estimators, self.stack_method_)
              if est != 'drop'
          )
  
          # Only not None or not 'drop' estimators will be used in transform.
          # Remove the None from the method as well.
          self.stack_method_ = [
              meth for (meth, est) in zip(self.stack_method_, all_estimators)
              if est != 'drop'
          ]
  
          X_meta = self._concatenate_predictions(X, predictions)
          if sample_weight is not None:
              try:
                  self.final_estimator_.fit(
                      X_meta, y, sample_weight=sample_weight
                  )
              except TypeError as exc:
                  if "unexpected keyword argument 'sample_weight'" in str(exc):
                      raise TypeError(
                          "Underlying estimator {} does not support sample "
                          "weights."
                          .format(self.final_estimator_.__class__.__name__)
                      ) from exc
                  raise
          else:
              self.final_estimator_.fit(X_meta, y)
  
          return self
function_tokens: def fit ( self , X , y , sample_weight = None ) : # all_estimators contains all estimators, the one to be fitted and the # 'drop' string. names , all_estimators = self . _validate_estimators ( ) self . _validate_final_estimator ( ) stack_method = [ self . stack_method ] * len ( all_estimators ) # Fit the base estimators on the whole training data. Those # base estimators will be used in transform, predict, and # predict_proba. They are exposed publicly. self . estimators_ = Parallel ( n_jobs = self . n_jobs ) ( delayed ( _parallel_fit_estimator ) ( clone ( est ) , X , y , sample_weight ) for est in all_estimators if est != 'drop' ) self . named_estimators_ = Bunch ( ) est_fitted_idx = 0 for name_est , org_est in zip ( names , all_estimators ) : if org_est != 'drop' : self . named_estimators_ [ name_est ] = self . estimators_ [ est_fitted_idx ] est_fitted_idx += 1 else : self . named_estimators_ [ name_est ] = 'drop' # To train the meta-classifier using the most data as possible, we use # a cross-validation to obtain the output of the stacked estimators. # To ensure that the data provided to each estimator are the same, we # need to set the random state of the cv if there is one and we need to # take a copy. cv = check_cv ( self . cv , y = y , classifier = is_classifier ( self ) ) if hasattr ( cv , 'random_state' ) and cv . random_state is None : cv . random_state = np . random . RandomState ( ) self . stack_method_ = [ self . _method_name ( name , est , meth ) for name , est , meth in zip ( names , all_estimators , stack_method ) ] predictions = Parallel ( n_jobs = self . n_jobs ) ( delayed ( cross_val_predict ) ( clone ( est ) , X , y , cv = deepcopy ( cv ) , method = meth , n_jobs = self . n_jobs , verbose = self . verbose ) for est , meth in zip ( all_estimators , self . stack_method_ ) if est != 'drop' ) # Only not None or not 'drop' estimators will be used in transform. # Remove the None from the method as well. self . stack_method_ = [ meth for ( meth , est ) in zip ( self . stack_method_ , all_estimators ) if est != 'drop' ] X_meta = self . _concatenate_predictions ( X , predictions ) if sample_weight is not None : try : self . final_estimator_ . fit ( X_meta , y , sample_weight = sample_weight ) except TypeError as exc : if "unexpected keyword argument 'sample_weight'" in str ( exc ) : raise TypeError ( "Underlying estimator {} does not support sample " "weights." . format ( self . final_estimator_ . __class__ . __name__ ) ) from exc raise else : self . final_estimator_ . fit ( X_meta , y ) return self