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 test dataset.
  
  Parameters
  ----------
  df_test : pandas dataframe of shape = (n_samples_test, n_features)
      The test dataset.
  
  Returns
  -------
  pandas dataframe of shape = (n_samples_test, n_features*int(copy)+n_metafeatures)
      The transformed test dataset.
docstr_tok: ["Creates","meta-features","for","the","test","dataset",".","Parameters","--","--","--","--","--","df_test",":","pandas","dataframe","of","shape","=","(","n_samples_test",",","n_features",")","The","test","dataset",".","Returns","--","--","--","-","pandas","dataframe","of","shape","=","(","n_samples_test",",","n_features","*","int","(","copy",")","+n_metafeatures",")","The","transformed","test","dataset","."]
code: def transform(self, df_test):
      """Creates meta-features for the test dataset.
  
      Parameters
      ----------
      df_test : pandas dataframe of shape = (n_samples_test, n_features)
          The test dataset.
  
      Returns
      -------
      pandas dataframe of shape = (n_samples_test, n_features*int(copy)+n_metafeatures)
          The transformed test dataset.
      """
  
      # sanity checks
      if (type(df_test) != pd.SparseDataFrame) and (
          type(df_test) != pd.DataFrame
      ):
          raise ValueError("df_test must be a DataFrame")
  
      if self.__fittransformOK:
          preds_test = pd.DataFrame([], index=df_test.index)
  
          # for each base estimator, we predict the meta feature on test set
          for c, clf in enumerate(self.base_estimators):
              y_pred_test = clf.predict_proba(df_test)
  
              for i in range(
                  0, y_pred_test.shape[1] - int(self.drop_first)
              ):
                  idx_name = "est" + str(c + 1) + "_class" + str(i)
                  preds_test[idx_name] = y_pred_test[:, i]
  
          layer = 1
          columns = [
              "layer" + str(layer) + "_" + s for s in preds_test.columns
          ]
  
          while len(np.intersect1d(df_test.columns, columns)) > 0:
              layer = layer + 1
              columns = [
                  "layer" + str(layer) + "_" + s
                  for s in preds_test.columns
              ]
  
          preds_test.columns = [
              "layer" + str(layer) + "_" + s for s in preds_test.columns
          ]
  
          if self.copy:
              # we keep also the initial features
              return pd.concat([df_test, preds_test], axis=1)
          else:
              # we keep only the meta features
              return preds_test
  
      else:
          raise ValueError("Call fit_transform before !")
  
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 6 for calling the StackingClassifier obj's underlying member method code with example usage: obj.transform(df_test) and returns: pd, preds_test