Ensemble Methods in Python
Román de las Heras
Data Scientist, Appodeal
Some features of stacking implementation from scikit-learn:
scikit-learn provides stacking estimators (since version 0.22)scikit-learn estimators
General steps for the implementation:
from sklearn.ensemble import StackingClassifier
# Instantiate the 1st-layer classifiers
classifiers = [
    ('clf1', Classifier1(params1)),
    ('clf2', Classifier2(params2)),
    ...
    ('clfN', ClassifierN(paramsN))
]
# Instantiate the 2nd-layer classifier
clf_meta = ClassifierMeta(paramsMeta)
# Build the Stacking classifier
clf_stack = StackingClassifier(
   estimators=classifiers,
   final_estimator=clf_meta,
   cv=5,
   stack_method='predict_proba',
   passthrough=False)
# Use the fit and predict methods
clf_stack.fit(X_train, y_train)
pred = clf_stack.predict(X_test)
from sklearn.ensemble import StackingRegressor
# Instantiate the 1st-layer regressors
regressors = [
    ('reg1', Regressor1(params1)),
    ('reg2', Regressor2(params2)),
    ...
    ('regN', RegressorN(paramsN))    
]
# Instantiate the 2nd-layer regressor
reg_meta = RegressorMeta(paramsMeta)
# Build the Stacking regressor
reg_stack = StackingRegressor(
   estimators=regressors,
   final_estimator=reg_meta,
   cv=5,
   passthrough=False)
# Use the fit and predict methods
reg_stack.fit(X_train, y_train)
pred = reg_stack.predict(X_test)
Ensemble Methods in Python