Ensemble Methods in Python
Román de las Heras
Data Scientist, Appodeal
scikit-learn
estimatorsCharacteristics:
from mlxtend.classifier
import StackingClassifier
# Instantiate the 1st-layer 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(
classifiers=[clf1, clf2, ... clfN],
meta_classifier=clf_meta,
use_probas=False,
use_features_in_secondary=False)
# Use the fit and predict methods
# like with scikit-learn estimators
clf_stack.fit(X_train, y_train)
pred = clf_stack.predict(X_test)
from mlxtend.regressor
import StackingRegressor
# Instantiate the 1st-layer 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(
regressors=[reg1, reg2, ... regN],
meta_regressor=reg_meta,
use_features_in_secondary=False)
# Use the fit and predict methods
# like with scikit-learn estimators
reg_stack.fit(X_train, y_train)
pred = reg_stack.predict(X_test)
Ensemble Methods in Python