class_docstr: A stacking classifier.
  
  A stacking classifier is a classifier that uses the predictions of
  several first layer estimators (generated with a cross validation method)
  for a second layer estimator.
  
  Parameters
  ----------
  base_estimators : list, default = [Classifier(strategy="LightGBM"), Classifier(strategy="RandomForest"),Classifier(strategy="ExtraTrees")]
      List of estimators to fit in the first level using a cross validation.
  
  level_estimator : object, default = LogisticRegression()
      The estimator used in second and last level.
  
  n_folds : int, default = 5
      Number of folds used to generate the meta features for the training set
  
  copy : bool, default = False
      If true, meta features are added to the original dataset
  
  drop_first : bool, default = True
      If True, each estimator output n_classes-1 probabilities
  
  random_state : None or int or RandomState. default = 1
      Pseudo-random number generator state used for shuffling. If None, use
      default numpy RNG for shuffling.
  
  verbose : bool, default = True
      Verbose mode.
class_docstr_tok: ["A","stacking","classifier",".","A","stacking","classifier","is","a","classifier","that","uses","the","predictions","of","several","first","layer","estimators","(","generated","with","a","cross","validation","method",")","for","a","second","layer","estimator",".","Parameters","--","--","--","--","--","base_estimators",":","list",",","default","=","[","Classifier","(","strategy=","''","LightGBM","''",")",",","Classifier","(","strategy=","''","RandomForest","''",")",",","Classifier","(","strategy=","''","ExtraTrees","''",")","]","List","of","estimators","to","fit","in","the","first","level","using","a","cross","validation",".","level_estimator",":","object",",","default","=","LogisticRegression","(",")","The","estimator","used","in","second","and","last","level",".","n_folds",":","int",",","default","=","5","Number","of","folds","used","to","generate","the","meta","features","for","the","training","set","copy",":","bool",",","default","=","False","If","true",",","meta","features","are","added","to","the","original","dataset","drop_first",":","bool",",","default","=","True","If","True",",","each","estimator","output","n_classes-1","probabilities","random_state",":","None","or","int","or","RandomState",".","default","=","1","Pseudo-random","number","generator","state","used","for","shuffling",".","If","None",",","use","default","numpy","RNG","for","shuffling",".","verbose",":","bool",",","default","=","True","Verbose","mode","."]
docstr: Creates meta-features for the training dataset.
  
  Parameters
  ----------
  df_train : pandas dataframe of shape = (n_samples, n_features)
      The training dataset.
  
  y_train : pandas series of shape = (n_samples, )
      The target.
  
  Returns
  -------
  pandas dataframe of shape = (n_samples, n_features*int(copy)+n_metafeatures)
      The transformed training dataset.
docstr_tok: ["Creates","meta-features","for","the","training","dataset",".","Parameters","--","--","--","--","--","df_train",":","pandas","dataframe","of","shape","=","(","n_samples",",","n_features",")","The","training","dataset",".","y_train",":","pandas","series","of","shape","=","(","n_samples",",",")","The","target",".","Returns","--","--","--","-","pandas","dataframe","of","shape","=","(","n_samples",",","n_features","*","int","(","copy",")","+n_metafeatures",")","The","transformed","training","dataset","."]
code: def fit_transform(self, df_train, y_train):
      """Creates meta-features for the training dataset.
  
      Parameters
      ----------
      df_train : pandas dataframe of shape = (n_samples, n_features)
          The training dataset.
  
      y_train : pandas series of shape = (n_samples, )
          The target.
  
      Returns
      -------
      pandas dataframe of shape = (n_samples, n_features*int(copy)+n_metafeatures)
          The transformed training dataset.
      """
  
      # noqa
  
      # sanity checks
      if (type(df_train) != pd.SparseDataFrame) and (
          type(df_train) != pd.DataFrame
      ):
          raise ValueError("df_train must be a DataFrame")
  
      if type(y_train) != pd.core.series.Series:
          raise ValueError("y_train must be a Series")
  
      # stratified k fold
      cv = StratifiedKFold(
          n_splits=self.n_folds,
          shuffle=True,
          random_state=self.random_state,
      )
  
      preds = pd.DataFrame([], index=y_train.index)
  
      classes = y_train.value_counts()
      classes_to_drop = classes[classes < 2].index
      indexes_to_drop = y_train[
          y_train.apply(lambda x: x in classes_to_drop)
      ].index
  
      if self.verbose:
          print("")
          print(
              "[=========================================================="
              "===================] LAYER [==============================="
              "====================================================]"
          )
          print("")
  
      for c, clf in enumerate(self.base_estimators):
          if self.verbose:
              print(
                  "> fitting estimator n°"
                  + str(c + 1)
                  + " : "
                  + str(clf.get_params())
                  + " ..."
              )
              print("")
  
          # for each base estimator, we create the meta feature on train set
          y_pred = self.__cross_val_predict_proba(
              clf, df_train, y_train, cv
          )
          for i in range(0, y_pred.shape[1] - int(self.drop_first)):
              preds["est" + str(c + 1) + "_class" + str(i)] = y_pred[
                  :, i
              ]
  
          # and we refit the base estimator on entire train set
          clf.fit(
              df_train.drop(indexes_to_drop),
              y_train.drop(indexes_to_drop),
          )
  
      layer = 1
      columns = ["layer" + str(layer) + "_" + s for s in preds.columns]
      while len(np.intersect1d(df_train.columns, columns)) > 0:
          layer = layer + 1
          columns = [
              "layer" + str(layer) + "_" + s for s in preds.columns
          ]
  
      preds.columns = [
          "layer" + str(layer) + "_" + s for s in preds.columns
      ]
  
      self.__fittransformOK = True
  
      if self.copy:
          # we keep also the initial features
          return pd.concat([df_train, preds], axis=1)
      else:
          # we keep only the meta features
          return preds
  
file_path: MLBox/mlbox/model/classification/stacking_classifier.py
imports: import numpy
  import pandas
  from sklearn.linear_model import LogisticRegression
  from sklearn.model_selection import StratifiedKFold
  from copy import copy
  from .classifier import Classifier
  import warnings
label_desc: Use image node_id 5 for calling the StackingClassifier obj's underlying member method code with example usage: obj.fit_transform(df_train, y_train) and returns: pd, preds