class_docstr: A Stacking regressor.
  
   A stacking regressor is a regressor 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 = [Regressor(strategy="LightGBM"),
                                     Regressor(strategy="RandomForest"),
                                     Regressor(strategy="ExtraTrees")]
      List of estimators to fit in the first level using a cross validation.
  
  level_estimator : object, default = LinearRegression()
      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
  
  random_state : None, 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","regressor",".","A","stacking","regressor","is","a","regressor","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","=","[","Regressor","(","strategy=","''","LightGBM","''",")",",","Regressor","(","strategy=","''","RandomForest","''",")",",","Regressor","(","strategy=","''","ExtraTrees","''",")","]","List","of","estimators","to","fit","in","the","first","level","using","a","cross","validation",".","level_estimator",":","object",",","default","=","LinearRegression","(",")","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","random_state",":","None",",","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: Create 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: ["Create","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):
      """Create 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.
  
      """
      # sanity checks
      if (type(df_train) != pd.SparseDataFrame) & (
          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")
  
      cv = KFold(
          n_splits=self.n_folds,
          shuffle=True,
          random_state=self.random_state,
      )
  
      preds = pd.DataFrame([], index=y_train.index)
  
      if self.verbose:
          print("")
          print(
              "[=========================================================="
              "===================] LAYER [==============================="
              "====================================================]"
          )
          print("")
  
      for c, reg in enumerate(self.base_estimators):
          if self.verbose:
              print(
                  "> fitting estimator n°"
                  + str(c + 1)
                  + " : "
                  + str(reg.get_params())
                  + " ..."
              )
              print("")
  
          # for each base estimator, we create the meta feature on train set
          y_pred = cross_val_predict(
              estimator=reg, X=df_train, y=y_train, cv=cv
          )
          preds["est" + str(c + 1)] = y_pred
  
          # and we refit the base estimator on entire train set
          reg.fit(df_train, y_train)
  
      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:
          return preds
  
file_path: MLBox/mlbox/model/regression/stacking_regressor.py
imports: import numpy
  import pandas
  from sklearn.linear_model import LinearRegression
  from sklearn.model_selection import KFold, cross_val_predict
  from copy import copy
  from .regressor import Regressor
  import warnings
label_desc: Use image node_id 4 for calling the StackingRegressor obj's underlying member method code with example usage: obj.fit_transform(df_train, y_train) and returns: pd, preds